-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_iso.sh
executable file
·188 lines (159 loc) · 4.32 KB
/
make_iso.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
# author : Oros
# 2021-02-21
#
# This script create a light Debian ISO which include dwagent (https://www.dwservice.net/)
set -euo pipefail
if [ ! -f config ]; then
if [ -f config.dist ]; then
cp config.dist config
else
echo "$0: ${1:-"config file not found"}" 1>&2
exit 1
fi
fi
. ./config
function help()
{
readonly PROGNAME=$(basename $0)
cat <<- EOF
$0 [-h] [-k]
Make a live CD Debian with dwagent (https://www.dwservice.net/)
Options
-h : This help
-k : Keep files in iso, tmp and chroot.
Use to only rebuid the ISO.
EOF
exit
}
keepFiles=0
eval set -- $(getopt -l keep-files -o kh -- "$@")
while true
do
name="$1"
shift
case $name in
-k|--keep-files)
keepFiles=1
;;
-h|--help)
help
;;
--)
break
;;
*)
echo "Illegal option: $name"
exit 1
;;
esac
done
if [ "$EUID" -ne 0 ]; then
echo -e "\033[31mPlease run as root\033[0m" 1>&2
exit 1
fi
if [ ! `which debootstrap` ]; then
apt-get install -y debootstrap
fi
if [ ! `which xorriso` ]; then
apt-get install -y xorriso
fi
if [ ! `which live-build` ]; then
apt-get install -y live-build
fi
if [ ! `which syslinux` ]; then
apt-get install -y syslinux
fi
if [ ! `which mksquashfs` ]; then
apt-get install -y squashfs-tools
fi
home_project=$(pwd)
chroot_files="$home_project/chroot_files"
iso_files="$home_project/iso_files"
mkdir -p "$livework"
cd "$livework"
if [ ! -f "${chroot_files}/root/dwagent_x86.sh" ]; then
wget -c https://www.dwservice.net/download/dwagent_x86.sh -O "${chroot_files}/root/dwagent_x86.sh"
chmod +x "${chroot_files}/root/dwagent_x86.sh"
fi
#http://ftp.debian.org/debian/ -> http://ftp.debian.org/debian
repositories="$(echo $repositories| sed 's|/$||')"
repositoriesProxy="$(echo $repositoriesProxy| sed 's|/$||')"
if [ "$keepFiles" -eq "0" ]; then
rm -fr iso
rm -fr tmp
rm -fr chroot
# build OS
if [ "$repositoriesProxy" != "" ]; then
echo "Use proxy $repositoriesProxy"
repo="${repositoriesProxy}/$(echo $repositories | sed 's|.*://||')"
# repositories="http://ftp.debian.org/debian"
# repositoriesProxy="http://myproxy.lan:3142"
# repo="http://myproxy.lan:3142/ftp.fr.debian.org/debian"
debootstrap --arch=amd64 $os_version chroot $repo
else
debootstrap --arch=amd64 $os_version chroot $repositories
fi
# configure the OS
cp -r "$chroot_files"/* chroot/
chmod +x chroot/install_in_chroot.sh
echo "${dist_name}" > chroot/etc/hostname
dbus-uuidgen > chroot/etc/machine-id
chroot chroot /install_in_chroot.sh
# clean tmp files
rm -r chroot/install_in_chroot.sh
rm -rf chroot/tmp/*
rm -f chroot/root/.keyboard_ok
rm -rf chroot/root/.bash_history
if [ "$repositoriesProxy" != "" ]; then
sed -i "s|$repo|$repositories|" chroot/etc/apt/sources.list
fi
fi
mkdir -p {iso/{EFI/boot,boot/grub/x86_64-efi,isolinux,live},tmp}
# make filesystem.squashfs
if [ -f iso/live/filesystem.squashfs ]; then
rm iso/live/filesystem.squashfs
fi
mksquashfs chroot iso/live/filesystem.squashfs -e boot
# custom files
cp -r $iso_files/iso/* iso/
touch iso/DWLIVE_DEBIAN
cp chroot/boot/vmlinuz*amd64 iso/live/vmlinuz
cp chroot/boot/initrd.img-*amd64 iso/live/initrd
cp /usr/lib/ISOLINUX/isolinux.bin iso/isolinux/
cp /usr/lib/syslinux/modules/bios/* iso/isolinux/
cp -r /usr/lib/grub/x86_64-efi/* iso/boot/grub/x86_64-efi/
grub-mkstandalone \
--format=x86_64-efi \
--output=tmp/bootx64.efi \
--locales="" \
--fonts="" \
"boot/grub/grub.cfg=${iso_files}/grub-standalone.cfg"
cd iso/EFI/boot
dd if=/dev/zero of=efiboot.img bs=1M count=20
mkfs.vfat efiboot.img
mmd -i efiboot.img efi efi/boot
mcopy -vi efiboot.img $livework/tmp/bootx64.efi ::efi/boot/
cd $livework
# build ISO
if [ -f "${home_project}/${iso_name}" ]; then rm "${home_project}/${iso_name}"; fi
xorriso \
-as mkisofs \
-iso-level 3 \
-o "${home_project}/${iso_name}" \
-full-iso9660-filenames \
-volid "DWLIVE_DEBIAN" \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-eltorito-boot isolinux/isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--eltorito-catalog isolinux/isolinux.cat \
-eltorito-alt-boot \
-e /EFI/boot/efiboot.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-append_partition 2 0xef ${livework}/iso/EFI/boot/efiboot.img \
"${livework}/iso"
echo "ISO build in ${home_project}/${iso_name}"
sudo chown $USER: "${home_project}/${iso_name}"