From 6a560e460a88c45436452d1a37adcf2249cba344 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Wed, 6 Apr 2022 01:32:04 +0200 Subject: [PATCH] Make installer idempotent --- install.sh | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/install.sh b/install.sh index 8a06701..0a00776 100755 --- a/install.sh +++ b/install.sh @@ -5,26 +5,21 @@ echo "Installing dependencies..." apk add lighttpd curl jq bash youtube-dl ffmpeg -read -p "Please enter your bot token: " token -read -p "Please enter the bot's username (without @): " bot -read -p "Please enter the domain for your bot: " domain -read -p "Do you want to use a log chat? (y/n): " logans -[ ! -z $logans ] && read -p "What's the log chat's chat ID? " logchat - -if [ -f /etc/konata.conf ] +if [ ! -f /etc/konata.conf ] then - read -p "/etc/konata.conf already exists. Do you want to remove it? (y/n) " ans - if [ "$ans" == "y" ] - then - rm /etc/konata.conf - else - echo "Keeping file. Please investigate this file and run the installer again." - exit 1 - fi -else + echo "Configuring bot..." + read -p "Please enter your bot token: " token + read -p "Please enter the bot's username (without @): " bot + read -p "Please enter the domain for your bot: " domain + read -p "Do you want to use a log chat? (y/n): " logans + [ "$logans" == "y" ] && read -p "What's the log chat's chat ID? " logchat + echo "token=$token" >> /etc/konata.conf echo "bot=$bot" >> /etc/konata.conf + echo "domain=$domain" >> /etc/konata.conf [ ! -z $logchat ] && echo "logchat=$logchat" >> /etc/konata.conf +else + . /etc/konata.conf fi echo "Installing application files..." @@ -32,6 +27,7 @@ install -m644 lighttpd.conf /etc/lighttpd/lighttpd.conf mkdir /var/www/konata rand=$RANDOM install -m755 konata.sh /usr/local/bin/konata +rm /var/www/konata/*.sh ln -s /usr/local/bin/konata /var/www/konata/$rand.sh install -m644 index.html /var/www/konata/index.html