aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/mkroot.sh7
-rwxr-xr-xscripts/root/dropbear44
-rwxr-xr-xscripts/root/plumbing45
3 files changed, 93 insertions, 3 deletions
diff --git a/scripts/mkroot.sh b/scripts/mkroot.sh
index 77284e76..43500ef1 100755
--- a/scripts/mkroot.sh
+++ b/scripts/mkroot.sh
@@ -11,7 +11,8 @@ getcross() { X="$(echo "$CCC/$1"-*cross/bin/"$1"*-cc)"; echo "${X%cc}"; }
# assign command line NAME=VALUE args to env vars
while [ $# -ne 0 ]; do
- [ "${1/=/}" != "$1" ] && eval "export ${1/=*/}=\"\${1#*=}\"" || PKG="$PKG $i"
+ [ "${1/=/}" != "$1" ] && eval "export ${1/=*/}=\"\${1#*=}\"" ||
+ { [ "$1" != '--' ] && PKG="${PKG:-plumbing} $1"; }
shift
done
@@ -48,7 +49,7 @@ else
fi
echo "Building for ${CROSS:=host}"
-: ${OUTPUT:=$TOP/$CROSS}
+: ${OUTPUT:=$TOP/$CROSS} ${PKGDIR:=$PWD/scripts/root}
[ -z "$ROOT" ] && ROOT="$OUTPUT/fs" && rm -rf "$ROOT"
MYBUILD="$BUILD/${CROSS_BASE:-host-}tmp"
rm -rf "$MYBUILD" && mkdir -p "$MYBUILD" || exit 1
@@ -228,7 +229,7 @@ else
fi
# Build any modules, clean up, and package root filesystem for initramfs.
-for i in $PKG; do announce "$i"; ./$i; done
+for i in $PKG; do announce "$i"; PATH="$PKGDIR:$PATH" source $i; done
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
diff --git a/scripts/root/dropbear b/scripts/root/dropbear
new file mode 100755
index 00000000..79a9d8c3
--- /dev/null
+++ b/scripts/root/dropbear
@@ -0,0 +1,44 @@
+#!/bin/echo Try "scripts/mkroot.sh dropbear"
+
+# Example overlay file, adding dropbear (which requires zlib)
+
+echo === download source
+
+download a4d316c404ff54ca545ea71a27af7dbc29817088 \
+ http://downloads.sf.net/libpng/zlib-1.2.8.tar.gz
+
+download 820ec2b8c869edbcf5ad1138777fc0f54349505c \
+ https://matt.ucc.asn.au/dropbear/releases/dropbear-2019.78.tar.bz2
+
+echo === Native build static zlib
+
+setupfor zlib
+# They keep checking in broken generated files.
+rm -f Makefile zconf.h &&
+CC=${CROSS_COMPILE}cc LD=${CROSS_COMPILE}ld AS=${CROSS_COMPILE}as ./configure &&
+make -j $(nproc) || exit 1
+
+# do _not_ cleanup zlib, we need the files we just built for dropbear
+cd ..
+
+echo === $HOST Native build static dropbear
+
+setupfor dropbear
+# Repeat after me: "autoconf is useless"
+echo 'echo "$@"' > config.sub &&
+ZLIB="$(echo ../zlib*)" &&
+CFLAGS="-I $ZLIB -O2" LDFLAGS="-L $ZLIB" ./configure --enable-static \
+ --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" &&
+cp dropbearmulti "$ROOT"/bin || exit 1
+for i in "$ROOT"/bin/{ssh,sshd,scp,dropbearkey}
+do
+ ln -s dropbearmulti $i || exit 1
+done
+cleanup
+
+rm -rf zlib-*
diff --git a/scripts/root/plumbing b/scripts/root/plumbing
new file mode 100755
index 00000000..0bb735ee
--- /dev/null
+++ b/scripts/root/plumbing
@@ -0,0 +1,45 @@
+#!/bin/echo run this from "make root"
+
+# Plumbing to download files
+
+[ -z "$ROOT" ] && echo "no" && exit 1
+mkdir -p "${DOWNLOAD:=$PWD/root_download}" || exit 1
+
+### Functions to download, extract, and clean up after source packages.
+
+# Usage: download HASH URL
+# Grabs source from URL confirming SHA1 hash (Basically == "wget $2")
+# You can stick extracted source in $DOWNLOAD and build will use that instead
+download() {
+ FILE="$(basename "$2")"
+ [ -d "$DOWNLOAD/${FILE/-*/}" ] && echo "$FILE" local && return 0
+ X=0; while true; do
+ [ "$(sha1sum < "$DOWNLOAD/$FILE" 2>/dev/null)" == "$1 -" ] &&
+ echo "$FILE" confirmed && break
+ rm -f $DOWNLOAD/${FILE/-[0-9]*/}-[0-9]* || break
+ [ $X -eq 0 ] && X=1 || exit 1
+ wget "$2" -O "$DOWNLOAD/$FILE"
+ done
+}
+
+# Usage: setupfor PACKAGE
+# Extracts source tarball (or snapshot a repo) to create disposable build dir.
+# Basically "tar xvzCf $MYBUILD $DOWNLOAD/$1.tar.gz && cd $NEWDIR"
+setupfor() {
+ PACKAGE="$(basename "$1")"
+ announce "$PACKAGE" && cd "$MYBUILD" && rm -rf "$PACKAGE" || exit 1
+ if [ -d "$DOWNLOAD/$PACKAGE" ]; then
+ cp -la "$DOWNLOAD/$PACKAGE/." "$PACKAGE" && cd "$PACKAGE" || exit 1
+ else
+ tar xvaf "$DOWNLOAD/$PACKAGE"-*.t* && cd "$PACKAGE"-* || exit 1
+ fi
+}
+
+# Usage: cleanup
+# Delete setupfor's dir, exiting if build failed (basically "rm -rf $PACKAGE")
+cleanup() {
+ [ $? -ne 0 ] && exit 1
+ [ -z "$PACKAGE" ] && exit 1
+ [ ! -z "$NO_CLEANUP" ] && return
+ cd .. && rm -rf "$PACKAGE"* || exit 1
+}