-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·94 lines (81 loc) · 1.96 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
#!/bin/bash
set -euo pipefail
INSTALLERS_PATH=".installers"
STOWSH_PATH="$INSTALLERS_PATH/stowsh"
ask() {
# Based on: https://gist.github.com/davejamesmiller/1965569
local reply
while true; do
echo -n "$1 [y/n] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
install_package() {
script="$INSTALLERS_PATH/$1/install.sh"
if [ -f "$script" ]; then
if ask "Run installer for $1?"; then
source $script
fi
fi
}
link_package() {
if ask "Link $1?"; then
echo "Linking $1 ..."
"$STOWSH_PATH" -v -s "$1" -t "$HOME"
fi
}
set_os_name() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if ! [ -f /etc/os-release ]; then
echo "Cannot determine Linux distro: /etc/os-release doesn't exist"
exit 1
fi
source /etc/os-release
export OSNAME=$NAME
elif [[ "$OSTYPE" == "darwin"* ]]; then
export OSNAME="MacOS"
else
echo "Unsupported OS: $OSTYPE"
exit 1
fi
}
set_install_cmd() {
case "$OSNAME" in
*openSUSE*)
export INSTALL_CMD="sudo zypper in -y"
;;
*Ubuntu*)
export INSTALL_CMD="sudo apt install -y"
;;
*MacOS*)
export INSTALL_CMD="brew install"
;;
*)
echo "Unrecognized OS: $OSNAME"
exit 1
;;
esac
}
main() {
set_os_name
set_install_cmd
# If any arguments were passed in, use them as the list of packages to install
if [ $# -eq 0 ]; then
# Get root level dirs that don't start with a dot
pkgs="$(find . -maxdepth 1 ! -name '.*' -type d | sed "s|./||")"
else
pkgs="$@"
fi
# Install packages
for pkg in $pkgs; do
install_package $pkg
link_package $pkg
done
}
main "$@"