-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxixer.sh
executable file
·122 lines (100 loc) · 3.18 KB
/
xixer.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
die() { echo -e "$@" ; exit 1; }
# defaults
XIXER_HOSTNAME="xixer-$(sha1sum <<< ${RANDOM} | head -c4)"
XIXER_ROOT_PASSWORD="xixer"
DEB_ARCH="amd64"
DEB_SUITE="stretch"
DEB_MIRROR="http://ftp.us.debian.org/debian/"
TARGET_PACKAGES=(
ca-certificates
curl
linux-image-${DEB_ARCH}
live-boot
nmap
openssh-client
parted
squashfs-tools
systemd-sysv
tcpdump
unzip
xz-utils
zip
)
for opt in "$@"; do
case ${opt} in
--hostname=*)
XIXER_HOSTNAME="${opt#*=}" ; shift ;;
--password=*)
XIXER_ROOT_PASSWORD="${opt#*=}" ; shift ;;
--usb-device=*)
XIXER_USB_DEV="${opt#*=}" ; shift ;;
--arch=*)
DEB_ARCH="${opt#*=}" ; shift ;;
--suite=*)
DEB_SUITE="${opt#*=}" ; shift ;;
--mirror=*)
DEB_MIRROR="${opt#*=}" ; shift ;;
esac
done
[[ -n ${XIXER_USB_DEV} ]] || \
die "--usb-device=<device name> is required"
XIXER_ROOT=${PWD}/xixer-root
mkdir -p ${XIXER_ROOT} || \
die "Failed to create ${XIXER_ROOT}!"
debootstrap \
--arch=${DEB_ARCH} --variant=minbase \
${DEB_SUITE} ${XIXER_ROOT} ${DEB_MIRROR} || \
die "debootstrap failed!"
chroot ${XIXER_ROOT} /bin/bash << EOF
set -xe
export DEBIAN_FRONTEND=noninteractive
echo ${XIXER_HOSTNAME} > /etc/hostname
chpasswd <<< "root:${XIXER_ROOT_PASSWORD}"
mount -t tmpfs none /dev/shm
rm -vf /etc/apt/sources.list /etc/apt/sources.list.d/*.list
cat > /etc/apt/sources.list <<EOF_SOURCES
deb http://ftp.us.debian.org/debian/ stretch main contrib non-free
deb http://security.debian.org/debian-security stretch/updates main contrib non-free
deb http://ftp.us.debian.org/debian/ stretch-updates main contrib non-free
EOF_SOURCES
apt-get update
apt-get install --no-install-recommends -yq ${TARGET_PACKAGES[@]}
apt-get clean
umount /dev/shm
rm -rf /var/lib/apt/lists/*
EOF
[[ $? -eq 0 ]] || \
die "Failed to configure root filesystem!"
parted /dev/${XIXER_USB_DEV} --script -- \
'mklabel msdos mkpart primary fat32 0% 100% set 1 boot on' || \
die "Failed to partition /dev/${XIXER_USB_DEV}!"
mkdosfs -F 32 -I /dev/${XIXER_USB_DEV}1 || \
die "Failed to format /dev/${XIXER_USB_DEV}1!"
syslinux -i /dev/${XIXER_USB_DEV}1 || \
die "Failed to install syslinux!"
dd conv=notrunc bs=440 count=1 if=/usr/lib/syslinux/mbr/mbr.bin \
of=/dev/${XIXER_USB_DEV} || \
die "Failed to install syslinux MBR to ${XIXER_USB_DEV}!"
mount /dev/${XIXER_USB_DEV}1 /mnt && mkdir /mnt/live || \
die "Failed to mount ${XIXER_USB_DEV}!"
(cd ${XIXER_ROOT} && \
mksquashfs . /mnt/live/filesystem.squashfs -e boot -noappend) || \
die "Failed to create squashfs!"
cp -v ${XIXER_ROOT}/boot/vmlinuz* /mnt/live/vmlinuz || \
die "Failed to copy kernel and ramdisk!"
cp -v ${XIXER_ROOT}/boot/initrd.img* /mnt/live/initrd || \
die "Failed to copy kernel and ramdisk!"
tar -C /usr/lib/syslinux/modules/bios -cf - \
menu.c32 hdt.c32 ldlinux.c32 libutil.c32 libmenu.c32 \
libcom32.c32 libgpl.c32 | tar -C /mnt -xf - || \
die "Failed to copy syslinux files!"
cp /boot/memtest86+.bin /mnt/live/memtest || \
die "Failed to copy memtest86"
cp /usr/share/misc/pci.ids /mnt || \
die "Failed to copy pci.ids"
cp /xixer/syslinux.cfg /mnt || \
die "Failed to copy syslinux.cfg"
umount /mnt
sync
echo "DONE!!"