Skip to content

Commit 7024d14

Browse files
committed
Complete rewrite and extension of lordfolken's transfer-xcsoar.sh.
- Provident background system buffer sync to help later syncs finish quicker - Use eth0 MAC ID in backup path - Simplify recursive copy operation by use of smart rsync features - More compatible to the new menu ovmenu-x from Max - Display rsync error codes to the user - Propagate rsync error codes to the invoking shell - Visibility of yearned-for final message improved - Message integrated that user should wait a moment - Show virtual progress bar. better user guidance - Bourne Shell compatibility restored - Avoid trouble when copying symlinks - Included into the backup the statuses of: - brightness of the display - rotation - touch screen calibration - language settings - dropbear settings - SSH, variod and sensord status - 3 backup/restore functions added: - Backup "Backup XCSoar and OV settings" - Restore "Restore XCSoar and OV settings" - Restore_XCSoar "Restore only XCSoar settings" This is on a branch to be proposed as a new PR in response to the PR Openvario#320 comments.
1 parent 613c274 commit 7024d14

File tree

3 files changed

+191
-33
lines changed

3 files changed

+191
-33
lines changed
Lines changed: 161 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,169 @@
11
#!/bin/sh
2+
#
3+
# transfer-xcsoar.sh
4+
# System backup transfer script to and from usbstick for Openvario and XCSoar
5+
#
6+
# Created by lordfolken 2022-02-08
7+
# Enhanced by 7lima & Blaubart 2022-06-19
8+
#
9+
# This backup and restore script stores all XCSoar settings and relevant
10+
# Openvario settings like:
11+
#
12+
# -brightness of the display
13+
# -rotation
14+
# -touch screen calibration
15+
# -language settings
16+
# -dropbear settings
17+
# -SSH, variod and sensord status
18+
#
19+
# backups are stored at USB stick at:
20+
# openvario/backup/<MAC address of eth0>/
21+
# So you can store backups from more than one OV on the same stick!
222

3-
# Transfer script for Up/Downloadng data to usbstick
23+
echo ' [==========] Starting'
24+
echo ' [#=========] Wait until "DONE !!" appears before you exit!'
425

5-
USB_PATH="/usb/usbstick/openvario/"
6-
XCSOAR_PATH="/home/root/.xcsoar"
26+
# Provident background system buffer sync to help later syncs finish quicker
27+
sync&
728

8-
case "$(basename "$0")" in
9-
'upload-xcsoar.sh')
10-
SRC_PATH="$USB_PATH/upload/xcsoar"
11-
DEST_PATH="$XCSOAR_PATH"
12-
;;
13-
*)
14-
>&2 echo 'call as upload-xcsoar.sh'
15-
exit 1
16-
esac
29+
# Path where the USB stick is mounted
30+
USB_PATH=/usb/usbstick
31+
32+
# XCSoar settings path
33+
XCSOAR_PATH=/home/root/.xcsoar
34+
35+
# XCSoar upload path
36+
XCSOAR_UPLOAD_PATH=openvario/upload/xcsoar
37+
38+
# Backup path within the USB stick
39+
BACKUP=openvario/backup
1740

18-
if [ ! -d "$SRC_PATH" ] || [ ! -d "$DEST_PATH" ]; then
19-
>&2 echo "Source $SRC_PATH or destination path $DEST_PATH does not exist"
20-
exit 1
21-
fi
22-
23-
if [ -z "$(find "$SRC_PATH" -type f | head -n 1 2>/dev/null)" ]; then
24-
echo 'No files found !!!'
25-
else
26-
# We use -c here due to cubieboards not having an rtc clock
27-
if rsync -r -c --progress "${SRC_PATH}/" "$DEST_PATH/"; then
28-
echo 'All files transfered successfully.'
29-
else
30-
>&2 echo 'An error has occured!'
31-
exit 1
41+
# MAC address of the Ethernet device eth0 to do a separate backup
42+
MAC=`ip li|grep -A 1 eth0|tail -n 1|cut -d ' ' -f 6|sed -e s/:/-/g`
43+
44+
# Restore Shell Function: calls rsync with unified options.
45+
# Copies all files and dirs from source recursively. Parameters:
46+
# $1 source
47+
# $2 target
48+
# $3 comment about type of items
49+
restore() {
50+
if
51+
# We use --checksum here due to cubieboards not having an rtc clock
52+
rsync --recursive --mkpath --checksum --quiet --progress "$1" "$2"
53+
test ${RSYNC_EXIT:=$?} -eq 0
54+
then
55+
echo " [####======] All $3 files have been restored."
56+
else
57+
>&2 echo " An rsync error $RSYNC_EXIT has occurred!"
3258
fi
33-
fi
59+
# Provident system buffer sync to help later syncs finish quicker
60+
sync&
61+
}
62+
63+
case `basename "$0"` in
64+
backup-system.sh)
65+
echo ' [##========] System check ...'
66+
67+
# Store SSH status
68+
if /bin/systemctl --quiet is-enabled dropbear.socket
69+
then echo enabled
70+
elif /bin/systemctl --quiet is-active dropbear.socket
71+
then echo temporary
72+
else echo disabled
73+
fi > /home/root/ssh-status
74+
75+
# Store variod and sensord status
76+
for DAEMON in variod sensord
77+
do
78+
if /bin/systemctl --quiet is-enabled $DAEMON
79+
then echo enabled
80+
else echo disabled
81+
fi > /home/root/$DAEMON-status
82+
done
83+
84+
# Copy brightness setting
85+
cat /sys/class/backlight/lcd/brightness > /home/root/brightness
86+
87+
echo ' [####======] Starting backup ...'
88+
# Copy all directories and files from list below to backup directory recursively.
89+
# We use --checksum here due to cubieboards not having an rtc clock
90+
if
91+
rsync --files-from - --archive --recursive --quiet \
92+
--relative --mkpath --checksum --safe-links \
93+
--progress \
94+
/ "$USB_PATH/$BACKUP/$MAC"/ <<-LISTE
95+
/etc/locale.conf
96+
/etc/udev/rules.d/libinput-ts.rules
97+
/etc/pointercal
98+
/etc/dropbear
99+
/home/root
100+
/opt/conf
101+
/var/lib/connman
102+
/boot/config.uEnv
103+
LISTE
104+
test ${RSYNC_EXIT:=$?} -eq 0
105+
then
106+
echo ' [######====] All files and settings have been backed up.'
107+
else
108+
>&2 echo " An rsync error $RSYNC_EXIT has occurred!"
109+
fi;;
110+
111+
upload-xcsoar.sh)
112+
echo ' [##========] Starting upload of XCSoar files ...'
113+
# Call Shell Function defined above
114+
restore "$USB_PATH/$XCSOAR_UPLOAD_PATH"/ "$XCSOAR_PATH"/ XCSoar;;
115+
116+
restore-xcsoar.sh)
117+
echo ' [##========] Starting restore of XCSoar ...'
118+
# Call Shell Function defined above
119+
restore "$USB_PATH/$BACKUP/$MAC/$XCSOAR_PATH"/ "$XCSOAR_PATH"/ XCSoar;;
120+
121+
restore-system.sh)
122+
echo ' [##========] Starting restore ...'
123+
124+
# Eliminate /etc/opkg backup in case it's present
125+
rm -rf "$USB_PATH/$BACKUP/$MAC"/etc/opkg/
126+
127+
# Call Shell Function defined above
128+
restore "$USB_PATH/$BACKUP/$MAC"/ / "Openvario and XCSoar"
129+
130+
# Restore SSH status
131+
case `cat /home/root/ssh-status` in
132+
enabled)
133+
/bin/systemctl enable --quiet --now dropbear.socket
134+
/bin/systemctl start --quiet --now dropbear.socket
135+
echo " [####======] SSH has been enabled permanently.";;
136+
temporary)
137+
/bin/systemctl disable --quiet --now dropbear.socket
138+
/bin/systemctl start --quiet --now dropbear.socket
139+
echo " [####======] SSH has been enabled temporarily.";;
140+
disabled)
141+
/bin/systemctl disable --quiet --now dropbear.socket
142+
echo " [####======] SSH has been disabled.";;
143+
esac
144+
145+
# Restore variod and sensord status
146+
for DAEMON in variod sensord
147+
do
148+
case `cat /home/root/$DAEMON-status` in
149+
enabled) /bin/systemctl enable --quiet --now $DAEMON
150+
/bin/systemctl start --quiet --now $DAEMON
151+
echo " [#####=====] $DAEMON has been enabled.";;
152+
disabled) /bin/systemctl disable --quiet --now $DAEMON
153+
echo " [#####=====] $DAEMON has been disabled.";;
154+
esac
155+
done
156+
157+
# Restore brightness setting
158+
cat /home/root/brightness > /sys/class/backlight/lcd/brightness
159+
echo " [######====] brightness setting has been restored.";;
160+
*)
161+
>&2 echo 'call as backup-system.sh, upload-xcsoar.sh, restore-xcsoar.sh or restore-system.sh'
162+
exit 1;;
163+
esac
34164

