Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and improvements #27

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions config.sample
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
# SPDX-License-Identifier: GPL-2.0
#
# This is check code sourced by gbmake

# Directory for kernel build objects, usually a relative path
# GNUBEE_KERNEL_OBJECTS=O
# Directory for initramfs, can be relative
# GNUBEE_INITRAMFS_TREE:=initramfs
# Directory containing kernel config files - 'kern_config' in parent of script by default
# GNUBEE_CONFIG_DIR=
# Directory where user-space tools are built - usually ../build from script dir
# GNUBEE_BUILD_DIR=
# Cross compiler - full path such as /opt/cross/bin/mipsel-unknown-linux-gnu-
# This file is sourced by gbmake
#
# $gbtools can be used as the path to the root of the gnubee-tools repository
# all paths can be relative to the directory the script is executed in

# Debian suite to use for debootstrap, will be used to build initramfs
# May be a release code name (e.g. stretch, buster, sid) or a symbolic name (eg, unstable, testing, stable, oldstable)
# GNUBEE_DEBIAN_SUITE="stable"

# Debian mirror to use for debootstrap, will be used to build initramfs
# GNUBEE_DEBIAN_MIRROR="http://deb.debian.org/debian/"

# Directory for kernel build objects
# GNUBEE_KERNEL_OBJECTS="O"

# Directory for initramfs
# GNUBEE_INITRAMFS_TREE="initramfs"

# Directory containing kernel config files
# GNUBEE_CONFIG_DIR="$gbtools/kern_config"

# Directory where user-space tools are built
# GNUBEE_BUILD_DIR="$gbtools/build"

# Path to cross compiler - must be in $PATH or full path such as /opt/cross/bin/mipsel-unknown-linux-gnu-
# CROSS_COMPILE=

# GnuBee running Debian from which various programs can be copied.
# [email protected]

# To include extenal modules in the image, list them here. Just the name
# of the directory may suffice if the Makefile there follows normal conventions.
# Otherwise provide a script that will build the module and install it.
Expand Down
43 changes: 41 additions & 2 deletions initramfs/config
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
# hostname
# ssh PermitRootLogin
# label filesystem
# add leds udev rule

mp=/tmp/newroot
default_debian_suite=buster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that related to the other change in config.sample:
GNUBEE_DEBIAN_SUITE="stable"

default_debian_mirror="http://httpredir.debian.org/debian"
include_packages="vim,openssh-server,ntpdate,cron,locales,udev,fake-hwclock,mtd-utils,ca-certificates,apt-transport-https,vlan,bash-completion,less,man-db,manpages,dbus"
Copy link
Contributor

@vincele vincele Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd separate that into 2 commits, one for the fix, maybe adding a reference in the commitmsg to the "timedatectl bug" that is being fixed.

And another commit for the "useful" stuff that may be a matter of taste (i.e.: you prefer minimalistic or with batteries included)


set_host() {
case `hostname` in
Expand All @@ -31,6 +35,33 @@ set_host() {
return 1
}

set_debian() {
while [ -z "$debian_suite" ]; do
read -p "Which Debian suite do you want to install? (jessie | stretch | buster | bullseye | sid) [buster] " debian_suite
case "$debian_suite" in
"" ) debian_suite="$default_debian_suite" ;;
jessie | stretch | buster | bullseye | sid ) ;;
* ) echo "Unknown debian suite. Please enter one of the above choices."
esac
done
while [ -z "$debian_mirror" ]; do
read -p "Which Debian mirror do you want to use? [$default_debian_mirror]" debian_mirror
debian_mirror="${debian_mirror%/}"
case "$debian_mirror" in
"" ) debian_mirror="$default_debian_mirror" ;;
* )
echo -n "Validating mirror URL ... "
if wget -q --spider "$debian_mirror/debian/dists/$debian_suite/Release.gpg"; then
echo "OK."
else
echo "ERROR, please enter a valid Debian mirror URL."
debian_mirror=
fi
esac
done

}

check_net() {
net_dev=`ip route show match 0/0 | awk '$4 == "dev" {print $5 }'`
if [ -z "$net_dev" ]; then
Expand Down Expand Up @@ -145,7 +176,7 @@ bootstrap() {
fi
PATH=/bin:/usr/bin:/sbin:/usr/sbin:$PATH
export PATH
debootstrap --arch=mipsel --include=vim,openssh-server,ntpdate,cron,locales,udev,fake-hwclock,mtd-utils,ca-certificates,apt-transport-https,vlan,libnl-3-200,libnl-genl-3-200 stretch $mp http://httpredir.debian.org/debian || exit 1
debootstrap --arch=mipsel --include="$include_packages" "$debian_version" "$mp" "$debian_mirror" || exit 1
return 1
}

Expand Down Expand Up @@ -199,6 +230,13 @@ fixup_modules() {
cp -a /lib/modules/. $mp/lib/modules
}

fixup_leds() {
cat > "$mp/lib/udev/rules.d/70-gnubee-leds.rules" <<- "EOF"
ACTION=="add", SUBSYSTEM=="leds", KERNEL=="gb-pc1:green:status", ATTR{trigger}="default-on"
ACTION=="add", SUBSYSTEM=="leds", KERNEL=="gb-pc1:green:system", ATTR{trigger}="activity"
EOF
}

fixup() {
hostname > $mp/etc/hostname
root=`grep '^root:' /etc/shadow`
Expand All @@ -211,10 +249,11 @@ fixup() {
esac
fixup_net
fixup_modules
fixup_leds
return 0
}

until set_host && set_passwd && set_net && set_time && create_filesystem && bootstrap && fixup; do
until set_host && set_debian && set_passwd && set_net && set_time && create_filesystem && bootstrap && fixup; do
:
done

Expand Down
13 changes: 7 additions & 6 deletions initramfs/init
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ set_led() {
echo $2 > delay_on
echo $3 > delay_off
;;
2 )
echo $2 > trigger
;;
* ) echo none > trigger
esac
)
Expand Down Expand Up @@ -105,7 +108,7 @@ gnubee_switch_root(){
done

set_led system
set_led status
set_led status 100 100

umount -l /proc /sys /dev/pts /dev
exec switch_root /mnt/root /sbin/init
Expand Down Expand Up @@ -178,11 +181,9 @@ gnubee_boot(){
udhcpd_config ethblack 192.168.10
udhcpd /udhcpd.conf
fi
if [ ! -s /etc/dropbear/dropbear_ecdsa_host_key ]; then
# build host didn't have dropbear, so make a new key on each boot
dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key
fi
dropbear

# -R to generate new host keys on each boot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment accurate ?

Reading the man page @ https://manpages.org/dropbear/8
I'm not sure I can tell if it'll only be generating keys if they are absent or if it will (re-)generate keys at each invokation.

I've not tested, sorry, just asking while looking at your PR...

dropbear -R

run_shell /dev/ttyS0
fi
Expand Down
Loading