Skip to content

Commit

Permalink
lime-sysupgrade: allow full path files on keep_on_upgrade and empty
Browse files Browse the repository at this point in the history
Signed-off-by: Pau Escrich <p4u@dabax.net>
  • Loading branch information
p4u committed Mar 28, 2017
1 parent ae2ac8e commit f6e68c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/lime-system/files/etc/config/lime-defaults
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
config lime system
option hostname 'LiMe-%M4%M5%M6'
option domain 'lan'
option keep_on_upgrade 'libremesh base-files-essential'
option keep_on_upgrade 'libremesh base-files-essential /etc/sysupgrade.conf'

config lime network
option primary_interface eth0
Expand Down
2 changes: 1 addition & 1 deletion packages/lime-system/files/etc/config/lime-example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
config lime system
option hostname 'LiMe-%M4%M5%M6' # Parametrizable with %Mn
option domain 'lan' # DNS domain for the L2 cloud it could be something like mycloud.mynetwork.tld, hosts that get their IP by DHCP will also get a fully qualified domain name like hostname.mycloud.mynetwork.tld
option keep_on_upgrade 'libremesh base-files-essential' # Files defining the list of files and directories to backup when upgrade. Relative to /lib/upgrade/keep.d
option keep_on_upgrade 'libremesh /etc/sysupgrade.conf' # Files defining the list of files and directories to backup when upgrade. Relative to /lib/upgrade/keep.d if no '/' defined.

### Network general option

Expand Down
20 changes: 12 additions & 8 deletions packages/lime-system/files/usr/bin/lime-sysupgrade
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/sh

FIRMWARE="$1"
shift
BACKUP_FILES="$@"
KEEP_LISTS="$(uci -q get lime.system.keep_on_upgrade || uci -q get lime-defaults.system.keep_on_upgrade)"

add_file() {
for l in `cat $1 | sed -e s/#.*$// -e /^$/d`; do
BACKUP_FILES="$BACKUP_FILES $l"
[ -e "$l" ] && BACKUP_FILES="$BACKUP_FILES $l"
done
}

Expand All @@ -14,23 +16,24 @@ usage() {
echo "Use system variable FORCE=1 for not being asked for confirmation"
echo ""
echo "In addition to the user specified backup files, the content of the following lists will also be included:"
for f in `uci get lime-defaults.system.keep_on_upgrade`; do
echo " -> /lib/upgrade/keep.d/$f"
for f in $KEEP_LISTS; do
echo $f | grep -q '/' && echo " -> $f" || echo " -> /lib/upgrade/keep.d/$f"
done
exit 0
}

[ ! -f "$FIRMWARE" ] && usage

for f in `uci get lime-defaults.system.keep_on_upgrade`; do
file="/lib/upgrade/keep.d/$f"
for f in $KEEP_LISTS; do
echo "$f" | grep -q '/' && file="$f" || file="/lib/upgrade/keep.d/$f"
[ -f "$file" ] && add_file $file || echo "Warning: Cannot read $file file"
done

tar czf /tmp/upgrade.tar.gz $BACKUP_FILES 2>/dev/null || {
[ -n "$BACKUP_FILES" ] && ( tar czf /tmp/upgrade.tar.gz $BACKUP_FILES 2>/dev/null || {
echo "Error: Cannot create tar.gz backup file"
echo "Command: tar czf /tmp/upgrade.tar.gz $BACKUP_FILES"
exit 1
}
})
echo "Upgrading the system..."
echo ""
echo "Files to be saved"
Expand All @@ -44,4 +47,5 @@ echo "Ready to perform the upgrade. Press [ENTER] to continue or CTRL+C to cance
[ "$FORCE" == "1" ] || read
echo ""

sysupgrade -f /tmp/upgrade.tar.gz $FIRMWARE &
[ -n "$BACKUP_FILES" ] && OPTIONS="-f /tmp/upgrade.tar.gz" || OPTIONS="-n"
sysupgrade $OPTIONS $FIRMWARE &

0 comments on commit f6e68c1

Please sign in to comment.