mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
commit
737dbcf094
3 changed files with 35 additions and 33 deletions
|
@ -1017,8 +1017,11 @@ then
|
|||
# Print the final results of the tests
|
||||
TEST_RESULTS
|
||||
|
||||
# Destroy all snapshots other than snap0
|
||||
destroy_temporary_snapshot
|
||||
# Set snap0 as the current snapshot
|
||||
current_snapshot=snap0
|
||||
# And clean temporary snapshots
|
||||
unset root_snapshot
|
||||
unset subpath_snapshot
|
||||
|
||||
done 3<<< "$(grep "^;; " "$check_process")"
|
||||
|
||||
|
|
|
@ -65,6 +65,9 @@ stop_timer () {
|
|||
create_temp_backup () {
|
||||
# Create a temporary snapshot
|
||||
|
||||
# snap1 for subpath or snap2 for root install
|
||||
snap_number=$1
|
||||
|
||||
start_timer
|
||||
# Check all the witness files, to verify if them still here
|
||||
check_witness_files >&2
|
||||
|
@ -72,13 +75,28 @@ create_temp_backup () {
|
|||
# Stop the container, before its snapshot
|
||||
sudo lxc-stop --name $lxc_name >&2
|
||||
|
||||
# Check if the snapshot already exist
|
||||
if [ ! -e "$snapshot_path/snap$snap_number" ]
|
||||
then
|
||||
echo "snap$snap_number doesn't exist, its first creation can be take a little while." >&2
|
||||
# Create the snapshot.
|
||||
sudo lxc-snapshot --name $lxc_name >> "$test_result" 2>&1
|
||||
|
||||
# Get the last created snapshot, and set it as the new current snapshot.
|
||||
current_snapshot=$(sudo lxc-snapshot --name $lxc_name --list | sort | tail --lines=1 | cut --delimiter=' ' --fields=1)
|
||||
# And return it
|
||||
echo "$current_snapshot"
|
||||
# lxc always creates the first snapshot it can creates.
|
||||
# So if snap1 doesn't exist and you try to create snap2, it will be named snap1.
|
||||
if [ "$snap_number" == "2" ] && [ ! -e "$snapshot_path/snap1" ]
|
||||
then
|
||||
# Rename snap1 to snap2
|
||||
sudo mv "$snapshot_path/snap1" "$snapshot_path/snap2"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Update the snapshot with rsync to clone the current lxc state
|
||||
sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "/var/lib/lxc/$lxc_name/rootfs/" "$snapshot_path/snap$snap_number/rootfs/" > /dev/null 2>> "$test_result"
|
||||
|
||||
# Set this snapshot as the current snapshot
|
||||
current_snapshot=snap$snap_number
|
||||
|
||||
stop_timer 1 >&2
|
||||
|
||||
# Restart the container, after the snapshot
|
||||
|
@ -106,27 +124,6 @@ use_temp_snapshot () {
|
|||
yunohost_result=0
|
||||
}
|
||||
|
||||
destroy_temporary_snapshot () {
|
||||
# Destroy all snapshots other than snap0
|
||||
|
||||
while true
|
||||
do
|
||||
local snapshot=$(sudo lxc-snapshot --name $lxc_name --list | sort | tail --lines=1 | cut --delimiter=' ' --fields=1)
|
||||
if [ -n "$snapshot" ] && [ "$snapshot" != "snap0" ]
|
||||
then
|
||||
echo "Destroy temporary snapshot $snapshot."
|
||||
sudo lxc-snapshot --name $lxc_name --destroy $snapshot
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Clear the variables which contains the snapshot names
|
||||
unset root_snapshot
|
||||
unset subpath_snapshot
|
||||
current_snapshot=snap0
|
||||
}
|
||||
|
||||
#=================================================
|
||||
|
||||
is_lxc_running () {
|
||||
|
@ -292,8 +289,8 @@ LXC_TURNOFF () {
|
|||
sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1
|
||||
fi
|
||||
|
||||
# Destroy all snapshots other than snap0
|
||||
destroy_temporary_snapshot
|
||||
# Set snap0 as the current snapshot
|
||||
current_snapshot=snap0
|
||||
}
|
||||
|
||||
LXC_CONNECT_INFO () {
|
||||
|
|
|
@ -443,7 +443,8 @@ CHECK_SETUP () {
|
|||
if [ -z "$root_snapshot" ]
|
||||
then
|
||||
ECHO_FORMAT "Create a snapshot for root installation.\n" "white" clog
|
||||
root_snapshot=$(create_temp_backup)
|
||||
create_temp_backup 2
|
||||
root_snapshot=snap2
|
||||
fi
|
||||
else
|
||||
# Check if a snapshot already exist for a subpath (or no_url) install
|
||||
|
@ -451,7 +452,8 @@ CHECK_SETUP () {
|
|||
then
|
||||
# Then create a snapshot
|
||||
ECHO_FORMAT "Create a snapshot for sub path installation.\n" "white" clog
|
||||
subpath_snapshot=$(create_temp_backup)
|
||||
create_temp_backup 1
|
||||
subpath_snapshot=snap1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue