1
1
#! /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!
2
22
3
- # Transfer script for Up/Downloadng data to usbstick
23
+ echo ' [==========] Starting'
24
+ echo ' [#=========] Wait until "DONE !!" appears before you exit!'
4
25
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 &
7
28
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
17
40
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!"
32
58
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
34
164
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!'
36
167
sync
37
- echo ' Done !!'
168
+ echo ' [##########] DONE !! ---------------------------------------------------'
169
+ exit $RSYNC_EXIT
0 commit comments