Finished converting build.sh

This commit is contained in:
Storm Dragon 2019-12-12 10:18:42 -05:00
parent 059d94b125
commit 7e4f67ce47

View File

@ -86,7 +86,7 @@ eval set -- "$options"
# Declare the overrides that will replace configuration file variables with command line options
declare -A overrides=()
while test $# -gt 0; do
while [[ $# -gt 0 ]]; do
case $1 in
-d|--work-directory) overrides[workdir]="$2"; shift 2 ;;
-H|--hostname) overrides[hostname]="$2"; shift 2 ;;
@ -115,7 +115,7 @@ while test $# -gt 0; do
-w|--wifi-password) overrides[wifipass]="$2"; shift 2 ;;
(--) shift ;;
(*)
if test -f "$1"; then
if [[ -f "$1" ]]; then
source "$1"
else
echo "Invalid configuration file specified." | log
@ -127,15 +127,34 @@ while test $# -gt 0; do
done
# Replace configuration variables using the overrides gathered from command line options
test "${overrides[workdir]}" && workdir="${overrides[workdir]}"
test "${overrides[hostname]}" && hostname="${overrides[hostname]}"
test "${overrides[networkname]}" && networkname="${overrides[networkname]}"
test "${overrides[imagename]}" && imagename="${PWD}/${overrides[imagename]}"
test "${overrides[userpass]}" && userpass="${overrides[userpass]}"
test "${overrides[rootpass]}" && rootpass="${overrides[rootpass]}"
test "${overrides[imagesize]}" && imagesize="${overrides[imagesize]}"
test "${overrides[username]}" && username="${overrides[username]}"
test "${overrides[wifipass]}" && wifipass="${overrides[wifipass]}"
if [[ "${overrides[workdir]}" ]]; then
workdir="${overrides[workdir]}"
fi
if [[ "${overrides[hostname]}" ]]; then
hostname="${overrides[hostname]}"
fi
if [[ "${overrides[networkname]}" ]]; then
networkname="${overrides[networkname]}"
fi
if [[ "${overrides[imagename]}" ]]; then
imagename="${PWD}/${overrides[imagename]}"
fi
if [[ "${overrides[userpass]}" ]]; then
userpass="${overrides[userpass]}"
fi
if [[ "${overrides[rootpass]}" ]]; then
rootpass="${overrides[rootpass]}"
fi
if [[ "${overrides[imagesize]}" ]]; then
imagesize="${overrides[imagesize]}"
fi
if [[ "${overrides[username]}" ]]; then
username="${overrides[username]}"
fi
if [[ "${overrides[wifipass]}" ]]; then
wifipass="${overrides[wifipass]}"
fi
# export workdir so it is available in subshells.
export workdir
@ -153,9 +172,9 @@ check_deps
# Before building an image, we must be sure that the work directory is clean except for a package cache.
# There is not yet a facility to complete a half-built failed image, but we can cache software packages.
if [ -d "$workdir" ]; then
clean_up "$workdir" || true
# Don't remove an otherwise empty work directory if a pacman cache is present
[ -d "${workdir}/pacman-cache" ] || rm -Rv "$workdir" |& log
clean_up "$workdir" || true
# Don't remove an otherwise empty work directory if a pacman cache is present
[[ -d "${workdir}/pacman-cache" ]] || rm -Rv "$workdir" |& log
fi
# Start by creating an empty image and mounting it.
@ -184,22 +203,17 @@ add_groups "${workdir}/root" |& log
add_user "${workdir}/root" "${username}" |& log
set_password "${workdir}/root" "${username}" "${userpass}" |& log
# Install packages from the AUR
# This is optional, and will only run if an AUR package list is set in the config file passed to this script.
test $aurlist && ./aur-install -l "$aurlist" "${workdir}/root" |& log
# Copy any override files into the new system. This overrides any system and user configuration files or scripts installed with packages.
# Remove any stale temporary files related to the file and content repositories
rm -Rfv /tmp/files-F123Light /tmp/content-F123Light |& log
rm -Rfv /tmp/stormux |& log
# Start by cloning the files-F123Light and content-F123Light repositories.
git clone -b $(git branch | grep \* | cut -f2 -d \ ) --recurse-submodules https://gitlab.com/F123/files-F123Light.git /tmp/files-F123Light |& log
git clone https://gitlab.com/F123/content-F123Light.git /tmp/content-F123Light |& log
# Start by cloning the stormux repository to /tmp
git clone -b $(git branch | grep \* | cut -f2 -d \ ) --recurse-submodules https://gitlab.com/stormux/stormux.git /tmp/stormux |& log
# Copy in the files.
cp -Rv /tmp/files-F123Light/files/* "${workdir}/root/" |& log
cp -Rv /tmp/stormux/files/files/* "${workdir}/root/" |& log
# Generate translations:
find /tmp/files-F123Light/locales -type f -iname '*.po' -exec bash -c '
find /tmp/stormux/locales -type f -iname '*.po' -exec bash -c '
for i ; do
# i is in file, o is outfile.
language="$(grep "^\"Language: .*\\n" "${i}" | cut -d " " -f2 | cut -d "\\" -f1)"
@ -212,13 +226,7 @@ find /tmp/files-F123Light/locales -type f -iname '*.po' -exec bash -c '
msgfmt "$i" -o "${workdir}/root/usr/share/locale/${language}/LC_MESSAGES/${o}"
done' _ {} +
mkdir -p "${workdir}/root/usr/share/doc/stormux" |& log
cp -Rv /tmp/content-F123Light/F123/* "${workdir}/root/usr/share/doc/F123/" |& log
# remove the temporary files again.
rm -Rv /tmp/files-F123Light /tmp/content-F123Light |& log
# Now copy any override files from this repository.
cp -Rv ../files/* "${workdir}/root/" || true |& log
cp -Rv /tmp/stormux/content/stormux/* "${workdir}/root/usr/share/doc/stormux/" |& log
# Set the system locale and generate all other locales specified in the configuration file.
# The default system locale must be set before we can copy user files to $HOME.
@ -242,12 +250,10 @@ systemd-nspawn -a -q -D $workdir/root\
download_package_databases $workdir/root |& log
set_fake_hwclock $workdir/root |& log
# Set gsettings keys to enable Orca
# This is optional, and cannot run on a text only system.
[ $gsettings ] && ./gsettings "${workdir}/root" |& log
# Configure wifi if network information is present in the configuration file.
test $networkname && setup_wifi $workdir/root wlan0 $networkname $wifipass |& log
if [[ -n "$networkname" ]]; then
setup_wifi $workdir/root wlan0 $networkname $wifipass |& log
fi
# Touch the firstboot file. It will be deleted by the firstboot script that looks for it.
systemd-nspawn -a -q -D $workdir/root\
@ -256,12 +262,14 @@ systemd-nspawn -a -q -D $workdir/root\
# Write a system timestamp.
# This timestamp will determine which incremental updates apply to this image
echo "$(date +%y%m%d%H%M)" > $workdir/root/etc/timestamp-f123light
echo "$(date +%y%m%d%H%M)" > $workdir/root/etc/timestamp-stormux
# Unmount the image file
clean_up "$workdir" |& log
# Keep the work directory if a pacman cache exists, otherwise remove it
[ -d "${workdir}/pacman-cache" ] || rm -Rv "$workdir" |& log
if [[ ! -d "${workdir}/pacman-cache" ]]; then
rm -Rv "$workdir" |& log
fi
# Once all scripts have completed, come back to the directory from which this script was launched.
cd $current && echo "cd $current" |& log