-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-standalone
executable file
·133 lines (107 loc) · 4.49 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env bash
# used for running individual installation scripts located in ./meta/configs/ folder
# usage:
# ./install-standalone nvim
# ./install-standalone tmux
# ./install-standalone zsh
#
# or
# ./install-standalone nvim tmux zsh
#
# NOTE: to run a config in sudo, then add '-sudo' as a suffix of the config to run.
# Ex: ./install-standalone apt-sudo
# check: https://github.com/ecarlson94/dotbot-template#for-installing-single-configurations
#
# ./meta/configs/ folder will contain .yaml files that will be used as config. It
# has the same directives as the default dotbot install-conf.yaml
# check: https://github.com/anishathalye/dotbot#full-example
#
# obtained from https://github.com/anishathalye/dotbot/wiki/Tips-and-Tricks#install-standalone
# author ecarlson94
set -e
BASE_CONFIG="base.yaml"
CONFIG_SUFFIX="" # 默认值是 ".yaml",这里改成空,可以使用 shell 自动补全生成
META_DIR="meta"
PROFILES_DIR="profiles"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${BASE_DIR}"
git submodule update --init --recursive
# load env variables.
# load XDG dotfile locations. https://wiki.archlinux.org/title/XDG_Base_Directory
#
# Why?
# You can load ENV variables and use them in dotbot configs.
# Ex: setting ENV ALACRITTY_CONFIG_PATH and using it in a dotbot config file
# source tools/zsh/zshenv # file to load ENV variables
# ------------------------------------------------------------------------------------------------ #
# Verify dotbot config files exist.
# Also checks if the config file exists if it has a suffix of '-sudo'. Ex: apt-sudo
# Checks if the file exists in meta/configs/ folder
# Exits program if a dotbot config doesn't exist
sudoSuffix="-sudo"
exitIfConfigNotFound=false # used as a flag to exit IF a config file is NOT found
for config in ${@}; do
# remove suffix '-sudo' in the variable $config
# check if the config filepath doesn't exist
# print message
# flag variable to exit
# remove suffix '-sudo'
# obtained from https://stackoverflow.com/a/16623897/3053548
config=${config%"$sudoSuffix"} # -sudo
configFilepath="${BASE_DIR}/${config}${CONFIG_SUFFIX}" # /Users/eqielb/.local/share/dotfiles/
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
# ------------------------------------------------------------------------------------------------ #
# Run dotbot config, one at a time
# loop through each command line argument
# make a temp file
# concatenate meta/base.yaml and the dotbot config together and place it to a temp file
# run command
# remove temp file
for config in ${@}; do
# create temporary file
configFile="$(mktemp)"
suffix="-sudo"
echo -e "$(<"${BASE_DIR}/${META_DIR}/${BASE_CONFIG}${CONFIG_SUFFIX}")\n$(<"${BASE_DIR}/${config%"$suffix"}${CONFIG_SUFFIX}")" > "$configFile"
cmd=("${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" --plugin-dir "${META_DIR}/dotbot-brew" -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}'))
printf '%0.s=' $(seq 1 $(stty size | awk '{print $2}'))
echo ""
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 ""
echo "Restart your terminal..."