Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (13)
This diff is collapsed.
......@@ -101,7 +101,8 @@ Commands:
* $KEEP_MAX_UPDATER updater snapshots
* $KEEP_MAX_ROLLBACK rollback backups snapshots
With --compare option also deletes snapshots that doesn't differ from
the previous one.
the next one (only the last snapshot from a group of identical ones
is retained).
delete <what>... Deletes corresponding snapshots.
Arguments can be either snapshot number or type specification.
......@@ -161,8 +162,13 @@ Commands:
server.
Multiple types can be divided by commas.
import path Import exported snapshot; path must point to .info file for the
snapshot.
import [-f] path Import exported snapshot; path must point to .info file for the
snapshot. Except when importing factory image with -f option, then it
has to be a tarball, but it can be an URL as well.
update-factory Updates factory image, if the devices is supported.
factory-version Display version of the image stored in factory snapshot.
help Display this help
......@@ -203,6 +209,9 @@ mount_root() {
}
mount_snp() {
if [ $# != 1 ]; then
die_helping "Wrong number of arguments"
fi
mkdir -p /mnt/snapshot-@$1
if [ -n "`ls -A "/mnt/snapshot-@$1"`" ]; then
die "ERROR: Something is already in '/mnt/snapshot-@$1'"
......@@ -282,6 +291,8 @@ generic_list() {
DESCRIPTION="$(filter_description "$DESCRIPTION")"
[ ! -d "$dir/@$snapshot" ] \
|| SIZE="$(btrfs qgroup show -f "$dir/@$snapshot" | sed -n 's|.*[[:blank:]]\([0-9.MGKi]*B\)[[:blank:]]*$|\1|p')"
[ ! -d "$dir/@$snapshot" -a -z "$SIZE" ] \
|| SIZE="$(btrfs qgroup show -f "$dir/@$snapshot" | sed -n 's|.*[[:blank:]]\([0-9.MGKi]*B\)[[:blank:]]*'"@$snapshot"'[[:blank:]]*$|\1|p')"
[ ! -f "$dir/$snapshot".tar.gz ] \
|| SIZE="$(du -sh "$dir/$snapshot".tar.gz | sed 's|[[:blank:]].*||')"
[ ! -f "$dir/$snapshot".tar.gz.pgp ] \
......@@ -305,6 +316,9 @@ generic_list() {
}
list() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
generic_list "$1" "$TMP_MNT_DIR"
}
......@@ -362,6 +376,9 @@ create() {
}
modify() {
if [ $# = 0 ]; then
die_helping "Wrong number of arguments"
fi
NUMBER="$1"
shift
if [ \! -d "$TMP_MNT_DIR"/@$NUMBER ]; then
......@@ -393,6 +410,9 @@ modify() {
}
delete() {
if [ $# != 1 ]; then
die_helping "Wrong number of arguments"
fi
NUMBER="$1"
if [ \! -d "$TMP_MNT_DIR"/@$NUMBER ]; then
echo "WARNING: Snapshot number $NUMBER does not exists!"
......@@ -411,6 +431,9 @@ delete() {
}
rollback() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
ROLL_TO="$1"
if [ -n "$ROLL_TO" ] && [ \! -d "$TMP_MNT_DIR"/@$ROLL_TO ]; then
die "Snapshot number $NUMBER does not exists!"
......@@ -473,6 +496,9 @@ my_status() {
}
cleanup() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
for info in "$TMP_MNT_DIR"/*.info; do
[ -f "$info" ] || continue
[ -d "$TMP_MNT_DIR/@`basename "$info" .info`" ] || rm "$info"
......@@ -546,6 +572,9 @@ cleanup() {
}
snp_diff() {
if [ $# -gt 3 ]; then
die_helping "Wrong number of arguments"
fi
if [ \! -d "$TMP_MNT_DIR"/@$1 ]; then
echo "Snapshot number $1 does not exists!"
ERR=3
......@@ -561,6 +590,9 @@ snp_diff() {
}
snp_status() {
if [ $# -gt 3 ]; then
die_helping "Wrong number of arguments"
fi
if [ \! -d "$TMP_MNT_DIR"/@$1 ]; then
echo "WARNING: Snapshot number $1 does not exists!"
return
......@@ -619,6 +651,9 @@ get_board() {
*M[Oo][Xx]*)
BOARD="mox"
;;
*Turris\ 1.*)
BOARD="turris1x"
;;
*)
BOARD="schnapps"
;;
......@@ -689,11 +724,15 @@ remote_mount() {
webdav_mount
;;
ssh://*)
FINAL_REMOTE_URL="$(echo "$REMOTE_URL" | sed -e 's|ssh://||' | sed -e 's|\:*\(\/.*\)|:\1|')"
FINAL_REMOTE_URL="$(echo "$REMOTE_URL" | sed -e 's|ssh://||' | sed -e 's|^\([^:/]*\)/|\1:/|')"
expr "$FINAL_REMOTE_URL" : '.*:' > /dev/null || FINAL_REMOTE_URL="$FINAL_REMOTE_URL:"
[ -n "`which sshfs`" ] || die "sshfs is not available"
sshfs "$FINAL_REMOTE_URL" "$TMP_RMT_MNT_DIR" || die "Can't access remote filesystem"
;;
local://*|file://*)
FINAL_REMOTE_URL="$(echo "$REMOTE_URL" | sed -e 's|^local://*|/|' -e 's|^file://*|/|')"
mount -o bind "$FINAL_REMOTE_URL" "$TMP_RMT_MNT_DIR" || die "Can't bind-mount local filesystem"
;;
smb:*|cifs:*)
local final_remote_url="$(echo "$REMOTE_URL" | sed -n 's|^[a-z:0-9.]*://|//|p')"
[ -n "$final_remote_url" ] || die "Invalid samba url $REMOTE_URL"
......@@ -721,23 +760,19 @@ remote_mount() {
remote_unmount() {
[ -n "$REMOTE_MOUNTED" ] || return
case "$REMOTE_URL" in
nextcloud://*)
umount -fl "$TMP_RMT_MNT_DIR" 2> /dev/null
;;
webdav://*)
umount -fl "$TMP_RMT_MNT_DIR" 2> /dev/null
;;
ssh://*)
fusermount -uz "$TMP_RMT_MNT_DIR" 2> /dev/null
;;
smb://*|cifs://*)
*)
umount -fl "$TMP_RMT_MNT_DIR" 2> /dev/null
;;
*) die "Invalid URL" ;;
esac
}
upload() {
if [ $# = 0 ]; then
die_helping "Wrong number of arguments"
fi
NUM=""
if expr "$1" : '[0-9]*$' > /dev/null; then
NUM="$1"
......@@ -759,6 +794,11 @@ sync_snps() {
if [ "x$1" = "x-t" ]; then
SYNC_TYPES="$2"
[ "$2" \!= all ] || SYNC_TYPES="$DEFAULT_SYNC_TYPES"
if [ "$3" ]; then
die_helping "Wrong number of arguments"
fi
elif [ "$1" ]; then
die_helping "Invalid argument"
fi
get_board
for info in "$TMP_MNT_DIR"/*.info; do
......@@ -783,6 +823,9 @@ sync_snps() {
}
remote_list() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
remote_mount
TBL_NUM=20
generic_list "$1" "$TMP_RMT_MNT_DIR"/"$REMOTE_PATH"
......@@ -815,6 +858,9 @@ download_tar() {
}
import_sn() {
if [ $# = 0 ] || [ $# -gt 2 ]; then
die_helping "Wrong number of arguments"
fi
if [ "x-f" = "x$1" ]; then
shift
case "$1" in
......@@ -863,6 +909,9 @@ import_sn() {
}
delete_type() {
if [ $# != 1 ]; then
die_helping "Wrong number of arguments"
fi
# .info files are named ${SNAPSHOT_NUMBER}.info
grep -l "TYPE=\"$1\"" "$TMP_MNT_DIR"/*.info | \
sed -n 's|.*/\([0-9]\+\)\.info$|\1|p' | \
......@@ -872,6 +921,9 @@ delete_type() {
}
savepoint() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
local time="$1"
[ -n "$time" ] || time=10
commit
......@@ -934,6 +986,25 @@ case $command in
upload)
upload "$@"
;;
update-factory)
get_board
if [ "$BOARD" != schnapps ]; then
old_hash="$(cat "$TMP_MNT_DIR/@factory/.image_hash" 2> /dev/null)"
new_hash="$(wget -O - "https://repo.turris.cz/hbs/medkit/$BOARD-medkit-latest.tar.gz.sha256")"
[ -n "$new_hash" ] || die "Can't get a hash of new factory image!"
if [ "$old_hash" = "$new_hash" ]; then
echo "No update available, latest image available is already your factory image."
else
import_sn -f "https://repo.turris.cz/hbs/medkit/$BOARD-medkit-latest.tar.gz"
echo "$new_hash" > "$TMP_MNT_DIR/@factory/.image_hash"
fi
else
die "Don't know what device I am, can't update my factory image"
fi
;;
factory-version)
cat "$TMP_MNT_DIR/@factory/etc/turris-version" 2> /dev/null || echo 0
;;
import)
import_sn "$@"
;;
......
......@@ -55,6 +55,18 @@ teardown_file() {
check_dataset_A "$ROOT_MOUNT"/@1
}
@test "Comparing snapshots works" {
echo "aaaa" > "$MAIN_MOUNT"/test
run $SUDO "${ROOT_DIR}"/schnapps.sh -d "$MAIN_MOUNT" create Testing snapshot
assert_success
echo "bbbb" > "$MAIN_MOUNT"/test
run $SUDO "${ROOT_DIR}"/schnapps.sh -d "$MAIN_MOUNT" cmp
assert_success
assert_output --partial "~ /test"
run $SUDO "${ROOT_DIR}"/schnapps.sh -d "$MAIN_MOUNT" diff
assert_output --regexp ".*test.*-aaaa.\+bbbb"
}
@test "Rollback works" {
create_dataset_A "$MAIN_MOUNT"
check_dataset_A "$MAIN_MOUNT"
......