-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·64 lines (55 loc) · 1.95 KB
/
setup.sh
File metadata and controls
executable file
·64 lines (55 loc) · 1.95 KB
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
# Menu tables and description
declare -a script_list=("iptablesConfiguration.sh" "iptablesRemove.sh" "iptablesList.sh")
declare -a script_descriptions=("Add drop script" "Delete drop chein script" " Show current iptables script")
# Scripts that stored in directory
script_dir="./scripts"
# Validate the scripts that stored in directory
if [ ! -d "$script_dir" ]; then
echo "The specified directory does not exist: $script_dir"
exit 1
fi
# Show menu
echo "Please select scrips to run:"
index=1
for script in "${script_list[@]}"; do
description="${script_descriptions[$((index-1))]}"
echo "$index) $script ($description)"
index=$((index + 1))
done
# Allow user to select menu
PS3="Select number: "
select selected in "${script_list[@]}"; do
if [ -z "$selected" ]; then
echo "Invlid select"
else
# Get the file pass that selected scripts
if [[ "$selected" == "view_iptables.sh" ]]; then
# Show currently settings of iptables
echo "Show current iptables..."
sudo iptables -L
break
fi
script_file="$script_dir/$selected"
# Check the script that existing or not
if [ ! -f "$script_file" ]; then
echo "The specified script does not found: $script_file"
break
fi
# Show description thier scripts
selected_index=$(echo "${script_list[@]}" | tr ' ' '\n' | grep -n "$selected" | cut -d ':' -f 1)
echo "Selected script: $selected"
echo "Description: ${script_descriptions[$((selected_index-1))]}"
echo "Do you want to run this script? (y/n)"
# Require to user
read confirm
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
# Run script
bash "$script_file"
echo "$selected script has been executed. "
else
echo "$selected was not executed. "
fi
break
fi
done