-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-standalone
executable file
·70 lines (56 loc) · 2.17 KB
/
install-standalone
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
#!/usr/bin/env bash
set -e
# shellcheck disable=2046,2086
SCRIPT_DIR="$(realpath $(dirname ${BASH_SOURCE[0]}))"
source "${SCRIPT_DIR}/.env.install"
cd "${BASE_DIR}"
git submodule update --init --recursive
sudoSuffix="-sudo"
exitIfConfigNotFound=false # used as a flag to exit IF a config file is NOT found
for config in ${@}; do
config=${config%"$sudoSuffix"}
configFilepath="${CONFIG_DIR}/${config}.${CONFIG_EXT}"
if [[ ! -e $configFilepath ]]; then
echo -e "Dotbot config \\033[1;31m$configFilepath \\033[0mDOESN'T exists"
exitIfConfigNotFound=true
fi
done
# exit if a config filepath is NOT found
if [[ $exitIfConfigNotFound == true ]]; then
echo -e "\nexiting"
exit 1
fi
# cleanup variables
unset sudoSuffix
unset exitIfConfigNotFound
for config in ${@}; do
# create temporary file
configFile="$(mktemp)"
suffix="-sudo"
echo -e "$(<"${BASE_CONFIG}")\n$(<"${CONFIG_DIR}/${config%"$suffix"}.${CONFIG_EXT}")" > "$configFile"
cmd=("${DOTBOT}" -d "${PACKAGE_DIR}" -c "$configFile")
# print a line depending on the terminal width
# get terminal width: https://unix.stackexchange.com/a/425158
# print a line of : https://stackoverflow.com/a/17030976/3053548
printf '%0.s=' $(seq 1 $(stty size | awk '{print $2}'))
echo -e "\nConfigure $config\n"
if [[ $config == *"sudo"* ]]; then
# - pass tools/zsh/zshenv file when running in sudo to load ENV
# - Why?
# - some of the dotbot configs are using using sudo and XDG envs defined in ./tools/zsh/zshenv
# - set HOME to current home user path
# - Why?
# - when running in sudo, the XDG env tools/zsh/zshenv are not not loaded
#
# - passing ENV in sudo https://unix.stackexchange.com/a/396528
# - setting BASH_ENV https://unix.stackexchange.com/a/429235
# - setting env HOME : assuming dotfiles repo is in the Home folder
# - requires full directory path
# cmd=(sudo env HOME="$(echo $HOME)" BASH_ENV="./tools/zsh/zshenv" "${cmd[@]}")
cmd=(sudo "${cmd[@]}")
fi
"${cmd[@]}"
rm -f "$configFile"
done
cd "${BASE_DIR}"
echo "Restart your terminal..."