Skip to content

Commit

Permalink
add in ability to run arbitary pkg installs
Browse files Browse the repository at this point in the history
  • Loading branch information
binhex committed Oct 9, 2023
1 parent fabba70 commit ce7b119
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
54 changes: 54 additions & 0 deletions build/root/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
# exit script if return code != 0
set -e

# release tag name from buildx arg, stripped of build ver using string manipulation
RELEASETAG="${1//-[0-9][0-9]/}"

# target arch from buildx arg
TARGETARCH="${2}"

if [[ -z "${RELEASETAG}" ]]; then
echo "[warn] Release tag name from build arg is empty, exiting script..."
exit 1
fi

if [[ -z "${TARGETARCH}" ]]; then
echo "[warn] Target architecture name from build arg is empty, exiting script..."
exit 1
fi

# build scripts
####

Expand Down Expand Up @@ -160,6 +176,14 @@ if [[ ! -z "${VNC_PASSWORD}" ]]; then
echo "[info] VNC_PASSWORD defined as '${VNC_PASSWORD}'" | ts '%Y-%m-%d %H:%M:%.S'
fi
export ENABLE_STARTUP_SCRIPTS=$(echo "${ENABLE_STARTUP_SCRIPTS}" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
if [[ ! -z "${ENABLE_STARTUP_SCRIPTS}" ]]; then
echo "[info] ENABLE_STARTUP_SCRIPTS defined as '${ENABLE_STARTUP_SCRIPTS}'" | ts '%Y-%m-%d %H:%M:%.S'
else
echo "[info] ENABLE_STARTUP_SCRIPTS not defined,(via -e ENABLE_STARTUP_SCRIPTS), defaulting to 'no'" | ts '%Y-%m-%d %H:%M:%.S'
export ENABLE_STARTUP_SCRIPTS="no"
fi
# ENVVARS_PLACEHOLDER
EOF

Expand All @@ -177,6 +201,36 @@ rm /tmp/envvars_heredoc

cat <<'EOF' > /tmp/config_heredoc
if [[ "${ENABLE_STARTUP_SCRIPTS}" == "yes" ]]; then
# define path to scripts
base_path="/config/home"
user_script_src_path="/home/nobody/.build/scripts/example-startup-script.sh"
user_script_dst_path="${base_path}/scripts"
mkdir -p "${user_script_dst_path}"
# copy example startup script
# note slence stdout/stderr and ensure exit code 0 due to src file may not exist (symlink)
if [[ ! -f "${user_script_dst_path}/example-startup-script.sh" ]]; then
cp "${user_script_src_path}" "${user_script_dst_path}/example-startup-script.sh" 2> /dev/null || true
fi
# find any scripts located in "${user_script_dst_path}"
user_scripts=$(find "${user_script_dst_path}" -maxdepth 1 -name '*sh' 2> '/dev/null' | xargs)
# loop over scripts, make executable and source
for i in ${user_scripts}; do
chmod +x "${i}"
echo "[info] Executing user script '${i}' in the background" | ts '%Y-%m-%d %H:%M:%.S'
source "${i}" &
done
# change ownership as we are running as root
chown -R nobody:users "${base_path}"
fi
# call symlink function from utils.sh
symlink --src-path '/home/nobody' --dst-path '/config/home' --link-type 'softlink' --log-level 'WARN'
Expand Down
48 changes: 48 additions & 0 deletions config/nobody/scripts/example-startup-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Example script showing how to install packages from AOR/AUR.

# IMPORTANT
# This script adds in the ability to install addtional application the end user may want,
# please do bear in mind every time the image is updated the container will be deleted
# and reinstallation of all packages listed will occur.

# remove previous pacman lock file if it exists
rm -f /var/lib/pacman/db.lck

# AOR packages
###

# Define AOR (Arch Official Repository) packages you want to install at startup.
# Go to the following URL for a list of available packages:- https://archlinux.org/packages/
#
# If you want to install more than one package then please user a space as a separator.
# Example: To install Docker and Java Runtime 11 you would specify:-
# pacman_packages="docker jre11-openjdk-headless"
pacman_packages=""

# install compiled packages using pacman
if [[ ! -z "${pacman_packages}" ]]; then
pacman -S --needed ${pacman_packages} --noconfirm
fi

# AUR packages
###

# IMPORTANT
# AUR packages may require compiling and thus time to install the application maybe
# (depending on the applications complexity) considerable, plwease be patient and monitor
# progress in the '/config/supervisord.log' file.

# Define AUR (Arch User Repository) packages you want to install at startup.
# Go to the following URL for a list of available packages:- https://aur.archlinux.org/packages/
#
# If you want to install more than one package then please user a space as a separator.
# Example: To install Powershell you would specify:-
# aur_packages="powershell"
aur_packages=""

# install compiled packages using helper 'yay'
if [[ ! -z "${aur_packages}" ]]; then
source '/usr/local/bin/aur.sh'
fi

0 comments on commit ce7b119

Please sign in to comment.