-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteo_adsb.sh
executable file
·116 lines (103 loc) · 3.21 KB
/
meteo_adsb.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
#!/bin/bash
CONFIG_FILE="config.json"
DEST_DIR="json_files"
DEMO_MODE=false
# Function to display help message
show_help() {
echo "Usage: $0 [-d]"
echo ""
echo "Options:"
echo " -d Run in demo mode. JSON files will not be copied."
echo ""
echo "Description:"
echo " This script sets up the Meteo-ADSB environment. It can be run in demo mode"
echo " where JSON files are not copied, or in normal mode where JSON files are"
echo " copied from a specified source directory."
}
# Function to read the configuration file
read_config() {
if [ -f "$CONFIG_FILE" ]; then
cat "$CONFIG_FILE"
else
echo "{}"
fi
}
# Function to save the configuration file
save_config() {
echo "$1" > "$CONFIG_FILE"
}
# Function to prompt for local or remote setup
prompt_local_or_remote() {
config=$(read_config)
local_machine=$(echo "$config" | jq -r '.local_machine')
if [ "$local_machine" == "null" ]; then
read -p "Is this a local machine setup? (y/n): " local_machine
config=$(echo "$config" | jq --arg local_machine "$local_machine" '.local_machine = $local_machine')
fi
save_config "$config"
}
# Function to prompt for remote details if needed
prompt_remote_details() {
config=$(read_config)
local_machine=$(echo "$config" | jq -r '.local_machine')
if [ "$local_machine" == "n" ]; then
read -p "Enter the remote IP address: " remote_ip
read -p "Enter the remote username: " remote_user
config=$(echo "$config" | jq --arg remote_ip "$remote_ip" --arg remote_user "$remote_user" '.remote_ip = $remote_ip | .remote_user = $remote_user')
save_config "$config"
fi
}
# Function to copy JSON files from source to destination
copy_files() {
config=$(read_config)
local_machine=$(echo "$config" | jq -r '.local_machine')
src_dir=$(echo "$config" | jq -r '.src_dir')
if [ "$local_machine" == "n" ]; then
remote_ip=$(echo "$config" | jq -r '.remote_ip')
remote_user=$(echo "$config" | jq -r '.remote_user')
scp "$remote_user@$remote_ip:$src_dir/*.json" "$DEST_DIR"
echo "Copied .json files from $src_dir on $remote_ip to $DEST_DIR"
else
cp "$src_dir"/*.json "$DEST_DIR"
echo "Copied .json files from $src_dir to $DEST_DIR"
fi
}
# Function to start the server
start_server() {
cd "$(dirname "$0")" || exit
local_ip=$(hostname -I | awk '{print $1}')
echo "Starting server at http://$local_ip:8000"
python3 -m http.server 8000 --directory . --bind 127.0.0.1 > /dev/null 2>&1 &
}
# Main script execution
main() {
mkdir -p "$DEST_DIR"
echo "Created destination directory: $DEST_DIR"
prompt_local_or_remote
prompt_remote_details
while getopts "dh" opt; do
case $opt in
d)
DEMO_MODE=true
;;
h)
show_help
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
show_help
exit 1
;;
esac
done
if [ "$DEMO_MODE" = true ]; then
echo "Running in demo mode. JSON files will not be copied."
else
echo "Copying JSON files..."
copy_files
fi
echo "Starting the server..."
start_server
}
main "$@"