-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.sh
executable file
·62 lines (50 loc) · 1.59 KB
/
demo.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
#!/bin/bash
LOGFILE="$HOME/robot_setup.log"
# Function to log messages
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOGFILE"
}
# Get current IP address of the robot
current_ip=$(hostname -I | sed -r 's/\s+$//' | grep -oE '^[^[:space:]]+')
if [ -z "$current_ip" ]; then
log "Failed to get current IP address."
exit 1
else
log "Current IP address: $current_ip"
fi
upstart_status=$(ls /lib/systemd/system/ | grep rbl_upstart)
# Check if service exists
if [ -n "$upstart_status" ]; then
log "Found an existing upstart service, enabling it..."
systemctl enable --user rbl_upstart.service > /dev/null 2>&1 && systemctl start --user rbl_upstart.service
if [ $? -eq 0 ]; then
log "Upstart service enabled and started successfully, robot in demonstration mode."
else
log "Failed to start upstart service."
exit 1
fi
else
log "Did not find an upstart service, creating a new one..."
sudo cp -f services/rbl_upstart.service /etc/systemd/user/
if [ $? -ne 0 ]; then
log "Failed to copy service file."
exit 1
fi
sudo systemctl daemon-reload
sleep 2 # Adding a short delay
systemctl --user enable rbl_upstart.service
systemctl --user start rbl_upstart.service
if [ $? -eq 0 ]; then
log "Upstart service enabled and started successfully, robot in demonstration mode."
else
log "Failed to start upstart service."
exit 1
fi
fi
loginctl enable-linger $USER
if [ $? -ne 0 ]; then
log "Failed to enable linger for user."
exit 1
else
log "Linger enabled for user."
fi