3 # SPDX-License-Identifier: GPL-3.0
6 # Twitter: @kokkiemouse
7 # Email : kokkiemouse@gmail.com
17 script_path=$(readlink -f "${0%/*}")
18 work_dir="${script_path}/work"
19 channels_dir="${script_path}/channels"
26 out_dir="${script_path}/out"
27 iso_label="${os_name}_${codename}_${arch}"
28 iso_publisher='Fascode Network <https://fascode.net>'
29 iso_application="${os_name} Live/Rescue CD"
30 iso_version="${codename}-$(date +%Y.%m.%d)"
31 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
40 start_time="$(date +%s)"
43 if [[ "${debug}" = true ]]; then
46 _current_time="$(date +%s)"
47 _time="$(("${_current_time}"-"${start_time}"))"
49 if [[ "${_time}" -ge 3600 ]]; then
50 echo "[$(date -d @${_time} +%H:%M.%S)]$("${script_path}/echo_color" -t 6 "[LFBS Core]")"
51 elif [[ "${_time}" -ge 60 ]]; then
52 echo "[00:$(date -d @${_time} +%M.%S)]$("${script_path}/echo_color" -t 6 "[LFBS Core]")"
54 echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LFBS Core]")"
57 "${script_path}/echo_color" -t 6 "[LFBS Core]"
61 # Show an INFO message
66 echo "$(_msg_common) $("${script_path}/echo_color" -t 2 "Info:") ${_msg}"
69 # Show an debug message
70 # _msg_debug <message>
72 if [[ "${debug}" = true ]]; then
75 echo "$(_msg_common) $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}"
79 # Show an ERROR message then exit with status
80 # _msg_error <message> <exit code>
86 echo "$(_msg_common) $("${script_path}/echo_color" -t 1 "Error:") ${_msg}"
88 if [[ ! ${_error} = 0 ]]; then
97 for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
98 _msg_info "Unmounting ${mount}"
103 # Helper function to run make_*() only one time.
109 if [[ ! -e "${work_dir}/build.${name}" ]]; then
110 _msg_info "$(echo $name | sed "s@_@ @g") is starting."
112 _msg_info "$(echo $name | sed "s@_@ @g") was done!"
113 touch "${work_dir}/build.${name}"
120 for mount in "dev" "dev/pts" "proc" "sys" "etc/resolv.conf"; do
121 #for mount in "dev" "dev/pts" "proc" "sys" ; do
122 if [[ "${mount}" == "etc/resolv.conf" ]]; then
123 cp /etc/resolv.conf "${work_dir}/airootfs/${mount}"
125 mount --bind /${mount} "${work_dir}/airootfs/${mount}"
129 chroot "${work_dir}/airootfs" "${@}"
131 for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
132 umount -fl "${mount}"
137 run_cmd dnf install -y ${@}
141 # Delete the file if it exists.
142 # For directories, rm -rf is used.
143 # If the file does not exist, skip it.
144 # remove <file> <file> ...
150 for _file in "${_list[@]}"; do
151 _msg_debug "Removeing ${_file}"
153 if [[ -f ${_file} ]]; then
155 elif [[ -d ${_file} ]]; then
163 echo "usage ${0} [options] [channel]"
165 echo " General options:"
167 echo " -a | --arch <str> Set architecture"
168 echo " Default: ${arch}"
169 echo " -c | --codename <str> Set ubuntu codename"
170 echo " Default: ${codename}"
171 echo " -m | --mirror <url> Set apt mirror server."
172 echo " Default: ${mirror}"
173 echo " -o | --out <out_dir> Set the output directory"
174 echo " Default: ${out_dir}"
175 echo " -w | --work <work_dir> Set the working directory"
176 echo " Default: ${work_dir}"
178 echo " -d | --debug "
179 echo " -h | --help This help message and exit"
181 echo "You can switch between installed packages, files included in images, etc. by channel."
189 for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
190 if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
191 channel_list+=( "${_channel}" )
195 for _channel in ${channel_list[@]}; do
196 if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then
197 description=$(cat "${channels_dir}/${_channel}/description.txt")
199 description="This channel does not have a description.txt."
202 echo -ne " ${_channel}"
204 for i in $( seq 1 $(( 23 - ${#_channel} )) ); do
208 echo -ne "${description}\n"
214 if [[ ${EUID} -ne 0 ]]; then
215 _msg_error "This script must be run as root." 1
218 [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
219 [[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
223 if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
224 _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
230 remove "${work_dir}/${codename}"
231 _msg_info "Installing Fedora to '${work_dir}/airootfs'..."
232 mkdir -p "${work_dir}/airootfs"
233 dnf --installroot="${work_dir}/airootfs" $(${script_path}/system/repository-json-parser.py ${script_path}/system/repository.json) groupinstall core -y
234 _msg_info "${codename} installed successfully!"
236 echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' > "${work_dir}/airootfs/etc/bash.bashrc"
237 run_cmd dnf upgrade -y
238 run_cmd dnf -y remove $(run_cmd dnf repoquery --installonly --latest-limit=-1 -q)
239 run_cmd dnf clean all
240 # run_cmd apt-get upgrade
245 if [[ ${EUID} -ne 0 ]]; then
246 _msg_error "This script must be run as root." 1
249 [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
250 [[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
254 if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
255 _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
261 _dnf_install dbus-tools
262 run_cmd dbus-uuidgen --ensure=/etc/machine-id
263 run_cmd mkdir /var/lib/dbus
264 run_cmd ln -sf /etc/machine-id /var/lib/dbus/machine-id
266 make_dnf_packages() {
267 remove "${work_dir}/airootfs/dnfpkglist"
268 #_apt_install initramfs-tools
269 # run_cmd env -i bash -c 'DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade --yes'
271 if [[ -f "${channels_dir}/share/packages.${arch}" ]]; then
272 grep -h -v ^'#' "${channels_dir}/share/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
275 if [[ -f "${channels_dir}/${channel_name}/packages.${arch}" ]]; then
276 grep -h -v ^'#' "${channels_dir}/${channel_name}/packages.${arch}" | grep -v "^$" >> "${work_dir}/airootfs/dnfpkglist"
279 if [[ -s "${work_dir}/airootfs/dnfpkglist" ]]; then
280 run_cmd env -i bash -c 'dnf -y --nogpgcheck install $(echo $(<dnfpkglist))'
283 remove "${work_dir}/airootfs/dnfpkglist"
287 # 参考記事:https://0e0.pw/ci83 https://0e0.pw/VJlg
289 _opt_short="w:o:ha:-:m:c:d"
290 _opt_long="help,arch:,codename:,debug,help,mirror:,out:,work,cache-only"
291 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
293 if [[ ${?} != 0 ]]; then
302 if [[ -z ${2} ]]; then
303 _msg_error "Please specify the architecture."
311 if [[ -z ${2} ]]; then
312 _msg_error "Please specify the codename."
328 if [[ -z ${2} ]]; then
329 _msg_error "Please specify the mirror server."
338 if [[ -z ${2} ]]; then
339 _msg_error "Please specify the out dir."
348 if [[ -z ${2} ]]; then
349 _msg_error "Please specify the out dir."
366 _msg_error "Invalid argument '${1}'"
372 bootfiles_dir="${work_dir}/bootfiles"
373 trap umount_chroot 0 2 15
375 if [[ -n "${1}" ]]; then
383 for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
384 if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
385 channel_list+=( "${_channel}" )
389 for i in ${channel_list[@]}; do
390 if [[ "${i}" = "${channel_name}" ]]; then
400 if [[ $(check_channel ${channel_name}) = false ]]; then
401 _msg_error "Invalid channel ${channel_name}"
409 run_once make_systemd
410 run_once make_dnf_packages
412 run_once make_add_user
414 run_once make_squashfs
418 run_once make_checksum