forked from 0x90/kali-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.sh
154 lines (129 loc) · 3.16 KB
/
helper.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
print_status(){
echo -e "\x1B[01;34m[*]\x1B[0m $1"
}
print_good(){
echo -e "\x1B[01;32m[*]\x1B[0m $1"
}
print_error(){
echo -e "\x1B[01;31m[*]\x1B[0m $1"
}
print_notification(){
echo -e "\x1B[01;33m[*]\x1B[0m $1"
}
apt_upgrade(){
apt-get update && apt-get upgrade -y
}
apt_super_upgrade(){
apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
}
apt_cleanup(){
apt-get -y autoremove && apt-get -y clean
}
install_add_apt_repo(){
cp files/bin/add-apt-repository.sh /usr/sbin/add-apt-repository
chmod o+x /usr/sbin/add-apt-repository
}
apt_echo_sources(){
echo "$1" > "/etc/apt/sources.list.d/$2.list"
}
apt_add_source(){
cp -f "files/etc/$1.list" "/etc/apt/sources.list.d/$1.list" && apt-get update -y
}
apt_add_repo(){
if [ ! -f /usr/sbin/add-apt-repository ]; then
print_notification "File /usr/sbin/add-apt-repository not found! Installing..."
install_add_apt_repo
fi
add-apt-repository "$1" && apt-get update -y
}
apt_add_key(){
wget -q "$1" -O- | sudo apt-key add -
}
check_euid(){
# print_status "Checking for root privs."
if [[ $EUID -ne 0 ]]; then
print_error "This script must be ran with sudo or root privileges, or this isn't going to work."
exit 1
# else
# print_good "w00t w00t we are root!"
fi
}
command_exists() {
type "$1" &> /dev/null ;
}
check_success(){
if [ $? -eq 0 ]; then
print_good "Procedure successful."
else
print_error "Procedure unsucessful! Exiting..."
exit 1
fi
}
ask(){
if [ "$ASKMODE" = "WIZARD" ]; then
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
read -p "$1 [$prompt] " REPLY
if [ -z "$REPLY" ]; then
REPLY=${default}
fi
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
elif [ "$ASKMODE" = "YES" ]; then
return 1;
elif [ "$ASKMODE" = "NO" ]; then
return 0;
elif [ "$ASKMODE" = "AUTO" ]; then
case "$default" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
fi
}
pause(){
read -sn 1 -p "Press any key to continue..."
}
read_default(){
return read -e -p "$1" -i "$2"
}
write_with_backup(){
if [ -f $2 ]; then
print_notification "$2 found, backuping to $2.bak"
cp "$2" "$2.bak"
fi
cp -f "$1" "$2"
}
show_help(){
echo "Usage: cmd [-h] [-y] [-n] [-a] [-u]"
echo "-h - help message"
echo "-y - yes to all dialog questions"
echo "-n - no to all questions"
echo "-a - auto mode: choose default"
echo "-u - update scripts"
}
# Main
ASKMODE="WIZARD"
while getopts ":ahnuyv" opt; do
case ${opt} in
h|\?) show_help;;
a) ASKMODE="AUTO";;
n) ASKMODE="NO";;
y) ASKMODE="YES";;
u) git pull;;
v) verbose=1;;
esac
done
check_euid