diff --git a/ct/snowshare.sh b/ct/snowshare.sh index 816036f49..a7363f88b 100644 --- a/ct/snowshare.sh +++ b/ct/snowshare.sh @@ -1,73 +1,43 @@ #!/usr/bin/env bash -source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) # Copyright (c) 2021-2025 community-scripts ORG # Author: TuroYT -# License: MIT -# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/TuroYT/snowshare -function header_info { -clear -cat <<"EOF" - _____ _____ __ - / ___/____ ____ _ __ / ___// /_ ____ ___________ - \__ \/ __ \/ __ \ | /| / / \__ \/ __ \/ __ `/ ___/ _ \ - ___/ / / / / /_/ / |/ |/ / ___/ / / / / /_/ / / / __/ -/____/_/ /_/\____/|__/|__/ /____/_/ /_/\__,_/_/ \___/ - -EOF -} -header_info -echo -e "Loading..." APP="SnowShare" -var_disk="8" -var_cpu="2" -var_ram="2048" -var_os="debian" -var_version="12" +var_tags="${var_tags:-file-sharing}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-2048}" +var_disk="${var_disk:-8}" +var_os="${var_os:-debian}" +var_version="${var_version:-12}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" + variables color catch_errors -function default_settings() { - CT_TYPE="1" - PW="" - CT_ID=$NEXTID - HN=$NSAPP - DISK_SIZE="$var_disk" - CORE_COUNT="$var_cpu" - RAM_SIZE="$var_ram" - BRG="vmbr0" - NET="dhcp" - GATE="" - APT_CACHER="" - APT_CACHER_IP="" - DISABLEIP6="no" - MTU="" - SD="" - NS="" - MAC="" - VLAN="" - SSH="no" - VERB="no" - echo_default -} - function update_script() { -header_info -if [[ ! -d /opt/snowshare ]]; then - msg_error "No ${APP} Installation Found!" + header_info + check_container_storage + check_container_resources + if [[ ! -d /opt/snowshare ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + msg_info "Updating ${APP}" + systemctl stop snowshare + cd /opt/snowshare + git pull + npm ci + npx prisma generate + npm run build + systemctl start snowshare + msg_ok "Updated ${APP}" exit -fi -msg_info "Updating ${APP}" -systemctl stop snowshare -cd /opt/snowshare -git pull -npm ci -npx prisma generate -npm run build -systemctl start snowshare -msg_ok "Updated ${APP}" -exit } start @@ -75,5 +45,6 @@ build_container description msg_ok "Completed Successfully!\n" -echo -e "${APP} should be reachable by going to the following URL. - ${BL}http://${IP}:3000${CL} \n" \ No newline at end of file +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}" \ No newline at end of file diff --git a/install/snowshare-install.sh b/install/snowshare-install.sh index f1f82aa03..a107c8556 100644 --- a/install/snowshare-install.sh +++ b/install/snowshare-install.sh @@ -1,93 +1,81 @@ #!/usr/bin/env bash -# Couleurs pour les messages -YW=$(echo "\033[33m") -BL=$(echo "\033[36m") -RD=$(echo "\033[01;31m") -BGN=$(echo "\033[4;92m") -GN=$(echo "\033[1;92m") -DGN=$(echo "\033[32m") -CL=$(echo "\033[m") -BFR="\\r\\033[K" -HOLD="-" -CM="${GN}✓${CL}" -CROSS="${RD}✗${CL}" +# Copyright (c) 2021-2025 community-scripts ORG +# Author: TuroYT +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE -msg_info() { - local msg="$1" - echo -ne " ${HOLD} ${YW}${msg}..." -} +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os -msg_ok() { - local msg="$1" - echo -e "${BFR} ${CM} ${GN}${msg}${CL}" -} +msg_info "Installing Dependencies" +$STD apt-get install -y \ + curl \ + sudo \ + git \ + make \ + gnupg \ + ca-certificates \ + postgresql \ + postgresql-contrib +msg_ok "Installed Dependencies" -msg_error() { - local msg="$1" - echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" -} - -# Installation des dépendances système -msg_info "Updating system packages" -apt-get update &>/dev/null -apt-get upgrade -y &>/dev/null -msg_ok "Updated system packages" - -msg_info "Installing dependencies" -apt-get install -y curl sudo git wget postgresql postgresql-contrib &>/dev/null -msg_ok "Installed dependencies" - -# Installation de Node.js 20 msg_info "Installing Node.js" -curl -fsSL https://deb.nodesource.com/setup_20.x | bash - &>/dev/null -apt-get install -y nodejs &>/dev/null -msg_ok "Installed Node.js $(node --version)" +mkdir -p /etc/apt/keyrings +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >/etc/apt/sources.list.d/nodesource.list +$STD apt-get update +$STD apt-get install -y nodejs +msg_ok "Installed Node.js $(node -v)" -# Configuration de PostgreSQL -msg_info "Configuring PostgreSQL" -systemctl enable --now postgresql &>/dev/null -sudo -u postgres psql -c "CREATE DATABASE snowshare;" &>/dev/null -sudo -u postgres psql -c "CREATE USER snowshare WITH ENCRYPTED PASSWORD 'snowshare';" &>/dev/null -sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE snowshare TO snowshare;" &>/dev/null -sudo -u postgres psql -c "ALTER DATABASE snowshare OWNER TO snowshare;" &>/dev/null -msg_ok "Configured PostgreSQL" +msg_info "Setting up PostgreSQL Database" +DB_NAME=snowshare +DB_USER=snowshare +DB_PASS="$(openssl rand -base64 18 | cut -c1-13)" +$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" +$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;" +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';" +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';" +$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'" +echo "" >>~/snowshare.creds +echo -e "SnowShare Database User: \e[32m$DB_USER\e[0m" >>~/snowshare.creds +echo -e "SnowShare Database Password: \e[32m$DB_PASS\e[0m" >>~/snowshare.creds +echo -e "SnowShare Database Name: \e[32m$DB_NAME\e[0m" >>~/snowshare.creds +msg_ok "Set up PostgreSQL Database" -# Clonage du dépôt -msg_info "Cloning SnowShare repository" -git clone https://github.com/TuroYT/snowshare.git /opt/snowshare &>/dev/null +msg_info "Installing SnowShare (Patience)" +cd /opt +RELEASE=$(curl -s https://api.github.com/repos/TuroYT/snowshare/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') +$STD git clone https://github.com/TuroYT/snowshare.git cd /opt/snowshare -msg_ok "Cloned repository" +$STD npm ci +msg_ok "Installed SnowShare" -# Installation des dépendances NPM -msg_info "Installing NPM dependencies" -npm ci &>/dev/null -msg_ok "Installed NPM dependencies" - -# Configuration de l'environnement -msg_info "Configuring environment" -cat < /opt/snowshare/.env -DATABASE_URL="postgresql://snowshare:snowshare@localhost:5432/snowshare" +msg_info "Creating Environment Configuration" +cat </opt/snowshare/.env +DATABASE_URL="postgresql://$DB_USER:$DB_PASS@localhost:5432/$DB_NAME" NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET="$(openssl rand -base64 32)" ALLOW_SIGNUP=true NODE_ENV=production EOF -msg_ok "Configured environment" +msg_ok "Created Environment Configuration" -# Génération Prisma et migrations -msg_info "Running Prisma migrations" -npx prisma generate &>/dev/null -npx prisma migrate deploy &>/dev/null -msg_ok "Ran Prisma migrations" +msg_info "Running Database Migrations" +cd /opt/snowshare +$STD npx prisma generate +$STD npx prisma migrate deploy +msg_ok "Ran Database Migrations" -# Build de l'application msg_info "Building SnowShare" -npm run build &>/dev/null +$STD npm run build msg_ok "Built SnowShare" -# Création du service systemd -msg_info "Creating systemd service" +msg_info "Creating Service" cat </etc/systemd/system/snowshare.service [Unit] Description=SnowShare - Modern File Sharing Platform @@ -106,17 +94,19 @@ RestartSec=10 [Install] WantedBy=multi-user.target EOF -systemctl daemon-reload -systemctl enable --now snowshare.service &>/dev/null -msg_ok "Created systemd service" +systemctl enable -q --now snowshare.service +msg_ok "Created Service" -# Configuration du cron pour le nettoyage -msg_info "Setting up cleanup cron job" -(crontab -l 2>/dev/null; echo "0 2 * * * cd /opt/snowshare && /usr/bin/npm run cleanup:expired >> /var/log/snowshare-cleanup.log 2>&1") | crontab - -msg_ok "Setup cleanup cron job" +msg_info "Setting up Cleanup Cron Job" +cat </etc/cron.d/snowshare-cleanup +0 2 * * * root cd /opt/snowshare && /usr/bin/npm run cleanup:expired >> /var/log/snowshare-cleanup.log 2>&1 +EOF +msg_ok "Set up Cleanup Cron Job" + +motd_ssh +customize -# Nettoyage msg_info "Cleaning up" -apt-get autoremove -y &>/dev/null -apt-get autoclean -y &>/dev/null -msg_ok "Cleaned up" \ No newline at end of file +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" \ No newline at end of file