diff --git a/install.sh b/install.sh index 371541e..b26284d 100755 --- a/install.sh +++ b/install.sh @@ -1,18 +1,85 @@ #!/usr/bin/bash -commit="git rev-parse --short HEAD" +# work in progress +id -u catask >/dev/null 2>&1 || sudo useradd -r -s /bin/false -m -d /etc/catask -U catask +sudo git clone https://git.mst.k.vu/mst/catask /tmp/catask +cd /tmp/catask + +commit_short_hash=$(git rev-parse --short HEAD) bold=$(tput bold) normal=$(tput sgr0) echo "--------------------------" -echo "${bold}Installing CatAsk (commit ${commit})...${normal}" +echo "${bold}Installing CatAsk (commit ${commit_short_hash})...${normal}" echo "--------------------------" -echo 'Creating & activating virtual environment...' +echo +echo "${bold}Creating & activating virtual environment...${normal}" python3 -m venv venv && . venv/bin/activate -echo 'Installing required packages...' +echo +echo "${bold}Installing required packages...${normal}" pip install -r requirements.txt + +# move to /etc/catask after installing packages +sudo cp -r /tmp/catask/ /etc/catask/ + +echo +echo "${bold}Configuring CatAsk...${normal}" cp .env.example .env; cp config.example.json config.json -read -n 1 -s -r -p "Press any key to open main config file" +echo +read -n 1 -s -r -p "Press any key to open main config file..." nano config.json -read -n 1 -s -r -p "Press any key to open .env config file" +read -n 1 -s -r -p "Press any key to open .env config file..." nano .env + +echo +echo 'Initializing the database...' +if flask init-db; then : ; else + echo 'If the error is "MySQL Connection not available." then you can safely ignore it' + echo 'Otherwise, create an issue at https://git.mst.k.vu/mst/catask/issues/new' + read -p "Proceed? (y/N) " proceed_after_error + proceed_after_error="${proceed_after_error,,}" + echo $proceed_after_error + if [[ "$proceed_after_error" == 'y' ]]; then + echo "Proceeding..." + else + exit 255 + fi +fi + +read -p "Do you want to install CatAsk as a systemd service? (Y/n) " sysd_service_input + +if [[ "$sysd_service_input" == 'n' ]]; then + echo "Start CatAsk with: ${bold}gunicorn -w 4 app:app -b 127.0.0.1:5000${normal}" + echo "Replace ${bold}127.0.0.1:5000${normal} with address where CatAsk will run" + exit 0 +else +read -p "Address on which CatAsk will run (127.0.0.1:5000): " catask_addr +catask_addr=${catask_addr:-127.0.0.1:5000} +sudo cat > /etc/systemd/system/catask.service << EOF +[Unit] +Description=catask + +[Service] +User=catask +WorkingDirectory=$PWD +ExecStart=$PWD/venv/bin/python3 -m gunicorn -w 4 app:app -b $catask_addr +EOF +fi +echo "Created a systemd service with these contents:" +echo "-----------------------" +cat << EOF +[Unit] +Description=catask + +[Service] +User=catask +WorkingDirectory=$PWD +ExecStart=$PWD/venv/bin/python3 -m gunicorn -w 4 app:app -b $catask_addr + +[Install] +WantedBy=multi-user.target +EOF +echo "-----------------------" +echo "Start the service with: ${bold}sudo systemctl start --now catask${normal}" +echo +echo "${bold}Install complete!${normal}"