Add default -y flag to install

This commit is contained in:
Rico Tiongson 2019-02-12 21:13:40 +08:00
parent 16742495eb
commit 1c9b497b56

34
install
View File

@ -17,6 +17,20 @@ abort () {
exec echo "Installation aborted" exec echo "Installation aborted"
} }
sudo mkdir -p $(dirname $CONF_PATH) || abort sudo mkdir -p $(dirname $CONF_PATH) || abort
# check if "-y" or "--yes" is passed as an argument
YES=false
while test $# -gt 0
do
case "$1" in
-y) YES=true
;;
--yes) YES=true
;;
esac
shift
done
sudo chown $USER $(dirname $CONF_PATH) sudo chown $USER $(dirname $CONF_PATH)
if [ ! -f $CONF_PATH ]; then if [ ! -f $CONF_PATH ]; then
if [ ! -f $OLD_CONF_PATH ]; then if [ ! -f $OLD_CONF_PATH ]; then
@ -30,15 +44,17 @@ if [ ! -f $CONF_PATH ]; then
else else
# config file found, ask user if overwrite # config file found, ask user if overwrite
echo "Old conf file found in $CONF_PATH" echo "Old conf file found in $CONF_PATH"
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response if [ $YES == false ]; then
response=${response,,} # tolower read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
if [[ "$response" =~ ^(no|n)$ ]]; then response=${response,,} # tolower
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response if [[ "$response" =~ ^(no|n)$ ]]; then
response=${response,,} read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
if [[ "$response" =~ ^(yes|y)$ ]]; then response=${response,,}
cat $DCONF_PATH > $CONF_PATH || abort if [[ "$response" =~ ^(yes|y)$ ]]; then
else cat $DCONF_PATH > $CONF_PATH || abort
abort else
abort
fi
fi fi
fi fi
fi fi