3 # SPDX-License-Identifier: GPL-3.0
6 # Twitter: @kokkiemouse
7 # Email : kokkiemouse@gmail.com
17 script_path=$(readlink -f "${0%/*}")
18 cache_dir="${script_path}/cache"
20 work_dir="${script_path}/work"
21 channels_dir="${script_path}/channels"
28 out_dir="${script_path}/out"
29 iso_label="${os_name}_${codename}_${arch}"
30 iso_publisher='Fascode Network <https://fascode.net>'
31 iso_application="${os_name} Live/Rescue CD"
32 iso_version="${codename}-$(date +%Y.%m.%d)"
33 iso_filename="${iso_name}-${iso_version}-${arch}.iso"
42 start_time="$(date +%s)"
45 if [[ "${debug}" = true ]]; then
48 _current_time="$(date +%s)"
49 _time="$(("${_current_time}"-"${start_time}"))"
51 if [[ "${_time}" -ge 3600 ]]; then
52 echo "[$(date -d @${_time} +%H:%M.%S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
53 elif [[ "${_time}" -ge 60 ]]; then
54 echo "[00:$(date -d @${_time} +%M.%S)]$("${script_path}/echo_color" -t 6 "[LUBS Core]")"
56 echo "[00:00.$(date -d @${_time} +%S)] $("${script_path}/echo_color" -t 6 "[LUBS Core]")"
59 "${script_path}/echo_color" -t 6 "[LUBS Core]"
63 # Show an INFO message
68 echo "$(_msg_common) $("${script_path}/echo_color" -t 2 "Info:") ${_msg}"
71 # Show an debug message
72 # _msg_debug <message>
74 if [[ "${debug}" = true ]]; then
77 echo "$(_msg_common) $("${script_path}/echo_color" -t 3 "Debug:") ${_msg}"
81 # Show an ERROR message then exit with status
82 # _msg_error <message> <exit code>
88 echo "$(_msg_common) $("${script_path}/echo_color" -t 1 "Error:") ${_msg}"
90 if [[ ! ${_error} = 0 ]]; then
99 for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
100 _msg_info "Unmounting ${mount}"
101 umount -fl "${mount}"
105 # Helper function to run make_*() only one time.
111 if [[ ! -e "${work_dir}/build.${name}" ]]; then
112 _msg_info "$(echo $name | sed "s@_@ @g") is starting."
114 _msg_info "$(echo $name | sed "s@_@ @g") was done!"
115 touch "${work_dir}/build.${name}"
122 for mount in "dev" "dev/pts" "proc" "sys" "run/systemd/resolve/stub-resolv.conf"; do
123 if [[ "${mount}" == "run/systemd/resolve/stub-resolv.conf" ]]; then
124 mount --bind /etc/resolv.conf "${work_dir}/airootfs/${mount}"
126 mount --bind /${mount} "${work_dir}/airootfs/${mount}"
130 chroot "${work_dir}/airootfs" "${@}"
132 for mount in $(mount | awk '{print $3}' | grep "$(realpath "${work_dir}")" | sort -r); do
133 umount -fl "${mount}"
138 run_cmd apt-get --no-install-recommends --yes install ${@}
142 # Delete the file if it exists.
143 # For directories, rm -rf is used.
144 # If the file does not exist, skip it.
145 # remove <file> <file> ...
151 for _file in "${_list[@]}"; do
152 _msg_debug "Removeing ${_file}"
154 if [[ -f ${_file} ]]; then
156 elif [[ -d ${_file} ]]; then
164 echo "usage ${0} [options] [channel]"
166 echo " General options:"
168 echo " -a | --arch <str> Set architecture"
169 echo " Default: ${arch}"
170 echo " -c | --codename <str> Set ubuntu codename"
171 echo " Default: ${codename}"
172 echo " -m | --mirror <url> Set apt mirror server."
173 echo " Default: ${mirror}"
174 echo " -o | --out <out_dir> Set the output directory"
175 echo " Default: ${out_dir}"
176 echo " -w | --work <work_dir> Set the working directory"
177 echo " Default: ${work_dir}"
179 echo " -d | --debug "
180 echo " -h | --help This help message and exit"
182 echo "You can switch between installed packages, files included in images, etc. by channel."
190 for _channel in $(ls -l "${channels_dir}" | awk '$1 ~ /d/ {print $9 }'); do
191 if [[ -n $(ls "${channels_dir}/${_channel}") ]] && [[ ! "${_channel}" = "share" ]]; then
192 channel_list+=( "${_channel}" )
196 for _channel in ${channel_list[@]}; do
197 if [[ -f "${channels_dir}/${_channel}/description.txt" ]]; then
198 description=$(cat "${channels_dir}/${_channel}/description.txt")
200 description="This channel does not have a description.txt."
203 echo -ne " ${_channel}"
205 for i in $( seq 1 $(( 23 - ${#_channel} )) ); do
209 echo -ne "${description}\n"
215 if [[ ${EUID} -ne 0 ]]; then
216 _msg_error "This script must be run as root." 1
219 [[ ! -d "${work_dir}" ]] && mkdir -p "${work_dir}"
220 [[ ! -d "${out_dir}" ]] && mkdir -p "${out_dir}"
224 if [[ -z $(grep -h -v ^'#' ${channels_dir}/${channel_name}/codename.${arch} | grep -x ${codename}) ]]; then
225 _msg_error "This codename (${channel_name}) is not supported on this channel (${codename})."
232 statusfile="${cache_dir}/${codename}/status"
235 if [[ ! -d "$(dirname ${statusfile})" ]]; then
236 mkdir -p "$(dirname ${statusfile})"
238 echo "${1}" > "${statusfile}"
241 if [[ -f "${statusfile}" ]] && [[ $(cat "${statusfile}" 2> /dev/null) = "Done" ]]; then
242 _msg_info "${codename} cache is found."
244 remove "${cache_dir}/${codename}"
246 _msg_info "Installing Fedora to '${cache_dir}/${codename}/airootfs'..."
247 mkdir -p "${cache_dir}/${codename}/airootfs"
248 dnf install dnf --releasever=${codename} --installroot="${cache_dir}/${codename}/airootfs" -y
249 _msg_info "${codename} installed successfully!"
253 if [[ "${cache_only}" = true ]]; then
257 rm -rf "${work_dir}/airootfs" && mkdir -p "${work_dir}/airootfs"
258 _msg_info "copy base files from '${cache_dir}/${codename}/airootfs' to '${work_dir}/airootfs'..."
259 rsync -au "${cache_dir}/${codename}/airootfs/" "${work_dir}/airootfs"
260 echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}' >> "${work_dir}/airootfs/etc/bash.bashrc"
261 #run_cmd apt-get update
262 # run_cmd apt-get upgrade