-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-profile
executable file
·153 lines (123 loc) · 4.67 KB
/
install-profile
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -e
# Do not continue until umask is fixed
if [ "$(umask)" = "0000" ]; then
echo "WSL umask was not fixed, cannot continue!"
exit 1
fi
BASE_CONFIG="base"
CONFIG_SUFFIX=".yaml"
META_DIR="meta"
CONFIG_DIR="configs"
PROFILES_DIR="profiles"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLUGIN_DIR="dotbot-plugins"
if [[ $1 = "macos" ]]; then
# Install Xcode command line tools first before use git command
xcode-select --install || echo Xcode command line tools installed.
fi
cd "${BASE_DIR}"
git submodule update --init --checkout --recursive --force
# HACK to make dotbot-brew work since Linuxbrew does not add PATH automatically.
if ! which brew; then
# See https://docs.brew.sh/Installation#unattended-installation
echo "Installing Homebrew..."
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
############
# Linuxbrew
############
if [ -d /home/linuxbrew/.linuxbrew/bin ]; then
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
fi
############
# Homebrew (Intel x86_64)
############
if [ -f /usr/local/bin/brew ]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
############
# Homebrew (Apple Silicon)
############
if [ -f /opt/homebrew/bin/brew ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
fi
# Require to use alias in script, see https://askubuntu.com/questions/98782/how-to-run-an-alias-in-a-shell-script
shopt -s expand_aliases
if [[ $1 == *"macos"* ]]; then
if ! which python2.7; then
echo "Installing Python2 to avoid 'SyntaxWarning for 'is' with literals' on Python 3.8.5 from MacOS Catalina..."
cat <<- "EOF" > ~/install-python2-monterey.sh
#!/bin/bash
export NONINTERACTIVE=1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install kamilturek/python2/python@2
EOF
chmod +x ~/install-python2-monterey.sh && ~/install-python2-monterey.sh
fi
elif [[ $1 == *"centos"* ]] || [[ $1 == *"rocky"* ]]; then
# !NOTE: do NOT use dnf because latest version switch to use SQLite that can't work on WSL1
sudo yum --nogpgcheck -y install python3-pip
fi
# Write update-dotfiles to use later
UPDATE_FILE=~/update-dotfiles.sh
# !BUG: do NOT use source `. .dots` that cause error if source from ZSH.
# shellcheck disable=SC2016
echo 'cd ~/; rm -f .dots; curl "https://raw.githubusercontent.com/nobitagamer/dotfiles/master/.dots?token=$(date +%s)" >.dots && bash .dots' | tee ${UPDATE_FILE}
chmod +x ${UPDATE_FILE}
CONFIGS=("")
PROFILES=("")
for profile in "${@}"; do
echo -e "\nReading profile $profile..."
if [[ $profile != *".yaml" ]]; then
if [ -f "${META_DIR}/${PROFILES_DIR}/$profile" ]; then
PROFILES+=("$profile")
while IFS= read -r config; do
CONFIGS+=("$config")
done < ${META_DIR}/${PROFILES_DIR}/$1
else
echo -e " [$profile] profile NOT FOUND!"
fi
shift
else
CONFIGS+=("$profile")
fi
done
# !Obsoleted: force use Python2 to avoid `SyntaxWarning for 'is' with literals` on Python 3.8.5 from MacOS Catalina
# See https://adamj.eu/tech/2020/01/21/why-does-python-3-8-syntaxwarning-for-is-literal/
which python2 2>/dev/null && alias python=python2
which python2.7 2>/dev/null && alias python=python2.7
which python3 2>/dev/null && alias python=python3
python --version
installcmd=$(cat <<EOF
python "${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" \
-d "${BASE_DIR}" \
--plugin-dir "${META_DIR}/${PLUGIN_DIR}" \
--plugin-dir "${META_DIR}/dotbot-brew" \
--plugin-dir "${META_DIR}/dotbot-pip" \
--plugin-dir "${META_DIR}/dotbot-yum" \
--plugin-dir "${META_DIR}/dotbot-dnf" \
--plugin-dir "${META_DIR}/dotbot-if"
EOF
)
# --plugin-dir "${META_DIR}/dotbot-brewfile" \
# Allow override for specific profile
for profile in ${PROFILES[*]}; do
[ -d "${META_DIR}/${PLUGIN_DIR}/$profile" ] && installcmd+=" --plugin-dir \"${META_DIR}/${PLUGIN_DIR}/$profile\""
done
# !BUG: sort will make configs apply in wrong order.
# Sort configs before apply, see https://stackoverflow.com/questions/7442417/how-to-sort-an-array-in-bash
# IFS=$'\n' CONFIGS=($(sort <<<"${CONFIGS[*]}"))
# unset IFS
# Join remaining args to configs
CONFIGS=(${CONFIGS[*]} ${@})
_cmd="$installcmd -c \"${META_DIR}/${BASE_CONFIG}${CONFIG_SUFFIX}\""
echo - Base install cmd: $_cmd
echo -e "\e[1;32m- Config will install: ${CONFIGS[*]}\e[0m"
eval $_cmd
for config in ${CONFIGS[*]}; do
echo -e "\nConfiguring $config..."
eval "$installcmd -c \"${META_DIR}/${CONFIG_DIR}/${config}${CONFIG_SUFFIX}\""
done