aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-05-08 03:16:38 -0500
committerRob Landley <rob@landley.net>2020-05-08 03:16:38 -0500
commit4761d756dde03e62de0c3f3d7f25067a4f207fa3 (patch)
treea562276a01feba9667ef9387b2f5391b9655a92d /scripts
parent9c6a08e1c36fb7f3b056cc24581cc5467d81ad12 (diff)
downloadtoybox-4761d756dde03e62de0c3f3d7f25067a4f207fa3.tar.gz
beat the dropbear build and module support a little further into shape.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mkroot.sh15
-rwxr-xr-xscripts/root/dropbear18
2 files changed, 24 insertions, 9 deletions
diff --git a/scripts/mkroot.sh b/scripts/mkroot.sh
index 43500ef1..b6386eac 100755
--- a/scripts/mkroot.sh
+++ b/scripts/mkroot.sh
@@ -94,7 +94,7 @@ if [ $$ -eq 1 ]; then
[ "$(date +%s)" -lt 10000000 ] && sntp -sq time.google.com
# Run expansion scripts (if any)
- for i in $(/etc/rc/* | sort); do [ -e "$i" ] && . $i; done
+ for i in $(echo /etc/rc/* | sort); do [ -e "$i" ] && . $i; done
[ -z "$CONSOLE" ] && CONSOLE="$(</sys/class/tty/console/active)"
[ -z "$HANDOFF" ] && HANDOFF=/bin/sh && echo Type exit when done.
@@ -109,7 +109,7 @@ chmod +x "$ROOT"/init &&
# Google's nameserver, passwd+group with special (root/nobody) accounts + guest
echo "nameserver 8.8.8.8" > "$ROOT"/etc/resolv.conf &&
cat > "$ROOT"/etc/passwd << 'EOF' &&
-root::0:0:root:/root:/bin/sh
+root:x:0:0:root:/root:/bin/sh
guest:x:500:500:guest:/home/guest:/bin/sh
nobody:x:65534:65534:nobody:/proc/self:/dev/null
EOF
@@ -120,6 +120,9 @@ announce toybox
make clean ${CONF:-defconfig KCONFIG_ALLCONFIG=<(echo $'CONFIG_SH=y\nCONFIG_ROUTE=y')} &&
LDFLAGS=--static PREFIX="$ROOT" make toybox install || exit 1
+# Build any modules
+for i in $PKG; do announce "$i"; PATH="$PKGDIR:$PATH" source $i; done
+
if [ -z "$LINUX" ] || [ ! -d "$LINUX/kernel" ]; then
echo 'No $LINUX directory, kernel build skipped.'
else
@@ -188,7 +191,7 @@ else
fi
# Write the qemu launch script
- echo "qemu-system-$QEMU" '"$@"' -nographic -no-reboot -m 256 \
+ echo qemu-system-"$QEMU" '"$@"' $QEMU_MORE -nographic -no-reboot -m 256 \
"-kernel $(basename "$VMLINUX") -initrd ${CROSS_BASE}root.cpio.gz" \
"-append \"quiet panic=1 HOST=$TARGET console=$KARGS \$KARGS\"" \
${DTB:+-dtb "$(basename "$DTB")"} ";echo -e '\e[?7h'" \
@@ -228,8 +231,8 @@ else
cp "$VMLINUX" "$OUTPUT" && cd .. && rm -rf linux && popd || exit 1
fi
-# Build any modules, clean up, and package root filesystem for initramfs.
-for i in $PKG; do announce "$i"; PATH="$PKGDIR:$PATH" source $i; done
+# clean up and package root filesystem for initramfs.
rmdir "$MYBUILD" "$BUILD" 2>/dev/null
announce "${CROSS_BASE}root.cpio.gz"
-(cd "$ROOT" && find .|cpio -o -H newc|gzip) > "$OUTPUT/$CROSS_BASE"root.cpio.gz
+(cd "$ROOT" && find . | cpio -o -H newc --no-preserve-owner | gzip) \
+ > "$OUTPUT/$CROSS_BASE"root.cpio.gz
diff --git a/scripts/root/dropbear b/scripts/root/dropbear
index 79a9d8c3..60654c45 100755
--- a/scripts/root/dropbear
+++ b/scripts/root/dropbear
@@ -28,17 +28,29 @@ setupfor dropbear
echo 'echo "$@"' > config.sub &&
ZLIB="$(echo ../zlib*)" &&
CFLAGS="-I $ZLIB -O2" LDFLAGS="-L $ZLIB" ./configure --enable-static \
- --host=${CROSS_BASE%-} &&
+ --disable-wtmp --host=${CROSS_BASE%-} &&
sed -i 's@/usr/bin/dbclient@ssh@' options.h &&
sed -i 's@\(#define NON_INETD_MODE\) 1@\1 0@' default_options.h &&
make -j $(nproc) PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 SCPPROGRESS=1 &&
${CROSS_COMPILE}strip dropbearmulti &&
-mkdir -p "$ROOT/bin" &&
+mkdir -p "$ROOT"/{bin,etc/dropbear,var/log} &&
+touch "$ROOT"/var/log/lastlog &&
cp dropbearmulti "$ROOT"/bin || exit 1
-for i in "$ROOT"/bin/{ssh,sshd,scp,dropbearkey}
+for i in "$ROOT"/bin/{ssh,dropbear,scp,dropbearkey}
do
ln -s dropbearmulti $i || exit 1
done
cleanup
rm -rf zlib-*
+
+# user root password root, user guest no password
+echo -e 'root:$1$939UTPzb$/PfVYAsF2Hqi/AQ3UBjbK/:::::::\nguest::::::::' > "$ROOT"/etc/shadow &&
+chmod 600 "$ROOT"/etc/shadow &&
+
+# file to run on host to ssh into guest
+echo 'ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" ${1:+$1@}127.0.0.1 -p 2222' > "$OUTPUT"/ssh2dropbear.sh &&
+chmod +x "$OUTPUT"/ssh2dropbear.sh
+
+# Forward 127.0.0.1:2222 into qemu instance
+QEMU_MORE="-nic user,hostfwd=tcp:127.0.0.1:2222-:22"