-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
executable file
·64 lines (53 loc) · 1.14 KB
/
utils.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
#!/bin/bash
set -e
shopt -s dotglob
MAGENTA="\033[0;35m"
RED="\033[0;31m"
COLOR_OFF="\033[0m"
function emphasis {
echo -e "${MAGENTA}${1}${COLOR_OFF}"
}
function error {
>&2 echo -e "${RED}${1}${COLOR_OFF}"
}
function os_detect {
echo -n "OS: "
if [ -x "$(command -v sw_vers)" ]; then
emphasis "macOS $(sw_vers -productVersion)"
./"$1"
elif [ -f /etc/os-release ]; then
source /etc/os-release
emphasis "$PRETTY_NAME"
if [ "$ID" = "debian" ]; then
./"$2"
else
os_supported=false
fi
else
emphasis "?"
os_supported=false
fi
if [ "$os_supported" = false ]; then
error "Unsupported OS :("
fi
}
move_to_home() {
if [ "$PWD" == "$HOME/Developer/setup" ]; then
emphasis "Already moved to home!"
else
mkdir -p ~/Developer/setup
mv ./* ~/Developer/setup
emphasis "Moved to '$HOME/Developer/setup'."
fi
}
ask_details() {
sudo -k # Invalidate sudo timestamp to force password input
while ! sudo -n true 2> /dev/null ; do
read -s -p "Password: " sudo_password
echo
sudo --stdin --validate <<< "${sudo_password}" 2> /dev/null || echo -n ""
done
}
renew_sudo() {
sudo -S -v <<< "${sudo_password}" 2> /dev/null
}