-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
executable file
·106 lines (85 loc) · 2.52 KB
/
setup.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
#!/bin/bash
show_help() {
echo "Usage: $0 [options]"
echo ""
echo "Choose the system you would like to install on your device for thr: TxUUT, RxMeas, ControlPC"
echo "Options:"
echo " --systen <system_name> Specify the username."
echo " --help Display this help message."
exit 0
}
if [[ $# -eq 0 ]]; then
echo "No parameters provided."
show_help
exit 1
fi
SYSTEM=""
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--system) SYSTEM="$2"; shift ;; # Assign the value of the user parameter
--help) show_help;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
# Check if the user parameter is set
if [[ -z "$USER" ]]; then
echo "Missing required parameter: --system <system_name>"
show_help
exit 1
fi
if [[ "$SYSTEM" != "RxMeas" && "$SYSTEM" != "TxUUT" && "$SYSTEM" != "ControlPC" ]]; then
echo "Wrong system name"
exit 1
fi
UTILS_DIR="$(pwd)/utils"
PROTO_FILE="$UTILS_DIR/Messages.proto" # Example .proto file
echo "Compiling proto file"
PROTO_DIR=$(dirname "$PROTO_FILE")
PROTO_BASENAME=$(basename "$PROTO_FILE")
if [[ "$SYSTEM" != "RxMeas" ]]; then
protoc --proto_path="$PROTO_DIR" --python_out="$UTILS_DIR" "$PROTO_BASENAME"
fi
if [[ "$SYSTEM" == "ControlPC" ]]; then
exit 1
fi
if [ "$SYSTEM" = "TxUUT" ]; then
EXEC_START="/usr/bin/python3 $(pwd)/TxUUT/main.py" #
DESCRIPTION="TxUUT service"
else
protoc --proto_path="$PROTO_DIR" --cpp_out="$UTILS_DIR" "$PROTO_BASENAME"
BUILD_DIR="$(pwd)/RxMeas/build"
echo "Creating build directory..."
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" || exit
cmake .. # Assuming CMakeLists.txt is located in RxMeas/main/
make
cd ../..
EXEC_START="$(pwd)/RxMeas/build/main" #
DESCRIPTION="RxMeas service"
fi
# Create the systemd service file
SERVICE_FILE="/etc/systemd/system/${SYSTEM}.service"
echo "Creating systemd service file at ${SERVICE_FILE}..."
sudo bash -c "cat > ${SERVICE_FILE} <<EOL
[Unit]
Description=${DESCRIPTION}
[Service]
ExecStart=${EXEC_START}
Restart=always
User=$(whoami)
Group=$(whoami)
[Install]
WantedBy=multi-user.target
EOL"
# Reload systemd to recognize the new service
echo "Reloading systemd daemon..."
sudo systemctl daemon-reload
# Enable the service to start on boot
echo "Enabling ${SYSTEM} service..."
sudo systemctl enable ${SYSTEM}.service
# Start the service immediately (optional)
echo "Starting ${SYSTEM} service..."
sudo systemctl start ${SYSTEM}.service
echo "Service setup complete!"