Skip to content

Commit

Permalink
move script installation into a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
brettaufheber committed Dec 31, 2023
1 parent b82e163 commit 78496bc
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 58 deletions.
89 changes: 89 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

function main {

# declare local variables
local OPTIONS_PARSED

# set default values and configuration
SELF_PATH="$(readlink -f "$0")"
SELF_NAME="$(basename "$SELF_PATH")"
WITH_DESKTOP_HELPERS=false

# parse arguments
OPTIONS_PARSED=$(
getopt \
--options 'd' \
--longoptions 'with-desktop-helpers' \
--name "$SELF_NAME" \
-- "$@"
)

# replace arguments
eval set -- "$OPTIONS_PARSED"

# apply arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-d | --with-desktop-helpers)
WITH_DESKTOP_HELPERS=true
shift 1
;;
--)
shift 1
break
;;
*)
break
;;
esac
done

# check if there is no unassigned argument left
if [[ $# -ne 0 ]]; then
echo "$SELF_NAME: cannot handle unassigned arguments: $*" >&2
exit 1
fi

task_install_script
}

function verify_root_privileges {

if [[ $EUID -ne 0 ]]; then
echo "$SELF_NAME: require root privileges" >&2
exit 1
fi
}

function task_install_script {

# declare local variables
local TEMPDIR
local SBINDIR
local ENTRY

# verify preconditions
verify_root_privileges

TEMPDIR="$(mktemp -d)"
SBINDIR='/usr/local/sbin'

git clone 'https://github.com/brettaufheber/ubuntu-headless-installer.git' "$TEMPDIR"

cp -v "$TEMPDIR/ubuntu-installer.sh" "$SBINDIR"
chmod a+x "$SBINDIR/ubuntu-installer.sh"

if "$WITH_DESKTOP_HELPERS"; then
for ENTRY in "$TEMPDIR/desktop-helpers"/*; do
cp -v "$ENTRY" "$SBINDIR"
chmod a+x "$SBINDIR/$(basename "$ENTRY")"
done
fi

rm -rf "$TEMPDIR"
}

set -euo pipefail
main "$@"
exit 0
58 changes: 0 additions & 58 deletions ubuntu-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ function main {

# select task
case "$TASK" in
install-script)
task_install_script
;;
install-desktop-helpers)
task_install_desktop_helpers
;;
update)
task_update
;;
Expand Down Expand Up @@ -386,52 +380,6 @@ function verify_mounting_boot {
fi
}

function task_install_script {

# declare local variables
local TEMPDIR
local BINDIR

# verify preconditions
verify_root_privileges

TEMPDIR="$(mktemp -d)"
BINDIR='/usr/local/sbin'

git clone 'https://github.com/brettaufheber/ubuntu-headless-installer.git' "$TEMPDIR"

cp -v "$TEMPDIR/ubuntu-installer.sh" "$BINDIR"
chmod a+x "$BINDIR/ubuntu-installer.sh"

rm -rf "$TEMPDIR"
}

function task_install_desktop_helpers {

# declare local variables
local TEMPDIR
local BINDIR

# verify preconditions
verify_root_privileges

TEMPDIR="$(mktemp -d)"
BINDIR='/usr/local/sbin'

git clone 'https://github.com/brettaufheber/ubuntu-headless-installer.git' "$TEMPDIR"

for i in "$TEMPDIR/desktop-helpers"/*; do

f="$(basename "$i")"

cp -v "$i" "$BINDIR"
chmod a+x "$BINDIR/$f"

done

rm -rf "$TEMPDIR"
}

function task_update {

# verify preconditions
Expand All @@ -452,9 +400,6 @@ function task_update {
# update via Flatpak package manager
flatpak -y update

# update helper scripts
ubuntu-installer.sh install-desktop-helpers

fi
}

Expand Down Expand Up @@ -1501,9 +1446,6 @@ function configure_desktop {
# add flatpak remote: flathub
chroot "$CHROOT" flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

# install helper scripts
chroot "$CHROOT" "$SELF_NAME" install-desktop-helpers

# modify default GNOME settings
install_default_gnome_settings

Expand Down

0 comments on commit 78496bc

Please sign in to comment.