-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·103 lines (89 loc) · 1.78 KB
/
bootstrap
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
#!/usr/bin/env bash
set -euo pipefail
command_exists() {
type -f "$1" >/dev/null 2>&1
}
ensure() {
COMMAND="$1"
shift
if [ "$#" -ge 1 ]
then
PACKAGES=("$@")
else
PACKAGES=("$COMMAND")
fi
if ! command_exists "$COMMAND"
then
"${INSTALLER[@]}" "${PACKAGES[@]}"
fi
}
sudo_() {
if [ "$EUID" -eq 0 ]
then
"$@"
else
sudo "$@"
fi
}
case "$OSTYPE" in
darwin*)
brew_env() {
if [ -d /opt/homebrew ]
then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
}
brew_env
if ! command_exists brew
then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew_env
fi
INSTALLER=(brew install)
# macOS has Python 3, but it's too old
if ! command_exists python3 || type python3 | grep -q /usr/bin/python3
then
"${INSTALLER[@]}" python@3
fi
;;
linux*)
DISTRO=$(grep '^ID=' /etc/os-release | cut -d = -f 2)
case $DISTRO in
debian|ubuntu)
INSTALLER=(sudo_ apt install --yes)
if [ -z "$(ls -A /var/lib/apt/lists)" ]
then
sudo_ apt update
fi
;;
fedora)
INSTALLER=(sudo_ dnf install --assumeyes)
;;
esac
ensure curl
ensure git
ensure sudo
case $DISTRO in
debian|ubuntu)
ensure python3 python3{,-venv}
;;
esac
;;
esac
PIPX=/usr/local/bin/pipx
if ! [ -f "$PIPX" ]
then
sudo_ touch -t 200001010000 "$PIPX"
fi
PIPX_TEMP=$(mktemp)
trap 'rm -f "$PIPX_TEMP"' EXIT
curl -sSL https://github.com/pypa/pipx/releases/latest/download/pipx.pyz -z "$PIPX" -o "$PIPX_TEMP"
if [ -s "$PIPX_TEMP" ]
then
sudo_ mv "$PIPX_TEMP" "$PIPX"
sudo_ chmod +rx "$PIPX"
fi
if [ "${1:-}" != "--development" ]
then
pipx upgrade --install mybox
fi