-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_scripts.sh
executable file
·46 lines (41 loc) · 1.7 KB
/
update_scripts.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
#!/usr/bin/env sh
# Copy new capture script from data folder and set as executable
SCRIPT_CAPTURE_NEW="/home/control/capture_local.py"
SCRIPT_CAPTURE_CURRENT="/home/control/skycam/scripts/capture_local.py"
SCRIPT_CAPTURE_LOG="/data/data/update_capture.log"
if [ -f "$SCRIPT_CAPTURE_NEW" ]; then
# Get timestamp to rename old script files
TIMESTAMP="$(date +%Y%m%dT%H%M%S)"
# Rename current script
mv "$SCRIPT_CAPTURE_CURRENT" "$SCRIPT_CAPTURE_CURRENT"."$TIMESTAMP"
# Rename new script and make it executable
mv "$SCRIPT_CAPTURE_NEW" "$SCRIPT_CAPTURE_CURRENT"
chmod +x "$SCRIPT_CAPTURE_CURRENT"
# Write last update to log
printf "%s:\n\%s\n" \
"Capture script updated on $TIMESTAMP" \
"$(diff "$SCRIPT_CAPTURE_CURRENT"."$TIMESTAMP" "$SCRIPT_CAPTURE_CURRENT")" \
>> "$SCRIPT_CAPTURE_LOG"
# Compress old script
gzip "$SCRIPT_CAPTURE_CURRENT"."$TIMESTAMP"
fi
SCRIPT_STARTUP_NEW="/home/control/skycam_startup.sh"
SCRIPT_STARTUP_CURRENT="/home/control/skycam/scripts/skycam_startup.sh"
SCRIPT_STARTUP_LOG="/data/data/update_startup.log"
if [ -f "$SCRIPT_STARTUP_NEW" ]; then
# Get timestamp to rename old script files
TIMESTAMP="$(date +%Y%m%dT%H%M%S)"
# Rename current script
mv "$SCRIPT_STARTUP_CURRENT" "$SCRIPT_STARTUP_CURRENT"."$TIMESTAMP"
# Rename new script and make it executable
mv "$SCRIPT_STARTUP_NEW" "$SCRIPT_STARTUP_CURRENT"
chmod +x "$SCRIPT_STARTUP_CURRENT"
# Write last update to log
printf "%s:\n\%s\n" \
"Capture script updated on $TIMESTAMP" \
"$(diff "$SCRIPT_STARTUP_CURRENT"."$TIMESTAMP" "$SCRIPT_STARTUP_CURRENT")" \
>> "$SCRIPT_STARTUP_LOG"
# Compress old script
gzip "$SCRIPT_STARTUP_CURRENT"."$TIMESTAMP"
fi
exit 0