-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move script installation into a separate file
- Loading branch information
1 parent
8ee4010
commit 21f8d2e
Showing
2 changed files
with
89 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters