Reworked the --install option, it now works

This commit is contained in:
Jarno Rankinen 2022-04-18 17:14:03 +03:00
parent 3e1fd62d0f
commit 7335f4a879
1 changed files with 25 additions and 23 deletions

36
snapsh
View File

@ -18,7 +18,7 @@
# Environment set up: # Environment set up:
SNAPSH_VERSION='0.2.0' SNAPSH_VERSION='0.2.1'
# 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
@ -389,24 +389,31 @@ install() {
root_check root_check
CURRENT_SNAPSH=$(command -v snapsh) SRC_DIR=${0%/*}
INSTALLED=$? INSTALLED=$(command -v snapsh)
if [[ -n "$INSTALLED" ]]; then
printf "Installing from $0. Make sure you are not executing snapsh from your \$PATH!\n" 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..." read -p "Press enter to continue or CTRL-C to stop..."
unset $REPLY unset $REPLY
if [[ ! "$INSTALLED" ]]; then
cp $0 $INSTALL_DIR
exit 0
else
CURRENT_VERSION=$(snapsh -v) CURRENT_VERSION=$(snapsh -v)
if [[ "$CURRENT_VERSION" != "$SNAPSH_VERSION" ]]; then if [[ "$CURRENT_VERSION" != "$SNAPSH_VERSION" ]]; then
SRC_DIR=${0%/*} printf "${INSTALL_DIR} already contains snapsh version $CURRENT_VERSION.\n"
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) " printf "Do you want to overwrite it with version $SNAPSH_VERSION? (y/n) "
read -n1 read -n1 OVERWRITE
if [[ "$REPLY" == "y" ]]; then else
printf "\nSame version of snapsh is already installed, exiting.\n"
exit 1
fi
fi
if [[ "$OVERWRITE" == "y" ]] || [[ -z "$INSTALLED" ]]; then
printf "Installing snapsh executable to $INSTALL_DIR"
cp -v $0 $INSTALL_DIR cp -v $0 $INSTALL_DIR
cp -v $SRC_DIR/snapsh.conf /etc/snapsh.conf COPYCONFIG='y'
if [[ -f /etc/snapsh.conf ]]; then
read -p -n1 "/etc/snapsh.conf already exists. Overwrite? (y/n)" COPYCONFIG
fi
[[ "$COPYCONFIG" == "y" ]] && cp -fv $SRC_DIR/snapsh.conf /etc/snapsh.conf
cp -v $SRC_DIR/snapsh-post-rollback.service /etc/systemd/system/ cp -v $SRC_DIR/snapsh-post-rollback.service /etc/systemd/system/
systemctl daemon-reload systemctl daemon-reload
mount_check mount_check
@ -414,11 +421,6 @@ install() {
printf "(Separate backup snapshots of current subvolumes are created automatically by snapsh)\n" printf "(Separate backup snapshots of current subvolumes are created automatically by snapsh)\n"
exit 0 exit 0
fi fi
else
printf "\nSame version of snapsh is already installed, exiting.\n"
exit 1
fi
fi
} }