aboutsummaryrefslogtreecommitdiff
path: root/scripts/root/dropbear
blob: 9dc9bb0dcabd4d9fbf1152dba1efdfe79cd6e093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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 \
  --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,etc/dropbear,var/log} &&
touch "$ROOT"/var/log/lastlog &&
cp dropbearmulti "$ROOT"/bin || exit 1
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 &&

echo 'netcat -p 22 -L dropbear -iRB &' > "$ROOT"/etc/rc/dropbear &&

# 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"