-
Notifications
You must be signed in to change notification settings - Fork 30
improve backup and restore procedure #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
83936e9
ddf511a
e3764bf
33dbddf
082b770
783c803
92e7ca1
09b0114
76ac512
90e564a
4e8a82f
631f2cf
8ca99bc
dbc5ba2
72a56b3
24cc85e
9a30677
5878591
53a2c7c
8471ae1
29a3061
f48123e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/sh | ||
# | ||
# system-info.sh | ||
# System info script gives an overview which packages and which versions are instaled | ||
# | ||
# Created by Blaubart, 2022-02-08 | ||
# | ||
|
||
# collect info of system and more installed packages | ||
IMAGE_VERSION=$(cat /etc/os-release | grep VERSION_ID | cut -d '=' -f 2) | ||
KERNEL_VERSION=$(uname -r) | ||
XCSOAR_MAPS_VERSION=$(opkg list-installed xcsoar-maps* | cut -d '-' -f 4) | ||
XCSOAR_MENU=$(opkg list-installed xcsoar-menu* | cut -d '-' -f 3) | ||
IP_ETH0=$(ip route | grep eth0 | head -n 2 | cut -d ' ' -f 8) | ||
MAC=`ip li|grep -A 1 eth0|tail -n 1|cut -d ' ' -f 6` | ||
HOSTNAME=$(cat /etc/hostname) | ||
IP_WLAN=$(ip route | grep wlan0 | tail -n 2 | head -n 1 | cut -d ' ' -f 8) | ||
I2C_TOOLS=$(opkg list-installed i2c-tools | cut -d '-' -f 3) | ||
E2FSPROGS=$(opkg list-installed e2fsprogs | cut -d '-' -f 2) | ||
USB_MODESWITCH=$(opkg list-installed usb-modeswitch | cut -d '-' -f 3) | ||
|
||
# collect status of SSH, variod and sensord | ||
if /bin/systemctl --quiet is-enabled dropbear.socket | ||
then | ||
SSH_STATUS=enabled | ||
else | ||
SSH_STATUS=disabled | ||
fi | ||
|
||
if /bin/systemctl --quiet is-enabled variod | ||
then | ||
VARIOD_STATUS=enabled | ||
else | ||
VARIOD_STATUS=disabled | ||
fi | ||
|
||
if /bin/systemctl --quiet is-enabled sensord | ||
then | ||
SENSORD_STATUS=enabled | ||
else | ||
SENSORD_STATUS=disabled | ||
fi | ||
|
||
#print info of system and packages | ||
echo ' Image: '$IMAGE_VERSION | ||
echo ' Kernel: '$KERNEL_VERSION | ||
|
||
# collect info of installed packages, depending of testing or stable version is used | ||
if [ -n "$(opkg list-installed xcsoar-testing)" ] | ||
then | ||
XCSOAR_VERSION=$(opkg list-installed xcsoar-testing | cut -d ' - ' -f 3) | ||
echo ' XCSoar-testing: '$XCSOAR_VERSION | ||
else | ||
XCSOAR_VERSION=$(opkg list-installed xcsoar | cut -d '-' -f 2) | ||
echo ' XCSoar:'$XCSOAR_VERSION | ||
fi | ||
|
||
echo ' Maps:'$XCSOAR_MAPS_VERSION | ||
echo ' Menu:'$XCSOAR_MENU | ||
|
||
if [ -n "$(opkg list-installed sensord-testing)" ] | ||
then | ||
SENSORD_VERSION=$(opkg list-installed sensord-testing | cut -d ' - ' -f 3) | ||
echo ' sensord-testing: '$SENSORD_VERSION | ||
else | ||
SENSORD_VERSION=$(opkg list-installed sensord | cut -d '-' -f 2) | ||
echo ' sensord:'$SENSORD_VERSION | ||
fi | ||
|
||
if [ -n "$(opkg list-installed variod-testing)" ] | ||
then | ||
VARIOD_VERSION=$(opkg list-installed variod-testing | cut -d ' - ' -f 3) | ||
echo ' variod-testing: '$VARIOD_VERSION | ||
else | ||
VARIOD_VERSION=$(opkg list-installed variod | cut -d '-' -f 2) | ||
echo ' variod:'$VARIOD_VERSION | ||
fi | ||
|
||
echo ' IP eth0: '$IP_ETH0 | ||
echo ' MAC-address eth0: '$MAC | ||
echo ' Hostname: '$HOSTNAME | ||
echo ' IP wlan0: '$IP_WLAN | ||
echo -e '\n' | ||
echo ' supplementary packages that are not included\n in every image:' | ||
echo ' i2c-tools:'$I2C_TOOLS | ||
echo ' e2fsprogs:'$E2FSPROGS | ||
echo ' usb-modeswitch:'$USB_MODESWITCH | ||
echo -e '\n' | ||
echo ' Status of SSH, variod and sensord:' | ||
echo ' SSH is '$SSH_STATUS | ||
echo ' variod is '$VARIOD_STATUS | ||
echo ' sensord is '$SENSORD_STATUS |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,227 @@ | ||
#!/bin/sh | ||
# | ||
# transfer-xcsoar.sh | ||
# System backup transfer script to and from usbstick for Openvario and XCSoar | ||
# | ||
# Created by lordfolken 2022-02-08 | ||
# Enhanced by 7lima & Blaubart 2022-06-19 | ||
# | ||
# This backup and restore script stores all XCSoar settings and relevant | ||
# Openvario settings like: | ||
# | ||
# -brightness of the display | ||
# -rotation | ||
# -touch screen calibration | ||
# -language settings | ||
# -dropbear settings | ||
# -SSH, variod and sensord status | ||
# | ||
# backups are stored at USB stick at: | ||
# openvario/backup/<MAC address of eth0>/ | ||
# So you can store backups from more than one OV on the same stick! | ||
|
||
# Transfer script for Up/Downloadng data to usbstick | ||
|
||
USB_PATH="/usb/usbstick/openvario/" | ||
XCSOAR_PATH="/home/root/.xcsoar" | ||
|
||
case "$(basename "$0")" in | ||
'download-all.sh') | ||
SRC_PATH="$XCSOAR_PATH" | ||
DEST_PATH="$USB_PATH/download/xcsoar" | ||
;; | ||
'upload-xcsoar.sh') | ||
SRC_PATH="$USB_PATH/upload/xcsoar" | ||
DEST_PATH="$XCSOAR_PATH" | ||
;; | ||
'upload-all.sh') | ||
SRC_PATH="$USB_PATH/upload" | ||
DEST_PATH="$XCSOAR_PATH" | ||
;; | ||
*) | ||
>&2 echo 'call as download-all.sh, upload-xcsoar.sh or upload-all.sh' | ||
exit 1 | ||
esac | ||
echo ' [==========] Starting' | ||
echo ' [#=========] Wait until "DONE !!" appears before you exit!' | ||
|
||
# Provident background system buffer sync to help later syncs finish quicker | ||
sync& | ||
|
||
# Path where the USB stick is mounted | ||
USB_PATH=/usb/usbstick | ||
|
||
# XCSoar settings path | ||
export XCSOAR_PATH=/home/root/.xcsoar | ||
|
||
# XCSoar upload path | ||
XCSOAR_UPLOAD_PATH=openvario/upload/xcsoar | ||
|
||
# Backup path within the USB stick | ||
BACKUP=openvario/backup | ||
|
||
# MAC address of the Ethernet device eth0 to do a separate backup | ||
MAC=`ip li|grep -A 1 eth0|tail -n 1|cut -d ' ' -f 6|sed -e s/:/-/g` | ||
|
||
# Restore Shell Function: calls rsync with unified options. | ||
# Copies all files and dirs from source recursively. Parameters: | ||
# $1 source | ||
# $2 target | ||
# $3 comment about type of items | ||
restore() { | ||
if | ||
# We use --checksum here due to cubieboards not having an rtc clock | ||
rsync --recursive --mkpath --checksum --quiet --progress "$1" "$2" | ||
test ${RSYNC_EXIT:=$?} -eq 0 | ||
then | ||
echo " [####======] All $3 files have been restored." | ||
else | ||
>&2 echo " An rsync error $RSYNC_EXIT has occurred!" | ||
fi | ||
# Provident system buffer sync to help later syncs finish quicker | ||
sync& | ||
} | ||
|
||
case `basename "$0"` in | ||
backup-system.sh) | ||
echo ' [##========] System check ...' | ||
|
||
# Store SSH status | ||
if /bin/systemctl --quiet is-enabled dropbear.socket | ||
then echo enabled | ||
elif /bin/systemctl --quiet is-active dropbear.socket | ||
then echo temporary | ||
else echo disabled | ||
fi > /home/root/ssh-status | ||
Comment on lines
+68
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indenting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a different compact indentation style deliberately used here.
Comment on lines
+68
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indenting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a different compact indentation style deliberately used here. |
||
|
||
if [ ! -d "$SRC_PATH" ] || [ ! -d "$DEST_PATH" ]; then | ||
>&2 echo "Source $SRC_PATH or destination path $DEST_PATH does not exist" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$(find "$SRC_PATH" -type f | head -n 1 2>/dev/null)" ]; then | ||
echo 'No files found !!!' | ||
else | ||
# We use -c here due to cubieboards not having an rtc clock | ||
if rsync -r -c --progress "${SRC_PATH}/" "$DEST_PATH/"; then | ||
echo 'All files transfered successfully.' | ||
else | ||
>&2 echo 'An error has occured!' | ||
exit 1 | ||
# Store variod and sensord status | ||
for DAEMON in variod sensord | ||
do | ||
if /bin/systemctl --quiet is-enabled $DAEMON | ||
then echo enabled | ||
else echo disabled | ||
fi > /home/root/$DAEMON-status | ||
done | ||
|
||
# Store if profiles are protected or not | ||
if [[ 'opkg list-installed | grep "e2fsprogs -"' == *"e2fsprogs"* ]]; | ||
then | ||
PROFILE= find "$XCSOAR_PATH" -maxdepth 1 -type f -name '*.prf' -exec sh -c ' | ||
for PROFILE; | ||
do | ||
mkdir -p /home/root/profile-settings | ||
PROFILE_FILE=`basename "$PROFILE"` | ||
PROFILE_NAME=${PROFILE_FILE%.*} | ||
if lsattr "$PROFILE" | cut -b 5 | fgrep -q i; | ||
then echo protected | ||
else echo unprotected | ||
fi > /home/root/profile-settings/$PROFILE_NAME | ||
done | ||
' -- {} + | ||
fi | ||
fi | ||
|
||
# Sync the buffer to be sure data is on disk | ||
# Copy brightness setting | ||
cat /sys/class/backlight/lcd/brightness > /home/root/brightness | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we ever implement some dynamic brightness setting, this would write the current (adapted) brightness into the backup, instead of a configured value. Where is the configured value saved? |
||
echo ' [####======] Starting backup ...' | ||
# Copy all directories and files from list below to backup directory recursively. | ||
# We use --checksum here due to cubieboards not having an rtc clock | ||
if | ||
rsync --files-from - --archive --recursive --quiet \ | ||
--relative --mkpath --checksum --safe-links \ | ||
--progress \ | ||
/ "$USB_PATH/$BACKUP/$MAC"/ <<-LISTE | ||
/etc/locale.conf | ||
/etc/udev/rules.d/libinput-ts.rules | ||
/etc/pointercal | ||
/etc/dropbear | ||
/home/root | ||
/opt/conf | ||
/var/lib/connman | ||
/boot/config.uEnv | ||
LISTE | ||
test ${RSYNC_EXIT:=$?} -eq 0 | ||
then | ||
echo ' [######====] All files and settings have been backed up.' | ||
else | ||
>&2 echo " An rsync error $RSYNC_EXIT has occurred!" | ||
fi;; | ||
|
||
upload-xcsoar.sh) | ||
echo ' [##========] Starting upload of XCSoar files ...' | ||
# Call Shell Function defined above | ||
if | ||
# We use --checksum here due to cubieboards not having an rtc clock | ||
rsync --recursive --mkpath --checksum --quiet --progress "$USB_PATH/$XCSOAR_UPLOAD_PATH"/ "$XCSOAR_PATH" | ||
test ${RSYNC_EXIT:=$?} -eq 0 | ||
then | ||
echo " [####======] All XCSoar files have been uploaded." | ||
else | ||
>&2 echo " An rsync error $RSYNC_EXIT has occurred!" | ||
fi | ||
# Provident system buffer sync to help later syncs finish quicker | ||
sync&;; | ||
|
||
restore-xcsoar.sh) | ||
echo ' [##========] Starting restore of XCSoar ...' | ||
# Call Shell Function defined above | ||
restore "$USB_PATH/$BACKUP/$MAC/$XCSOAR_PATH"/ "$XCSOAR_PATH"/ XCSoar;; | ||
|
||
restore-system.sh) | ||
echo ' [##========] Starting restore ...' | ||
|
||
# Eliminate /etc/opkg backup in case it's present | ||
rm -rf "$USB_PATH/$BACKUP/$MAC"/etc/opkg/ | ||
|
||
# Call Shell Function defined above | ||
restore "$USB_PATH/$BACKUP/$MAC"/ / "Openvario and XCSoar" | ||
/bin/systemctl restart --quiet --now ts_uinput | ||
|
||
# Restore SSH status | ||
case `cat /home/root/ssh-status` in | ||
enabled) | ||
/bin/systemctl enable --quiet --now dropbear.socket | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enabling does not start the dropbear daemon. This needs a start in addtion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right! I'll add it. |
||
echo " [####======] SSH has been enabled permanently.";; | ||
temporary) | ||
/bin/systemctl disable --quiet --now dropbear.socket | ||
/bin/systemctl start --quiet --now dropbear.socket | ||
echo " [####======] SSH has been enabled temporarily.";; | ||
disabled) | ||
/bin/systemctl disable --quiet --now dropbear.socket | ||
echo " [####======] SSH has been disabled.";; | ||
esac | ||
|
||
# Restore variod and sensord status | ||
for DAEMON in variod sensord | ||
do | ||
case `cat /home/root/$DAEMON-status` in | ||
enabled) /bin/systemctl enable --quiet --now $DAEMON | ||
echo " [#####=====] $DAEMON has been enabled.";; | ||
disabled) /bin/systemctl disable --quiet --now $DAEMON | ||
echo " [#####=====] $DAEMON has been disabled.";; | ||
esac | ||
done | ||
|
||
# Restore protection for profiles if necessary | ||
if [[ 'opkg list-installed | grep "e2fsprogs -"' == *"e2fsprogs"* ]]; | ||
then | ||
PROFILE= find "$XCSOAR_PATH" -maxdepth 1 -type f -name '*.prf' -exec sh -c ' | ||
for PROFILE; | ||
do | ||
PROFILE_FILE=`basename "$PROFILE"` | ||
PROFILE_NAME=${PROFILE_FILE%.*} | ||
case `cat /home/root/profile-settings/"$PROFILE_NAME"` in | ||
protected) chattr +i "$XCSOAR_PATH"/"$PROFILE_NAME.prf" | ||
echo " [######====] $PROFILE_NAME.prf has been protected.";; | ||
unprotected) echo " [######====] $PROFILE_NAME.prf is still unprotected.";; | ||
esac | ||
done | ||
' -- {} + | ||
else | ||
PROFILE= find "$XCSOAR_PATH" -maxdepth 1 -type f -name '*.prf' -exec sh -c ' | ||
for PROFILE; | ||
do | ||
PROFILE_FILE=`basename "$PROFILE"` | ||
PROFILE_NAME=${PROFILE_FILE%.*} | ||
case `cat /home/root/profile-settings/"$PROFILE_NAME"` in | ||
protected) echo " You try to protect $PROFILE_NAME.prf, but chattr is not installed!";; | ||
esac | ||
done | ||
' -- {} + | ||
fi | ||
|
||
# Restore brightness setting | ||
cat /home/root/brightness > /sys/class/backlight/lcd/brightness | ||
echo " [#######===] brightness setting has been restored." | ||
|
||
# Restore rotation setting | ||
grep "rotation" /boot/config.uEnv | cut -d '=' -f 2 | tr -d '"' > /sys/class/graphics/fbcon/rotate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm horrified by this line. And I'm horrified by this whole PR which adds shitloads of fragile shell script code. |
||
echo " [########==] rotation setting has been restored.";; | ||
*) | ||
>&2 echo 'call as backup-system.sh, upload-xcsoar.sh, restore-xcsoar.sh or restore-system.sh' | ||
exit 1;; | ||
esac | ||
|
||
# Sync the system buffer to make sure all data is on disk | ||
echo ' [#########=] Please wait a moment, synchronization is not yet complete!' | ||
sync | ||
echo 'Done !!' | ||
echo ' [##########] DONE !! ---------------------------------------------------' | ||
exit $RSYNC_EXIT |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ SRC_URI = "\ | |
file://update-system.sh \ | ||
file://download-igc.sh \ | ||
file://transfer-xcsoar.sh \ | ||
file://system-info.sh \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has nothing to do with rearranging menu items, and probably this fails the build because this script doesn't exist (yet). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right! |
||
file://ov-calibrate-ts.sh \ | ||
" | ||
|
||
|
@@ -41,12 +42,14 @@ do_install() { | |
${S}/update-system.sh \ | ||
${S}/download-igc.sh \ | ||
${S}/transfer-xcsoar.sh \ | ||
${S}/system-info.sh \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
${S}/ov-calibrate-ts.sh \ | ||
${D}${bindir}/ | ||
cd ${D}${bindir} | ||
ln -s -r transfer-xcsoar.sh upload-all.sh | ||
ln -s -r transfer-xcsoar.sh restore-system.sh | ||
ln -s -r transfer-xcsoar.sh restore-xcsoar.sh | ||
ln -s -r transfer-xcsoar.sh backup-system.sh | ||
ln -s -r transfer-xcsoar.sh upload-xcsoar.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this script? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script is to upload files like XCSoar profile, Flarmnet database etc. to /home/root/.xcsoar. We still have to add this part to transfer-xcsoar.sh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point was: this part of the commit doesn't belong in this commit! |
||
ln -s -r transfer-xcsoar.sh download-all.sh | ||
} | ||
|
||
FILES:${PN} = " \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit does three things:
Doing 3 distinct things in 1 commit obscures the code changes, because one cannot see what was changed; the commitdiff is "remove 20 lines here, add 100 lines over there", but no diff possible.