-
Notifications
You must be signed in to change notification settings - Fork 1
/
kaliup.sh
executable file
·103 lines (91 loc) · 2.21 KB
/
kaliup.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
#!/usr/bin/env bash
#
# Setup Kali Linux
#
#/ Usage:
#/ ./kaliup.sh [<script_name> <script_name2>...] [--help]
#/
#/ Support Kali 2020.1
set -e
set -u
usage() {
# Dislpay usage message
# $SCRIPT_DIR: global var, custom script directory
printf "%b\n" "$(grep '^#/' "$0" | cut -c4-)"
if [[ "$(find "$SCRIPT_DIR" -maxdepth 1 -name '*.sh' 2>/dev/null | wc -l)" -gt "0" ]]; then
local s f
printf "\n%s\n" 'Custom scripts:'
for s in "$SCRIPT_DIR"/*.sh; do
f=$(basename -- "$s")
f=${f%.*}
printf "%-20s" " $f"
printf "%-50s\n" "run $s"
done
printf "%-20s" " <script_name>"
printf "%-50s\n" "run $SCRIPT_DIR/<script_name>.sh"
fi
exit 0
}
set_var() {
# Declare global variables
CURRENT_DIR=$(dirname "$0")
convert_yaml_to_var "$CURRENT_DIR/globalvar.yaml"
}
print_info() {
# Display information
# $1: info message
printf "%b\n" "\033[32m[INFO]\033[0m $1" >&2
}
print_error() {
# Display error message
# $1: error message
printf "%b\n" "\033[31m[ERROR]\033[0m $1" >&2
}
run_sudo() {
# Run as root using sudo
echo "$KALI_PASSWORD" | sudo -S echo
}
convert_yaml_to_var() {
# Declare global variable from yaml file
# $1: input yaml file
while IFS= read -r line; do
eval "$line"
done < <(sed \
-e '/^\s*$/d' \
-e '/^#/d' \
-e 's/[[:space:]]*$//' \
-e '/:$/d' \
-e "s/:[^:\/\/]/='/g" \
-e "s/$/'/g" \
-e 's/ *=/=/g' "$1")
}
get_app_list() {
# Return an array from app list file
# $1: app list file
if [[ -f "$1" ]]; then
sed -E '/^#/d' "$1"
else
echo ""
fi
}
main() {
# main function
# $@: all arguments
# $SCRIPT_DIR: custom script directory
local opts
set_var
expr "$*" : ".*--help" > /dev/null && usage
[[ -z "${1:-}" ]] && usage
opts=("$@")
for i in "${opts[@]}"; do
if [[ -f "$SCRIPT_DIR/${i}.sh" ]]; then
print_info "Running ${i}.sh..."
source "$SCRIPT_DIR/${i}.sh"
else
print_error "${i}.sh is not found!"
fi
done
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi