-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver
More file actions
85 lines (76 loc) · 1.98 KB
/
server
File metadata and controls
85 lines (76 loc) · 1.98 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
function show_help() {
echo "Usage: [server] [Flag]"
echo " -start Start HTTP server"
echo " -stop Stop running server"
echo " -uninstall Uninstall the server tool"
echo " --help Show help message"
}
function start_server() {
echo "Starting the Python HTTP server..."
python3 -m http.server 80 &
echo -n "SIM 1 IP: "
ip1=$(ip addr show dev rmnet_data1 | grep -oP 'inet \K[\d.]+')
if [ -n "$ip1" ]; then
echo "$ip1"
else
echo "not found"
fi
echo -n "SIM 2 IP: "
ip2=$(ip addr show dev rmnet_data2 | grep -oP 'inet \K[\d.]+')
if [ -n "$ip2" ]; then
echo "$ip2"
else
echo "not found"
fi
for interface in wlan1 wlan0; do
ip_address=$(ip -4 addr show dev $interface | grep -Po 'inet \K[\d.]+')
if [ -n "$ip_address" ]; then
echo "$interface $ip_address"
else
echo "$interface: No IP address found"
fi
done
}
function stop_server() {
echo "Stopping the server..."
if ps aux | grep -q 'python3 -m http.server 80'; then
pkill -f 'python3 -m http.server 80'
echo "Server stopped successfully."
else
echo "Server is not running."
fi
}
function uninstall_tool() {
read -p "Are you sure you want to uninstall this tool from your system? (Y/N): " choice
case "$choice" in
[Yy]* )
sudo rm -f /usr/local/bin/server
echo "Tool successfully uninstalled."
;;
[Nn]* )
echo "Uninstallation aborted."
;;
* )
echo "Invalid choice. Please enter Y or N."
;;
esac
}
# Main script logic
case "$1" in
"-start")
start_server
;;
"-stop")
stop_server
;;
"-uninstall")
uninstall_tool
;;
"--help")
show_help
;;
*)
echo "Invalid option. Use 'server --help' for usage instructions."
;;
esac