|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | + |
| 4 | +#Copyright (c) 2021-2024 community-scripts ORG |
| 5 | +# Author: Michel Roegl-Brunner (michelroegl-brunner) |
| 6 | +# License: MIT |
| 7 | +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 8 | + |
| 9 | + |
| 10 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 11 | +color |
| 12 | +verb_ip6 |
| 13 | +catch_errors |
| 14 | +setting_up_container |
| 15 | +network_check |
| 16 | +update_os |
| 17 | + |
| 18 | +msg_info "Installing Dependencies" |
| 19 | +$STD apt-get install -y \ |
| 20 | + curl \ |
| 21 | + composer \ |
| 22 | + git \ |
| 23 | + sudo \ |
| 24 | + mc \ |
| 25 | + nginx \ |
| 26 | + php8.2-{bcmath,common,ctype,curl,fileinfo,fpm,gd,iconv,intl,mbstring,mysql,soap,xml,xsl,zip,cli} \ |
| 27 | + mariadb-server |
| 28 | +msg_ok "Installed Dependencies" |
| 29 | + |
| 30 | +msg_info "Setting up database" |
| 31 | +DB_NAME=snipeit_db |
| 32 | +DB_USER=snipeit |
| 33 | +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) |
| 34 | +mysql -u root -e "CREATE DATABASE $DB_NAME;" |
| 35 | +mysql -u root -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED WITH mysql_native_password AS PASSWORD('$DB_PASS');" |
| 36 | +mysql -u root -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost'; FLUSH PRIVILEGES;" |
| 37 | +{ |
| 38 | + echo "SnipeIT-Credentials" |
| 39 | + echo "SnipeIT Database User: $DB_USER" |
| 40 | + echo "SnipeIT Database Password: $DB_PASS" |
| 41 | + echo "SnipeIT Database Name: $DB_NAME" |
| 42 | +} >> ~/snipeit.creds |
| 43 | +msg_ok "Set up database" |
| 44 | + |
| 45 | +msg_info "Installing Snipe-IT" |
| 46 | +cd /opt |
| 47 | +RELEASE=$(curl -s https://api.github.com/repos/snipe/snipe-it/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') |
| 48 | +wget -q "https://github.com/snipe/snipe-it/archive/refs/tags/v${RELEASE}.zip" |
| 49 | +unzip -q v${RELEASE}.zip |
| 50 | +mv snipe-it-${RELEASE} /opt/snipe-it |
| 51 | + |
| 52 | +cd /opt/snipe-it |
| 53 | +cp .env.example .env |
| 54 | +IPADDRESS=$(hostname -I | awk '{print $1}') |
| 55 | + |
| 56 | +sed -i -e "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" \ |
| 57 | + -e "s|^DB_DATABASE=.*|DB_DATABASE=$DB_NAME|" \ |
| 58 | + -e "s|^DB_USERNAME=.*|DB_USERNAME=$DB_USER|" \ |
| 59 | + -e "s|^DB_PASSWORD=.*|DB_PASSWORD=$DB_PASS|" .env |
| 60 | + |
| 61 | +chown -R www-data: /opt/snipe-it |
| 62 | +chmod -R 755 /opt/snipe-it |
| 63 | + |
| 64 | + |
| 65 | +export COMPOSER_ALLOW_SUPERUSER=1 |
| 66 | +$STD composer update --no-plugins --no-scripts |
| 67 | +$STD composer install --no-dev --prefer-source --no-plugins --no-scripts |
| 68 | + |
| 69 | +$STD php artisan key:generate --force |
| 70 | +msg_ok "Installed SnipeIT" |
| 71 | + |
| 72 | +msg_info "Creating Service" |
| 73 | + |
| 74 | +cat <<EOF >/etc/nginx/conf.d/snipeit.conf |
| 75 | +server { |
| 76 | + listen 80; |
| 77 | + root /opt/snipe-it/public; |
| 78 | + server_name $IPADDRESS; |
| 79 | + index index.php; |
| 80 | + |
| 81 | + location / { |
| 82 | + try_files \$uri \$uri/ /index.php?\$query_string; |
| 83 | + } |
| 84 | + |
| 85 | + location ~ \.php\$ { |
| 86 | + include fastcgi.conf; |
| 87 | + include snippets/fastcgi-php.conf; |
| 88 | + fastcgi_pass unix:/run/php/php8.2-fpm.sock; |
| 89 | + fastcgi_split_path_info ^(.+\.php)(/.+)\$; |
| 90 | + fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; |
| 91 | + include fastcgi_params; |
| 92 | + } |
| 93 | +} |
| 94 | +EOF |
| 95 | + |
| 96 | +systemctl reload nginx |
| 97 | +msg_ok "Configured Service" |
| 98 | + |
| 99 | + |
| 100 | +motd_ssh |
| 101 | +customize |
| 102 | + |
| 103 | +msg_info "Cleaning up" |
| 104 | +rm -rf /opt/v${RELEASE}.zip |
| 105 | +$STD apt-get -y autoremove |
| 106 | +$STD apt-get -y autoclean |
| 107 | +msg_ok "Cleaned" |
0 commit comments