--umount, -v|--version, --install options
This commit is contained in:
parent
338a39ca1a
commit
df62fe781c
74
snapsh
74
snapsh
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
# Environment set up:
|
# Environment set up:
|
||||||
|
|
||||||
|
SNAPSH_VERSION='0.1.0'
|
||||||
|
|
||||||
# If config file exists, source it, otherwise use default values
|
# If config file exists, source it, otherwise use default values
|
||||||
if [[ -e /etc/snapsh.conf ]]; then
|
if [[ -e /etc/snapsh.conf ]]; then
|
||||||
. /etc/snapsh.conf
|
. /etc/snapsh.conf
|
||||||
|
@ -29,8 +31,10 @@ else
|
||||||
fi # (Not the one used in --list)
|
fi # (Not the one used in --list)
|
||||||
|
|
||||||
exit() {
|
exit() {
|
||||||
umount ${TOPLEVEL}
|
if [[ "$SNAPSH_MOUNT" != "true" ]]; then
|
||||||
rmdir ${TOPLEVEL}
|
umount ${TOPLEVEL} &> /dev/null
|
||||||
|
rmdir ${TOPLEVEL} &> /dev/null
|
||||||
|
fi
|
||||||
builtin exit $1
|
builtin exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,6 +340,54 @@ root_check() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version() {
|
||||||
|
|
||||||
|
echo $SNAPSH_VERSION
|
||||||
|
exit
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Convenience option to copy the files to correct places
|
||||||
|
install() {
|
||||||
|
|
||||||
|
INSTALL_DIR=/usr/local/bin/
|
||||||
|
|
||||||
|
root_check
|
||||||
|
|
||||||
|
CURRENT_SNAPSH=$(command -v snapsh)
|
||||||
|
INSTALLED=$?
|
||||||
|
printf "Installing from $0. Make sure you are not executing snapsh from your \$PATH!\n"
|
||||||
|
read -p "Press enter to continue or CTRL-C to stop..."
|
||||||
|
unset $REPLY
|
||||||
|
if [[ ! "$INSTALLED" ]]; then
|
||||||
|
cp $0 $INSTALL_DIR
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
CURRENT_VERSION=$(snapsh -v)
|
||||||
|
if [[ "$CURRENT_VERSION" != "$SNAPSH_VERSION" ]]; then
|
||||||
|
SRC_DIR=${0%/*}
|
||||||
|
printf "/usr/local/bin/snapsh version $CURRENT_VERSION is already installed.\n"
|
||||||
|
printf "Do you want to overwrite it with version $SNAPSH_VERSION? (y/n) "
|
||||||
|
read -n1
|
||||||
|
if [[ "$REPLY" == "y" ]]; then
|
||||||
|
cp -v $0 $INSTALL_DIR
|
||||||
|
cp -v $SRC_DIR/snapsh.conf /etc/snapsh.conf
|
||||||
|
cp -v $SRC_DIR/snapsh-post-rollback.service /etc/systemd/system/
|
||||||
|
systemctl daemon-reload
|
||||||
|
mount_check
|
||||||
|
printf "Please enable snapsh-post-rollback.service to automatically remove leftover subvolumes after rollbacks.\n"
|
||||||
|
printf "(Separate backup snapshots of current subvolumes are created automatically by snapsh)\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
printf "\nSame version of snapsh is already installed, exiting.\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# If no options are given, display help
|
# If no options are given, display help
|
||||||
|
@ -346,7 +398,7 @@ fi
|
||||||
|
|
||||||
|
|
||||||
# Options parsing:
|
# Options parsing:
|
||||||
OPTIONS=$(getopt -a -n snapsh -o hs:d:lr:t: --long help,snapshot:,description:,list,remove:,rollback:,type:,post-rollback,mount -- "$@")
|
OPTIONS=$(getopt -a -n snapsh -o hvs:d:lr:t: --long help,snapshot:,description:,list,remove:,rollback:,type:,post-rollback,mount,umount,install,version -- "$@")
|
||||||
|
|
||||||
# Invalid options (getopt returns nonzero)
|
# Invalid options (getopt returns nonzero)
|
||||||
if [[ "$?" -ne 0 ]]; then
|
if [[ "$?" -ne 0 ]]; then
|
||||||
|
@ -363,7 +415,6 @@ while true; do
|
||||||
|
|
||||||
-h | --help)
|
-h | --help)
|
||||||
help
|
help
|
||||||
shift
|
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -418,9 +469,20 @@ while true; do
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--mount)
|
--mount)
|
||||||
|
SNAPSH_MOUNT=true
|
||||||
mount_check
|
mount_check
|
||||||
shift
|
exit 0
|
||||||
break
|
;;
|
||||||
|
--umount)
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--install)
|
||||||
|
install
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-v | --version)
|
||||||
|
version
|
||||||
|
exit
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--)
|
--)
|
||||||
|
|
|
@ -3,7 +3,7 @@ Description=Remove leftover *.backup subvolumes
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/usr/sbin/snapsh --post-rollback
|
ExecStart=snapsh --post-rollback
|
||||||
RemainAfterExit=yes
|
RemainAfterExit=yes
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|
Loading…
Reference in New Issue