-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsynth
executable file
·173 lines (122 loc) · 3.6 KB
/
synth
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
#! /bin/sh
case "$1" in
( -h | --help )
put "synth: Generate the ISO image described in the given file." \
"" \
"Usage:" \
" synth opts Where opts is any option." \
" synth args Where args are the arguments." \
"" \
"Options:" \
" -h,--help Show this help." \
"" \
"Arguments:" \
" file img Given file as input, generate the ISO image img." \
" img is optional. If not passed, it will be named after file."
exit;;
esac
# Functions.
put () { printf "%b\n" "$@"; }
err () { put "synth: \e[31mError:\e[0m $*" >&2; exit 1; }
get_k () { put "$desc" | grep "$1" | cut -d " " -f 2-; }
setup_base () {
sys_base=$(get_k BASE)
case "$sys_base" in
( @URL:* ) tmp=$(mktemp)
wget -qO $tmp "${sys_base#@URL:}"
tar xf "$tmp" -C "$tmp_root";;
( @LOCAL:* ) tar xf "${sys_base#@LOCAL:}" -C "$tmp_root";;
( * ) pull "$tmp_root" "$sys_base";;
esac
test -x "${input%/*}/preinst" ||
return
cp "${input%/*}/preinst" "$tmp_root"
runch "$tmp_root" "/preinst"
rm -rf "$tmp_root/preinst"
}
install_pkgs () {
pm=$(get_k PACKAGE_MANAGER)
pkgs=$(get_k PACKAGES)
case "$pm" in
( pacman )
pm_u="$pm --noconfirm -Syu"
pm_i="$pm --noconfirm -S";;
( apt )
pm_u="$pm -y upgrade"
pm_i="$pm -y install";;
( apk )
pm_u="$pm update"
pm_i="$pm add";;
( "" )
put " :: Warning: No package manager specified."
return;;
( * ) err "Unsupported package manager '$pm'. Aborting.";;
esac
runch $tmp_root $pm_u
test "$pkgs" || {
put " :: Warning: No additional packages were specified."
return
}
runch "$tmp_root" $pm_i $pkgs
test -x "${input%/*}/postinst" ||
return
runch \
-m "${input%/*}/postinst:/postinst" \
-r "/postinst" \
"$tmp_root" "/postinst"
}
setup_bootloader () {
get_k BOOT_FILES | while read item; do
src="$tmp_root/${item%=>*}"
dst="$iso_dir/${item#*=>}"
src_path="${src%/*}"
dst_path="${dst%/*}"
test -e "$src" ||
err "'$src' does not exist."
mkdir -p "$dst_path"
cp -r "$src" "$dst"
done
}
# Start the build.
root_sfs=rootfs.sfs
tmp_root=$(mktemp -d $(pwd)/.tmp.XXXX)
iso_dir=$(mktemp -d $(pwd)/.tmp.XXXX)
input="${1:-synthfile}"
output="${2:-img.iso}"
test -f "$input" ||
err "'$input' is not a file."
# Remove waste after the build.
trap "rm -rf '$tmp_root' '$iso_dir'" EXIT HUP INT TERM
# TODO FIXME
# Stop doing parsing, use bcf instead.
desc=$(
sed -E \
-e ":x N" \
-e "/,$/ b x" \
-e "/[A-Z_][ \t]*$/ b x" \
-e "s/,\n[ \t]*/ /g" \
-e "s/([A-Z_]+)\n*[ \t]*/\1 /g" \
-e "s/[ \t]*->[ \t]*/->/g" \
"$input"
)
setup_base
install_pkgs
setup_bootloader
# All done. Generate the artifacts.
mksquashfs "$tmp_root" \
"$iso_dir/$root_sfs" \
-b 1M \
-comp xz \
-no-progress
mkiso -u "$(get_k UPDATE_URL)" \
-s "$(get_k HASH_URL)" \
-r "$(get_k RELEASE)" \
$(test $(get_k BIOS_BOOT) = on && put "-b") \
$(test $(get_k UEFI_BOOT) = on && put "-e") \
"$iso_dir" \
"$output"
zsyncmake "$output" \
-u "$(get_k UPDATE_URL)" \
-o "$output.zsync"
sha256sum "$output" > "$output.sha256sum"
put "$output"*