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: ...@@ -101,7 +101,8 @@ Commands:
* $KEEP_MAX_UPDATER updater snapshots * $KEEP_MAX_UPDATER updater snapshots
* $KEEP_MAX_ROLLBACK rollback backups snapshots * $KEEP_MAX_ROLLBACK rollback backups snapshots
With --compare option also deletes snapshots that doesn't differ from 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. delete <what>... Deletes corresponding snapshots.
Arguments can be either snapshot number or type specification. Arguments can be either snapshot number or type specification.
...@@ -161,8 +162,13 @@ Commands: ...@@ -161,8 +162,13 @@ Commands:
server. server.
Multiple types can be divided by commas. Multiple types can be divided by commas.
import path Import exported snapshot; path must point to .info file for the import [-f] path Import exported snapshot; path must point to .info file for the
snapshot. 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 help Display this help
...@@ -203,6 +209,9 @@ mount_root() { ...@@ -203,6 +209,9 @@ mount_root() {
} }
mount_snp() { mount_snp() {
if [ $# != 1 ]; then
die_helping "Wrong number of arguments"
fi
mkdir -p /mnt/snapshot-@$1 mkdir -p /mnt/snapshot-@$1
if [ -n "`ls -A "/mnt/snapshot-@$1"`" ]; then if [ -n "`ls -A "/mnt/snapshot-@$1"`" ]; then
die "ERROR: Something is already in '/mnt/snapshot-@$1'" die "ERROR: Something is already in '/mnt/snapshot-@$1'"
...@@ -282,6 +291,8 @@ generic_list() { ...@@ -282,6 +291,8 @@ generic_list() {
DESCRIPTION="$(filter_description "$DESCRIPTION")" DESCRIPTION="$(filter_description "$DESCRIPTION")"
[ ! -d "$dir/@$snapshot" ] \ [ ! -d "$dir/@$snapshot" ] \
|| SIZE="$(btrfs qgroup show -f "$dir/@$snapshot" | sed -n 's|.*[[:blank:]]\([0-9.MGKi]*B\)[[:blank:]]*$|\1|p')" || 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 ] \ [ ! -f "$dir/$snapshot".tar.gz ] \
|| SIZE="$(du -sh "$dir/$snapshot".tar.gz | sed 's|[[:blank:]].*||')" || SIZE="$(du -sh "$dir/$snapshot".tar.gz | sed 's|[[:blank:]].*||')"
[ ! -f "$dir/$snapshot".tar.gz.pgp ] \ [ ! -f "$dir/$snapshot".tar.gz.pgp ] \
...@@ -305,6 +316,9 @@ generic_list() { ...@@ -305,6 +316,9 @@ generic_list() {
} }
list() { list() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
generic_list "$1" "$TMP_MNT_DIR" generic_list "$1" "$TMP_MNT_DIR"
} }
...@@ -362,6 +376,9 @@ create() { ...@@ -362,6 +376,9 @@ create() {
} }
modify() { modify() {
if [ $# = 0 ]; then
die_helping "Wrong number of arguments"
fi
NUMBER="$1" NUMBER="$1"
shift shift
if [ \! -d "$TMP_MNT_DIR"/@$NUMBER ]; then if [ \! -d "$TMP_MNT_DIR"/@$NUMBER ]; then
...@@ -393,6 +410,9 @@ modify() { ...@@ -393,6 +410,9 @@ modify() {
} }
delete() { delete() {
if [ $# != 1 ]; then
die_helping "Wrong number of arguments"
fi
NUMBER="$1" NUMBER="$1"
if [ \! -d "$TMP_MNT_DIR"/@$NUMBER ]; then if [ \! -d "$TMP_MNT_DIR"/@$NUMBER ]; then
echo "WARNING: Snapshot number $NUMBER does not exists!" echo "WARNING: Snapshot number $NUMBER does not exists!"
...@@ -411,6 +431,9 @@ delete() { ...@@ -411,6 +431,9 @@ delete() {
} }
rollback() { rollback() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
ROLL_TO="$1" ROLL_TO="$1"
if [ -n "$ROLL_TO" ] && [ \! -d "$TMP_MNT_DIR"/@$ROLL_TO ]; then if [ -n "$ROLL_TO" ] && [ \! -d "$TMP_MNT_DIR"/@$ROLL_TO ]; then
die "Snapshot number $NUMBER does not exists!" die "Snapshot number $NUMBER does not exists!"
...@@ -473,6 +496,9 @@ my_status() { ...@@ -473,6 +496,9 @@ my_status() {
} }
cleanup() { cleanup() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
for info in "$TMP_MNT_DIR"/*.info; do for info in "$TMP_MNT_DIR"/*.info; do
[ -f "$info" ] || continue [ -f "$info" ] || continue
[ -d "$TMP_MNT_DIR/@`basename "$info" .info`" ] || rm "$info" [ -d "$TMP_MNT_DIR/@`basename "$info" .info`" ] || rm "$info"
...@@ -546,6 +572,9 @@ cleanup() { ...@@ -546,6 +572,9 @@ cleanup() {
} }
snp_diff() { snp_diff() {
if [ $# -gt 3 ]; then
die_helping "Wrong number of arguments"
fi
if [ \! -d "$TMP_MNT_DIR"/@$1 ]; then if [ \! -d "$TMP_MNT_DIR"/@$1 ]; then
echo "Snapshot number $1 does not exists!" echo "Snapshot number $1 does not exists!"
ERR=3 ERR=3
...@@ -561,6 +590,9 @@ snp_diff() { ...@@ -561,6 +590,9 @@ snp_diff() {
} }
snp_status() { snp_status() {
if [ $# -gt 3 ]; then
die_helping "Wrong number of arguments"
fi
if [ \! -d "$TMP_MNT_DIR"/@$1 ]; then if [ \! -d "$TMP_MNT_DIR"/@$1 ]; then
echo "WARNING: Snapshot number $1 does not exists!" echo "WARNING: Snapshot number $1 does not exists!"
return return
...@@ -619,6 +651,9 @@ get_board() { ...@@ -619,6 +651,9 @@ get_board() {
*M[Oo][Xx]*) *M[Oo][Xx]*)
BOARD="mox" BOARD="mox"
;; ;;
*Turris\ 1.*)
BOARD="turris1x"
;;
*) *)
BOARD="schnapps" BOARD="schnapps"
;; ;;
...@@ -689,11 +724,15 @@ remote_mount() { ...@@ -689,11 +724,15 @@ remote_mount() {
webdav_mount webdav_mount
;; ;;
ssh://*) 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:" expr "$FINAL_REMOTE_URL" : '.*:' > /dev/null || FINAL_REMOTE_URL="$FINAL_REMOTE_URL:"
[ -n "`which sshfs`" ] || die "sshfs is not available" [ -n "`which sshfs`" ] || die "sshfs is not available"
sshfs "$FINAL_REMOTE_URL" "$TMP_RMT_MNT_DIR" || die "Can't access remote filesystem" 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:*) smb:*|cifs:*)
local final_remote_url="$(echo "$REMOTE_URL" | sed -n 's|^[a-z:0-9.]*://|//|p')" 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" [ -n "$final_remote_url" ] || die "Invalid samba url $REMOTE_URL"
...@@ -721,23 +760,19 @@ remote_mount() { ...@@ -721,23 +760,19 @@ remote_mount() {
remote_unmount() { remote_unmount() {
[ -n "$REMOTE_MOUNTED" ] || return [ -n "$REMOTE_MOUNTED" ] || return
case "$REMOTE_URL" in 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://*) ssh://*)
fusermount -uz "$TMP_RMT_MNT_DIR" 2> /dev/null fusermount -uz "$TMP_RMT_MNT_DIR" 2> /dev/null
;; ;;
smb://*|cifs://*) *)
umount -fl "$TMP_RMT_MNT_DIR" 2> /dev/null umount -fl "$TMP_RMT_MNT_DIR" 2> /dev/null
;; ;;
*) die "Invalid URL" ;;
esac esac
} }
upload() { upload() {
if [ $# = 0 ]; then
die_helping "Wrong number of arguments"
fi
NUM="" NUM=""
if expr "$1" : '[0-9]*$' > /dev/null; then if expr "$1" : '[0-9]*$' > /dev/null; then
NUM="$1" NUM="$1"
...@@ -759,6 +794,11 @@ sync_snps() { ...@@ -759,6 +794,11 @@ sync_snps() {
if [ "x$1" = "x-t" ]; then if [ "x$1" = "x-t" ]; then
SYNC_TYPES="$2" SYNC_TYPES="$2"
[ "$2" \!= all ] || SYNC_TYPES="$DEFAULT_SYNC_TYPES" [ "$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 fi
get_board get_board
for info in "$TMP_MNT_DIR"/*.info; do for info in "$TMP_MNT_DIR"/*.info; do
...@@ -783,6 +823,9 @@ sync_snps() { ...@@ -783,6 +823,9 @@ sync_snps() {
} }
remote_list() { remote_list() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
remote_mount remote_mount
TBL_NUM=20 TBL_NUM=20
generic_list "$1" "$TMP_RMT_MNT_DIR"/"$REMOTE_PATH" generic_list "$1" "$TMP_RMT_MNT_DIR"/"$REMOTE_PATH"
...@@ -815,6 +858,9 @@ download_tar() { ...@@ -815,6 +858,9 @@ download_tar() {
} }
import_sn() { import_sn() {
if [ $# = 0 ] || [ $# -gt 2 ]; then
die_helping "Wrong number of arguments"
fi
if [ "x-f" = "x$1" ]; then if [ "x-f" = "x$1" ]; then
shift shift
case "$1" in case "$1" in
...@@ -863,6 +909,9 @@ import_sn() { ...@@ -863,6 +909,9 @@ import_sn() {
} }
delete_type() { delete_type() {
if [ $# != 1 ]; then
die_helping "Wrong number of arguments"
fi
# .info files are named ${SNAPSHOT_NUMBER}.info # .info files are named ${SNAPSHOT_NUMBER}.info
grep -l "TYPE=\"$1\"" "$TMP_MNT_DIR"/*.info | \ grep -l "TYPE=\"$1\"" "$TMP_MNT_DIR"/*.info | \
sed -n 's|.*/\([0-9]\+\)\.info$|\1|p' | \ sed -n 's|.*/\([0-9]\+\)\.info$|\1|p' | \
...@@ -872,6 +921,9 @@ delete_type() { ...@@ -872,6 +921,9 @@ delete_type() {
} }
savepoint() { savepoint() {
if [ $# -gt 1 ]; then
die_helping "Wrong number of arguments"
fi
local time="$1" local time="$1"
[ -n "$time" ] || time=10 [ -n "$time" ] || time=10
commit commit
...@@ -934,6 +986,25 @@ case $command in ...@@ -934,6 +986,25 @@ case $command in
upload) upload)
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)
import_sn "$@" import_sn "$@"
;; ;;
......
...@@ -55,6 +55,18 @@ teardown_file() { ...@@ -55,6 +55,18 @@ teardown_file() {
check_dataset_A "$ROOT_MOUNT"/@1 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" { @test "Rollback works" {
create_dataset_A "$MAIN_MOUNT" create_dataset_A "$MAIN_MOUNT"
check_dataset_A "$MAIN_MOUNT" check_dataset_A "$MAIN_MOUNT"
......