35-
# Sync the buffer to be sure data is on disk
165+
# Sync the system buffer to make sure all data is on disk
166+
echo ' [#######===] Please wait a moment, synchronization is not yet complete!'
36167
sync
37-
echo 'Done !!'
168+
echo ' [##########] DONE !! ---------------------------------------------------'
169+
exit $RSYNC_EXIT

meta-ov/recipes-apps/ovmenu-ng-skripts/ovmenu-ng-skripts_0.1.bb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ do_install() {
4646
${S}/ov-calibrate-ts.sh \
4747
${D}${bindir}/
4848
cd ${D}${bindir}
49+
ln -s -r transfer-xcsoar.sh restore-system.sh
50+
ln -s -r transfer-xcsoar.sh restore-xcsoar.sh
51+
ln -s -r transfer-xcsoar.sh backup-system.sh
4952
ln -s -r transfer-xcsoar.sh upload-xcsoar.sh
5053
}
5154

meta-ov/recipes-apps/ovmenu-ng/files/ovmenu-ng.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ function submenu_file() {
4444
--menu "You can use the UP/DOWN arrow keys" 15 50 4 \
4545
Download_IGC "Download XCSoar IGC files to USB" \
4646
Update_Maps "Update Maps" \
47-
Upload_XCSoar "Upload files from USB to XCSoar" \
47+
Upload_XCSoar "Update or upload XCSoar files" \
48+
Backup "Backup XCSoar and OV settings" \
49+
Restore "Restore XCSoar and OV settings" \
50+
Restore_XCSoar "Restore only XCSoar settings" \
4851
Back "Back to Main" 2>"${INPUT}"
4952

5053
menuitem=$(<"${INPUT}")
@@ -54,6 +57,9 @@ function submenu_file() {
5457
Download_IGC) download_igc_files;;
5558
Update_Maps) update_maps_files;;
5659
Upload_XCSoar) upload_xcsoar_files;;
60+
Backup) backup_files;;
61+
Restore) restore_files;;
62+
Restore_XCSoar) restore_xcsoar_files;;
5763
Back) ;;
5864
esac
5965
}
@@ -326,10 +332,27 @@ function download_igc_files() {
326332
/usr/bin/download-igc.sh
327333
}
328334

329-
# Copy /usb/usbstick/openvario/upload to /home/root/.xcsoar
335+
# Copy XCSoar and OpenVario settings to /usb/usbstick/openvario/backup/<MAC address of eth0>
336+
function backup_files() {
337+
/usr/bin/backup-system.sh > /tmp/tail.$$ &
338+
dialog --backtitle "OpenVario" --title "Result" --tailbox /tmp/tail.$$ 30 50
339+
}
340+
341+
# Copy /usb/usbstick/openvario/upload/xcsoar to /home/root/.xcsoar
330342
function upload_xcsoar_files() {
331-
echo "Uploading files ..." > /tmp/tail.$$
332-
/usr/bin/upload-xcsoar.sh >> /tmp/tail.$$ &
343+
/usr/bin/upload-xcsoar.sh > /tmp/tail.$$ &
344+
dialog --backtitle "OpenVario" --title "Result" --tailbox /tmp/tail.$$ 30 50
345+
}
346+
347+
# Copy XCSoar and OpenVario settings from /usb/usbstick/openvario/backup/<MAC address of eth0>
348+
function restore_files(){
349+
/usr/bin/restore-system.sh > /tmp/tail.$$ &
350+
dialog --backtitle "OpenVario" --title "Result" --tailbox /tmp/tail.$$ 30 50
351+
}
352+
353+
# Copy /usb/usbstick/openvario/backup/<MAC address of eth0>/home/root/.xcsoar to /home/root/.xcsoar
354+
function restore_xcsoar_files(){
355+
/usr/bin/restore-xcsoar.sh > /tmp/tail.$$ &
333356
dialog --backtitle "OpenVario" --title "Result" --tailbox /tmp/tail.$$ 30 50
334357
}
335358

0 commit comments

Comments
 (0)