-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinitramfs_hook.sh
executable file
·53 lines (46 loc) · 1.52 KB
/
initramfs_hook.sh
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
#!/bin/sh -e
case $1 in
prereqs)
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
for e in /sbin/vg* /sbin/lv* /sbin/pv*; do
cp -a $e ${DESTDIR}/bin/$(basename $e)
done
cat <<EOF > ${DESTDIR}/bin/boot
#!/bin/sh
touch /tmp/noautoboot
kill -9 \$(ps | grep '[s]h -i' | awk '{print \$1}')
EOF
chmod +x ${DESTDIR}/bin/boot
copy_exec "/sbin/fdisk" "/bin/"
copy_exec "/usr/bin/qemu-img" "/bin/"
copy_exec "/usr/bin/curl" "/bin/"
copy_exec "/usr/bin/scp" "/bin/"
copy_exec "/usr/bin/screen" "/bin/"
copy_exec "/usr/bin/rsync" "/bin/"
copy_exec "/usr/bin/lsof" "/bin/"
# Copy non-busybox/full tar
copy_exec "/bin/tar" "/sbin/"
# Copy mkfs
copy_exec "/sbin/mke2fs" "/sbin/"
ln -s mke2fs "${DESTDIR}/sbin/mkfs.ext4"
ln -s mke2fs "${DESTDIR}/sbin/mkfs.ext2"
# Copy certificates
cp -a /etc/ssl ${DESTDIR}/etc/ssl
mkdir -p ${DESTDIR}/usr/share/
cp -a /usr/share/ca-certificates ${DESTDIR}/usr/share/
# Copy xterm info for screen
mkdir -p ${DESTDIR}/lib/terminfo
cp -a /lib/terminfo/x ${DESTDIR}/lib/terminfo
install -d -m 755 ${DESTDIR}/var/run/screen
# Fix DNS resolver
cp -a /lib/x86_64-linux-gnu/libnss_dns* ${DESTDIR}/lib/x86_64-linux-gnu/
echo "nameserver 8.8.8.8" > ${DESTDIR}/etc/resolv.conf
cp -a /etc/initramfs-tools/bin/deploy_os*.sh ${DESTDIR}/bin/
# Define /sbin PATH for dropbear user
TMP_ROOT_DIR=$(ls -d ${DESTDIR}/root-* 2>/dev/null || ls -d ${DESTDIR}/root)
echo 'export PATH=$PATH:/sbin:/usr/sbin' > "${TMP_ROOT_DIR}/.profile"
# Stop the autoboot on timeout
echo 'touch /tmp/noautoboot' >> "${TMP_ROOT_DIR}/.profile"