Skip to content
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

improve backup and restore procedure #320

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
83936e9
Squashed commit for Openvario merge request "improve backup and resto…
Jun 18, 2022
ddf511a
rearranging the menu items
Blaubart Jul 12, 2022
e3764bf
improve progress bar
Blaubart Jul 12, 2022
33dbddf
Moved system info functionality into new script system-info.sh. Exten…
7lima Jul 16, 2022
082b770
Update_Maps menu item moved from submenu_system to submenu_file
7lima Jul 17, 2022
783c803
Renaming, addition and reordering of backup/restore functions.
7lima Jul 17, 2022
92e7ca1
Complete rewrite and extension of lordfolken's transfer-xcsoar.sh.
7lima Jul 17, 2022
09b0114
Merge branch 'pull_request_315-branch' into pull_request_317-branch
7lima Jul 17, 2022
76ac512
Manually reverted my .gitignore customisations from former times.
7lima Jul 17, 2022
90e564a
Fixed newly introduced problems in menu code.
7lima Jul 17, 2022
4e8a82f
Update transfer-xcsoar.sh
Blaubart Aug 13, 2022
631f2cf
Update transfer-xcsoar.sh
Blaubart Aug 14, 2022
8ca99bc
Update transfer-xcsoar.sh
Blaubart Aug 15, 2022
dbc5ba2
Update transfer-xcsoar.sh
Blaubart Aug 15, 2022
72a56b3
implement automatic rotation after backup
Blaubart Mar 9, 2023
24cc85e
Update transfer-xcsoar.sh
Blaubart Mar 30, 2023
9a30677
bug fix - check if e2fsprogs is installed
Blaubart Mar 31, 2023
5878591
Bug fix - IP of eth0 and wlan0 was not found
Blaubart Apr 10, 2023
53a2c7c
add a new line at the end of the file
Blaubart Apr 10, 2023
8471ae1
removing double quote from the rotation value
Blaubart Apr 10, 2023
29a3061
Update openvario-image-testing.bb
Blaubart Apr 10, 2023
f48123e
restart tslib after restore
Blaubart Apr 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions meta-ov/recipes-apps/ovmenu-ng-skripts/files/system-info.sh
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 1 | 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 | 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

Comment on lines +22 to +29
Copy link
Collaborator

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:

  • move code to a new script (why?)
  • reformat the code
  • add new features

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.

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
255 changes: 216 additions & 39 deletions meta-ov/recipes-apps/ovmenu-ng-skripts/files/transfer-xcsoar.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,222 @@
#!/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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indenting

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a different compact indentation style deliberately used here.
Futhermore the echo commands' output is redirected by a single if ... fi output redirection.
I welcome any counterproposal to make it even clearer.

Comment on lines +68 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indenting

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a different compact indentation style deliberately used here.
Futhermore the echo commands' output is redirected by a single if ... fi output redirection.
I welcome any counterproposal to make it even clearer.


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" > /dev/null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not so portable. Please do a stat command to the executable.

Copy link

@7lima 7lima Apr 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Querying the version of the daemons by a "opkg list-installed" query is not as portable as desired, yes.
But this is an inherited flaw from earlier system-info versions.
It should be improved separately from this pull request.

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

Copy link
Contributor

Choose a reason for hiding this comment

The 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"

# Restore SSH status
case `cat /home/root/ssh-status` in
enabled)
/bin/systemctl enable --quiet --now dropbear.socket
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The 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" > /dev/null;
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.";;
*)
>&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
Expand Up @@ -23,6 +23,7 @@ SRC_URI = "\
file://update-system.sh \
file://download-igc.sh \
file://transfer-xcsoar.sh \
file://system-info.sh \
Copy link
Collaborator

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right!

file://ov-calibrate-ts.sh \
"

Expand All @@ -41,12 +42,14 @@ do_install() {
${S}/update-system.sh \
${S}/download-igc.sh \
${S}/transfer-xcsoar.sh \
${S}/system-info.sh \
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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} = " \
Expand Down
Loading