-
Notifications
You must be signed in to change notification settings - Fork 1
/
jbuild
executable file
·216 lines (180 loc) · 6 KB
/
jbuild
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env bash
readonly TODAY_DATE=$(date +%Y.%m.%d)
readonly SCRIPT_DATE="v2023.04.15.r3"
# Build variables
readonly WORKING="working"
readonly OUTPUT="output"
readonly SOURCE="archlive"
readonly LIVEROOT="airootfs"
readonly CONFIG="jovarkos-config"
function error() {
printf "%b\n" "[\e[1m\e[91mERROR\e[0m]: ${0##*/}: $*" >&2
}
function clean () {
echo "Cleaning ${WORKING} directory..."
sudo rm -rf ${WORKING}
}
function run_iso() {
qemu-system-x86_64 \
-boot order=d,menu=on,reboot-timeout=5000 \
-m size=3072,slots=0,maxmem=$((3 << 20)) \
-smp 2 \
-k en-us \
-name archiso,process=archiso_0 \
-device virtio-scsi-pci,id=scsi0 \
-display sdl \
-vga virtio \
-audiodev pa,id=snd0 \
-device ich9-intel-hda \
-device hda-output,audiodev=snd0 \
-device virtio-net-pci,romfile=,netdev=net0 -netdev user,id=net0,hostfwd=tcp::60022-:22 \
-machine type=q35,smm=on,accel=kvm,usb=on,pcspk-audiodev=snd0 \
-global ICH9-LPC.disable_s3=1 \
-enable-kvm \
-serial stdio \
-no-reboot \
-cdrom "$1"
}
function list_profiles() {
cat << OPTIONS
Options for '-p' and '--profile':
Profile - see <https://wiki.archlinux.org/title/Archiso#Prepare_a_custom_profile>
for more information
- Use either 'releng' (Used in Official Monthly Builds) or 'baseline' (Minimal live configuration) as the profile name.
- Profiles live in the /usr/share/archiso/configs/ directory. Listed below is a list of profiles found on this machine.
OPTIONS
echo "Available profiles:"
# Prevent globbing errors
[[ -d /usr/share/archiso/configs && -r /usr/share/archiso/configs ]] && {
[[ -s /usr/share/archiso/configs ]] && {
profiles=(/usr/share/archiso/configs/*)
# Strip directory components
printf '%s\n' "${profiles[@]##*/}"
}
}
}
function profile() {
# If no profile is specified, list available profiles
if (( "${#1}" )); then
if (( "${#2}" )); then
# If no path is specified, use the default path
cp -r "/usr/share/archiso/configs/$1" $2
cat << MESSAGE
Copied profile $1 to $2
Please edit files in $2 to customize your ISO. Then run 'jbuild -b' from ${PWD} to build your ISO
MESSAGE
else
cp -r "/usr/share/archiso/configs/$1" ${SOURCE}
cat << MESSAGE
Copied profile $1 to ${SOURCE}
Please edit files in ${SOURCE} to customize your ISO. Then run 'jbuild -b' from ${PWD} to build your ISO
MESSAGE
fi
else
list_profiles
exit 1
fi
}
function usage() {
cat << USAGE
Usage: jbuild [FLAG] [OPTIONS]
Options:
-b, --build Clean working directory and build fresh ISO image using defaults from the ${SOURCE}/profiledef.sh file
-r, --run <path to iso> Run ISO image
-p, --profile <profile name> Create new profile using the specified profile name. Run without options to see available profiles.
-h, --help Print this help message
-v, --version Get the version of this script
Users may also omit '--' in the options above.
USAGE
version
}
m=0
for dep in make mkarchiso; do
type -P "${dep}" &> /dev/null || {
error "${dep} is not installed. Please install it and try again."
# Count missing dependencies
(( m++ ))
}
done
# Fail when one or more are missing
(( m )) && exit 1
# Parse command-line options and arguments, send to functions as needed
while (( $# )); do
case "$1" in
(-b | --build | build)
[[ -d "${SOURCE}" ]] || {
cat << MENU
Please select profile to build upon:
releng (Used in Official Monthly Builds)
baseline (Minimal live configuration)
MENU
read -r -p "Profile: " PROFILE
cp -r "/usr/share/archiso/configs/${PROFILE}" ${SOURCE}
echo "Copied profile ${PROFILE} to ${SOURCE}"
}
echo "Clearing ${WORKING} directory before beginning..."
sudo rm -rf ${WORKING}
if [[ -d "${CONFIG}" ]]; then
echo "${CONFIG} directory already exists. Continuing..."
echo "Copying ${CONFIG}/archlive to $(pwd)..."
sudo cp ${CONFIG}/archlive . -r
else
echo "JovarkOS configuration directory not found in $(pwd). Skipping..."
fi
echo "Building ISO..."
sudo mkarchiso -v -w ${WORKING} -o ${OUTPUT} ${SOURCE} -P "JovarkOS Development Team" -L "JovarkOS Live ${TODAY_DATE}" -A "JovarkOS Live"
echo "Build complete. ISO is located at ${OUTPUT}/jovarkos-${TODAY_DATE}-x86_64.iso"
sudo chmod -R 777 ${OUTPUT}
clean
exit 0
;;
(-r | --run | run)
run_iso "$2"
exit 0
;;
(-c | --clean | clean)
clean
exit 0
;;
(-p | --profile | profile)
# If no profile is specified, list available profiles
if (( "${#2}" )); then
# If no path is specified, use the default path
if (( "${#3}" )); then
# If a path is specified, use that path
profile "$2" "$3"
exit 0
else
profile "$2"
exit 0
fi
else
list_profiles
exit 1
fi
;;
(--profiles | profiles)
# If no profile is specified, list available profiles
list_profiles
exit 1
;;
(-h | --help | help)
usage
exit 0
;;
(-v | --version | version)
echo "JovarkOS ISO build script ${SCRIPT_DATE}"
exit 0
;;
(*)
error "Invalid option: ${1@Q}"
usage
exit 1
;;
esac
done
(( $# )) || {
error "Please provide an argument.\n"
usage
exit 1
}