-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·113 lines (94 loc) · 3.33 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
#
# Post-install Setup configuration
#
# Copyright (C) 2021 Rodrigo Silva (MestreLion) <[email protected]>
# License: GPLv3 or later, at your choice. See <http://www.gnu.org/licenses/gpl>
#
# Tasks performed:
# - If a config file is not provided, create and install one from template
# - Install the bash-completion file
# - Install the executable(s)
# - Install and upgrade extra repositories and packages
###############################################################################
DESCRIPTION='Setup Configuration'
mydir=$(dirname "$(readlink -f "$0")")
setuplib=${SETUP_LIB_PATH:-"$mydir"/setuplib}
if [[ -r "$setuplib" ]]; then
# shellcheck source=setuplib
source "$setuplib"
else
echo "Setup library not found: $setuplib" >&2; exit 1;
fi
#------------------------------------------------------------------------------
if ! [[ -v SETUP_REPOSITORIES ]]; then SETUP_REPOSITORIES=(universe multiverse); fi
if ! [[ -v SETUP_PACKAGES ]]; then SETUP_PACKAGES=(); fi
#------------------------------------------------------------------------------
execdir=$BIN_HOME # TODO: add SETUP_PREFIX to allow system-wide install
bashcompdir=${BASH_COMPLETION_USER_DIR:-${DATA_HOME}/bash-completion}/completions
execfile=$execdir/$SETUP_SLUG
bashcompfile=$bashcompdir/$SETUP_SLUG
#------------------------------------------------------------------------------
show_settings() {
if ! ((SETUP_VERBOSE)); then return; fi
message "Settings from environment and parsed from config file:"
set | grep -E '^SET(UP|EN)_' | sort || :
}
#------------------------------------------------------------------------------
if [[ ! -f "$SETEN_CONFIG" ]]; then
message "Install config file: ${SETEN_CONFIG}"
install --mode 600 -DT -- "$mydir"/seten.template.conf "$SETEN_CONFIG"
fi
if ((SETUP_INTERACTIVE)); then
while true; do
editor "$SETEN_CONFIG"
# shellcheck source=setuplib
source "$setuplib"
show_settings
if confirm "Proceed with those settings?"; then break; fi
done
else
# shellcheck source=setuplib
source "$setuplib"
fi
# SETUP_DIR is intentionally set to $mydir here and (indirectly) in setuplib
# Hardcode it in seten.sh.in and seten.bash-completion.in
# Only bootstrap.sh read it from config file.
message "Install main executable: ${execfile}"
mkdir -p -- "$execdir"
awk \
-v SETUP_DIR="$(printf '%q' "$mydir")" \
'{
sub("@@SETUP_DIR@@", SETUP_DIR)
print
}' \
"$mydir"/seten.sh.in > "$execfile"
chmod +x -- "$execfile"
message "Install bash completion: ${bashcompfile}"
mkdir -p -- "$bashcompdir"
awk \
-v SETUP_DIR="$( printf '%q' "$mydir")" \
-v SETUP_SLUG="$(printf '%q' "$SETUP_SLUG")" \
'{
sub("@@SETUP_SLUG@@", SETUP_SLUG)
sub("@@SETUP_DIR@@", SETUP_DIR)
print
}' \
"$mydir"/seten.bash-completion.in > "$bashcompfile"
message "Enable extra repositories"
for repo in "${SETUP_REPOSITORIES[@]}"; do
setup_run sudo add-apt-repository -y --no-update "$repo"
done
message "Upgrade packages"
setup_run sudo apt update
setup_run sudo apt -y full-upgrade
message "Install extra packages"
install_package "${SETUP_PACKAGES[@]}"
setup_run sudo apt -y autoremove
if [[ "$PATH" =~ (^|:)"$execdir"(:|$) ]]; then
message "Done! Use the command '${SETUP_SLUG}' to run setup scripts"
else
message "Done! Add '${execdir}' to your \$PATH to enable " \
"the command '${SETUP_SLUG}' to run setup scripts"
echo "PATH=\$PATH:${execdir}"
fi