-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkiso.sh
executable file
·156 lines (133 loc) · 4.25 KB
/
mkiso.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
#!/usr/bin/bash
#
# Create a bootable cdrom.
#
# Author: Alastair Hughes
# Contact: < hobbitalastair at yandex dot com >
set -e
# Initial setup.
VERSION="0.2"
USAGE="<config dir> <iso file> [extra packages ...]"
source "$(dirname "$(realpath "$0")")/lib/libmain.sh"
source "$(dirname "$(realpath "$0")")/lib/libpackage.sh"
source "$(dirname "$(realpath "$0")")/lib/libboot.sh"
# We overwrite the next two functions from lib/libpackage.sh and
# lib/libboot.sh, as we want to run everything as root to avoid possible
# permission issues.
root_own() {
local mount="$1"
local file="$2"
chown root "${mount}/${file}"
chgrp root "${mount}/${file}"
}
callpacman() {
pacman --noconfirm --root "$@"
}
main() {
# Generate the fs and boot.
local configdir="$1"
local iso="$2"
shift 2
loadrepoconf "${configdir}"
# Check that we are root (needed to avoid permissions issues).
if [ "$(whoami)" != root ]; then
error 1 "We need to be root!"
fi
local fs="${config[builddir]}/iso"
rm -rf "${fs}"
mkdir -p "${fs}/var/lib/pacman"
# Install the packages.
installpkglist "${configdir}" "${fs}" cdrom "$@"
# We assume syslinux; set it up.
local filename
for filename in "${fs}/usr/lib/syslinux/bios/"*.c32; do
cp "${filename}" \
"${fs}/boot/syslinux/$(basename "${filename}")"
done
cat > "${fs}/boot/syslinux/syslinux.cfg" << EOF
DEFAULT linux
PROMPT 0
TIMEOUT 50
UI menu.c32
MENU TITLE Takahe Linux
MENU COLOR border 30;44 #40ffffff #a0000000 std
MENU COLOR title 1;36;44 #9033ccff #a0000000 std
MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel 37;44 #50ffffff #a0000000 std
MENU COLOR help 37;40 #c0ffffff #a0000000 std
MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07 37;40 #90ffffff #a0000000 std
MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
LABEL linux
MENU LABEL Takahe Linux
LINUX ../vmlinuz
APPEND root=/dev/sr0 ro panic=10
LABEL hdt
MENU LABEL HDT (Hardware Detection Tool)
COM32 hdt.c32
LABEL reboot
MENU LABEL Reboot
COM32 reboot.c32
LABEL poweroff
MENU LABEL Poweroff
COM32 poweroff.c32
EOF
root_own "${fs}" "boot/syslinux/syslinux.cfg"
# Generate the hostname.
printf 'takahe\n' > "${fs}/etc/hostname"
root_own "${fs}" 'etc/hostname'
# Generate an empty fstab.
: > "${fs}/etc/fstab"
root_own "${fs}" 'etc/fstab'
# Add the init scripts.
cat > "${fs}/etc/init.d/run" << EOF
#!/usr/bin/sh
/usr/bin/getty -l /usr/bin/login 0 /dev/console
EOF
chmod +x "${fs}/etc/init.d/run"
root_own "${fs}" 'etc/init.d/run'
# Create a repo on the CDROM, for ease of access.
install -dm0755 "${fs}/repo"
cp "${configdir}/pkgs/"* "${fs}/repo/"
# Point pacman at the local repo.
sed -i "${fs}/etc/pacman.conf" -e 's:/mnt/repo:/repo:'
# Generate the iso.
# We need -rock (rock ridge extensions) and -no-emul-boot to let us have
# extended permissions and such exotic things as symlinks!
message info "Creating the iso..."
mkisofs -b 'usr/lib/syslinux/bios/isolinux.bin' \
-c 'usr/lib/syslinux/bios/boot.cat' \
-boot-load-size 4 -boot-info-table \
-rock -no-emul-boot "${fs}" > "${iso}" || \
error 3 "Failed to generate the iso!"
message info "Created iso '${iso}'!"
message info "To burn the image to a cd, run"
message info "# cdrecord dev=/dev/cdrom -v -sao '${iso}'"
message info "where -sao is replaced by -tao or similar if required"
# Clean up...
rm -rf "${fs}"
}
# Parse the arguments.
CONFIGDIR="" # Set the initial config dir.
ISOFILE="" # Set the iso file.
EXTRA="" # Extra packages to install.
parseargs "$@" # Initial argument parse.
# Manual argument parse.
for arg in "$@"; do
ignore_arg "${arg}" || \
case "${arg}" in
*) if [ -z "${CONFIGDIR}" ]; then
CONFIGDIR="${arg}"
elif [ -z "${ISOFILE}" ]; then
ISOFILE="${arg}"
else
EXTRA+=" ${arg}"
fi;;
esac
done
setup "${CONFIGDIR}"
if [ -z "${ISOFILE}" ]; then
error 2 "No iso file specified!"
fi
main "${CONFIGDIR}" "${ISOFILE}" ${EXTRA}