-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·71 lines (58 loc) · 1.84 KB
/
setup.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
#!/usr/bin/env sh
set -e
install_homebrew() {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
setup_project_directory() {
# Create the Projects directory if it doesn't exist
mkdir -p ~/Projects
pushd ~/Projects
# Clone the git repo if it doesn't exist
folder="dotfiles"
url="https://github.com/funkymonkeymonk/dotfiles.git"
if ! git clone "${url}" "${folder}" 2>/dev/null && [ -d "${folder}" ] ; then
echo "No need to clone: ${folder} exists"
fi
popd
}
build_environment_list() {
# TODO: Add an all option
options=(`ls Brewfile.* | grep -v site-specific | grep -v *.json`)
touch Brewfile.site-specific
menu() {
echo "Avaliable options:"
for i in ${!options[@]}; do
printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
if [[ "$msg" ]]; then echo "$msg"; fi
}
prompt="Check an option (again to uncheck, ENTER when done): "
while menu && read -rp "$prompt" num && [[ "$num" ]]; do
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#options[@]} )) ||
{ msg="Invalid option: $num"; continue; }
((num--)); msg="${options[num]} was ${choices[num]:+un}checked"
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
printf "You selected"; msg=" nothing"
echo "Brewfile" >> temp
echo "Brewfile.site-specific" >> temp
for i in ${!options[@]}; do
[[ "${choices[i]}" ]] && { printf " %s" "${options[i]}"; msg=""; }
# Write environment to temp file
[[ "${choices[i]}" ]] && { echo "${options[i]}" >> temp ;}
done
echo "$msg"
# Move temp file to env file
## TODO prompt and diff
mv temp env
}
run_install() {
echo "Starting install now"
make run
}
install_homebrew
setup_project_directory
pushd ~/Projects/dotfiles
build_environment_list
run_install