-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·135 lines (118 loc) · 3.01 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
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
#!/bin/bash
# ------------------------------------------------------------------------------
# Interactive installer & updater for Misc-Scripts.
#
# Usage: [sudo] ./install.sh
#
# Run as root/sudo, (un)installs & updates the scripts in /usr/local/bin and
# /usr/local/sbin, otherwise in the user's home directory ~/bin and ~/sbin.
#
# Author : Esa Jokinen (oh2fih)
# Home : https://github.com/oh2fih/Misc-Scripts
# ------------------------------------------------------------------------------
# Configuration.
WIDTH=80
# Checks and initialization.
if ! command -v whiptail &> /dev/null; then
printf "\n%s\n\n" "This interactive installer requires whiptail!" >&2
exit 1
fi
if [ "$EUID" -eq 0 ]; then
BIN=/usr/local/bin
SBIN=/usr/local/sbin
else
BIN="$HOME/bin"
SBIN="$HOME/sbin"
fi
GITROOT="$(git rev-parse --show-toplevel)" || exit 1
# Interactive menus.
MENULIST=()
MENUCOUNT=0
cd "$GITROOT/bin" || exit 1
for f in *; do
((MENUCOUNT++))
if test -f "$BIN/$f"; then
MENULIST+=("bin/$f" "" "ON")
else
MENULIST+=("bin/$f" "" "OFF")
fi
done
HEIGHT=$((MENUCOUNT + 9))
TOINSTALL=$(
whiptail --title "Misc-Script to install (1/2)" \
--checklist --separate-output \
"Choose the Misc-Scripts to be installed,\nbin => ${BIN}" \
"$HEIGHT" "$WIDTH" "$MENUCOUNT" \
"${MENULIST[@]}" 3>&1 1>&2 2>&3
)
exitstatus=$?
if [ "$exitstatus" -ne 0 ]; then
printf "Aborting...\n"
exit "$exitstatus"
fi
TOINSTALL+=$'\n'
MENULIST=()
MENUCOUNT=0
cd "$GITROOT/sbin" || exit 1
for f in *; do
((MENUCOUNT++))
if test -f "$SBIN/$f"; then
MENULIST+=("sbin/$f" "" "ON")
else
MENULIST+=("sbin/$f" "" "OFF")
fi
done
HEIGHT=$((MENUCOUNT + 9))
TOINSTALL+=$(
whiptail --title "Misc-Script to install (2/2)" \
--checklist --separate-output \
"Choose the Misc-Scripts to be installed,\nsbin => ${SBIN}" \
"$HEIGHT" "$WIDTH" "$MENUCOUNT" \
"${MENULIST[@]}" 3>&1 1>&2 2>&3
)
exitstatus=$?
if [ "$exitstatus" -ne 0 ]; then
printf "Aborting...\n"
exit "$exitstatus"
fi
# Install, update & uninstall.
cd "$GITROOT/bin" || exit 1
for f in *; do
if grep -q -x "bin/$f" <<< "$TOINSTALL"; then
if [[ ! -e "$BIN" ]]; then
printf "Creating directory %s...\n" "$BIN"
mkdir -p "$BIN"
fi
if test -f "$BIN/$f"; then
printf "Updating %s/%s...\n" "$BIN" "$f"
else
printf "Installing %s/%s...\n" "$BIN" "$f"
fi
cp "$GITROOT/bin/$f" "$BIN/$f"
else
if test -f "$BIN/$f"; then
printf "Removing %s/%s...\n" "$BIN" "$f"
rm "$BIN/$f"
fi
fi
done
cd "$GITROOT/sbin" || exit 1
for f in *; do
if grep -q -x "sbin/$f" <<< "$TOINSTALL"; then
if [[ ! -e "$SBIN" ]]; then
printf "Creating directory %s...\n" "$SBIN"
mkdir -p "$SBIN"
fi
if test -f "$SBIN/$f"; then
printf "Updating %s/%s...\n" "$SBIN" "$f"
else
printf "Installing %s/%s...\n" "$SBIN" "$f"
fi
cp "$GITROOT/sbin/$f" "$SBIN/$f"
else
if test -f "$SBIN/$f"; then
printf "Removing %s/%s...\n" "$SBIN" "$f"
rm "$SBIN/$f"
fi
fi
done