diff --git a/functions.py b/functions.py index 3b5e6e8..37d7d53 100644 --- a/functions.py +++ b/functions.py @@ -62,8 +62,6 @@ def connectToDb(): password=dbPass, database=dbName, port=dbPort, - pool_name=f"{const.appName}-pool", - pool_size=32, autocommit=True ) return conn diff --git a/install.sh b/install.sh index 9b89668..f507349 100755 --- a/install.sh +++ b/install.sh @@ -1,31 +1,69 @@ #!/usr/bin/bash -# work in progress -id -u catask >/dev/null 2>&1 || sudo useradd -r -s /bin/false -m -d /etc/catask -U catask -# cloning branch dev for now because the installer doesn't exist in main branch yet -git clone https://git.gay/mst/catask ~/tmp/catask --branch dev -cd ~/tmp/catask - -commit_short_hash=$(git rev-parse --short HEAD) +working_dir=~/tmp/catask bold=$(tput bold) normal=$(tput sgr0) +git_repo_url="https://git.mst.k.vu/mst/catask" +git_repo_issue_url="${git_repo_url}/issues/new" echo "--------------------------" -echo "${bold}Installing CatAsk (commit ${commit_short_hash})...${normal}" +echo "${bold}Installing CatAsk...${normal}" echo "--------------------------" echo +echo "${bold}Cloning the repository...${normal}" +# this might work... or not, who knows +id -u catask >/dev/null 2>&1 || sudo useradd -r -s /bin/false -m -d /etc/catask -U catask +# cloning dev branch for now because the installer doesn't exist in main branch yet +git clone $git_repo_url $working_dir --branch dev +cd $working_dir +echo echo "${bold}Creating & activating virtual environment...${normal}" python3 -m venv venv && . venv/bin/activate echo echo "${bold}Installing required packages...${normal}" +echo pip install -r requirements.txt # move to /etc/catask after installing packages -sudo cp -r ~/tmp/catask/ /etc/catask/ +sudo mv $working_dir /etc/ +working_dir="/etc/catask" + +# check if redis is installed +if ! command -v redis-cli 2>&1 >/dev/null; then + + echo + echo "${bold}Installing Redis...${normal}" + # grab variables from os-release file + . /etc/os-release + os_like=$ID_LIKE + case "$os_like" in + debian) + # standard redis install instructions from https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/install-redis-on-linux/#install-on-ubuntudebian + sudo apt-get install lsb-release curl gpg + curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg + sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg + echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list + sudo apt-get update + sudo apt-get install redis + ;; + fedora) + # standard redis install instructions from https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/install-redis-on-linux/#install-on-red-hatrocky + sudo dnf install redis + sudo systemctl enable redis + sudo systemctl start redis + ;; + # if id isn't like debian or fedora + *) + echo "Distribution '$os_like' isn't yet supported. File an issue at ${git_repo_issue_url}" + ;; + esac + +fi echo echo "${bold}Configuring CatAsk...${normal}" -cp .env.example .env; cp config.example.json config.json +cd $working_dir +cp $working_dir/.env.example $working_dir/.env; cp $working_dir/config.example.json $working_dir/config.json echo read -n 1 -s -r -p "Press any key to open main config file..." nano config.json @@ -33,10 +71,10 @@ read -n 1 -s -r -p "Press any key to open .env config file..." nano .env echo -echo 'Initializing the database...' +echo "${bold}Initializing the database...${normal}" 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' + # echo 'If the error is "MySQL Connection not available." then you can safely ignore it' + echo "Otherwise, create an issue at ${git_repo_issue_url}" read -p "Proceed? (y/N) " proceed_after_error proceed_after_error="${proceed_after_error,,}" echo $proceed_after_error @@ -49,7 +87,7 @@ fi read -p "Do you want to install CatAsk as a systemd service? (Y/n) " sysd_service_input -if [[ "$sysd_service_input" == 'n' ]]; then +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 diff --git a/requirements.txt b/requirements.txt index dc2224d..fa69d5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ bleach pathlib Flask-Compress gunicorn +Flask-Limiter