From 495377369851af734ebfb5caca75dcb43f421f10 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Wed, 27 Nov 2024 14:44:30 +0100 Subject: [PATCH] Bare Metal install Script for SnipeIT --- ct/snipeit.sh | 72 ++++++++++++++++++++++++++ install/snipeit-install.sh | 101 +++++++++++++++++++++++++++++++++++++ json/snipeit.json | 36 +++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 ct/snipeit.sh create mode 100644 install/snipeit-install.sh create mode 100644 json/snipeit.json diff --git a/ct/snipeit.sh b/ct/snipeit.sh new file mode 100644 index 00000000..f54d7bfd --- /dev/null +++ b/ct/snipeit.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2024 tteck +# Author: tteck (tteckster) +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +function header_info { +clear +cat <<"EOF" + _____ _ _____ _______ + / ____| (_) |_ _|__ __| + | (___ _ __ _ _ __ ___ | | | | + \___ \| '_ \| | '_ \ / _ \ | | | | + ____) | | | | | |_) | __/_| |_ | | + |_____/|_| |_|_| .__/ \___|_____| |_| + | | + |_| +EOF +} +header_info +echo -e "Loading..." +APP="SnipeIT" +var_disk="20" +var_cpu="2" +var_ram="2048" +var_os="debian" +var_version="12" +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 +check_container_storage +check_container_resources +if [[ ! -d /var ]]; then msg_error "No ${APP} Installation Found!"; exit; fi +msg_info "Updating ${APP} LXC" +apt-get update &>/dev/null +apt-get -y upgrade &>/dev/null +msg_ok "Updated ${APP} LXC" +exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" diff --git a/install/snipeit-install.sh b/install/snipeit-install.sh new file mode 100644 index 00000000..46ae36f1 --- /dev/null +++ b/install/snipeit-install.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +#Copyright (c) 2021-2024 community-scripts ORG +# Author: Michel Roegl-Brunner (michelroegl-brunner) +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt-get install -y curl +$STD apt-get install -y git +$STD apt-get install -y sudo +$STD apt-get install -y mc +$STD apt-get install -y nginx +$STD apt-get install -y php8.2-{bcmath,common,ctype,curl,fileinfo,fpm,gd,iconv,intl,mbstring,mysql,soap,xml,xsl,zip,cli} +$STD apt-get install -y mariadb-server +msg_ok "Installed Dependencies" + +msg_info "Installing Composer" +curl -sS https://getcomposer.org/installer -o composer-setup.php +php composer-setup.php --install-dir=/usr/local/bin --filename=composer +msg_ok "Installed Composer" + +msg_ok "Configre Database\n" +read -r -p "Enter password for Database user: " password +echo -e 'CREATE DATABASE snipeit;' | mysql +echo -e "GRANT ALL ON snipeit.* TO snipeit@localhost identified by '$password';" | mysql +echo -e 'FLUSH PRIVILEGES;' | mysql +msg_ok "Configured Database" + +msg_info "Clone SnipeIT from Github" +cd /var/www/html +git clone https://github.com/snipe/snipe-it snipe-it +msg_ok "Finished cloning" + +msg_info "Configure SnipeIT" +cd snipe-it +cp .env.example .env +IPADDRESS=$(hostname -I | awk '{print $1}') +sed -i "s|^APP_URL=.*|APP_URL=http://$IPADDRESS|" .env + +sed -i "s|^DB_DATABASE=.*|DB_DATABASE=snipeit|" .env +sed -i "s|^DB_USERNAME=.*|DB_USERNAME=snipeit|" .env +sed -i "s|^DB_PASSWORD=.*|DB_PASSWORD=$password|" .env +chown -R www-data: /var/www/html/snipe-it +chmod -R 755 /var/www/html/snipe-it +git config --global --add safe.directory /var/www/html/snipe-it + +msg_ok "Configred SnipeIT" + +msg_info "Update SnipeIT dependencies" +export COMPOSER_ALLOW_SUPERUSER=1 +composer update --no-plugins --no-scripts +composer install --no-dev --prefer-source --no-plugins --no-scripts +msg_ok "Update OK" + +msg_info "Generate APP_KEY" +php artisan key:generate --force +msg_ok "Done" + +msg_info "Configure NGINX" +echo -e ' +server { + listen 80; + server_name '$IPADDRESS'; + root /var/www/html/snipe-it/public; + + index index.php; + + location / { + try_files $uri $uri/ /index.php?$query_string; + + } + + location ~ \.php$ { + include fastcgi.conf; + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/run/php/php8.2-fpm.sock; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +}' > /etc/nginx/conf.d/snipeit.conf +systemctl restart nginx +msg_ok "Configured NGINX" + +msg_ok "SnipeIT is up and running, head to $IPADDRESS to reach the site" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" diff --git a/json/snipeit.json b/json/snipeit.json new file mode 100644 index 00000000..0eb7228b --- /dev/null +++ b/json/snipeit.json @@ -0,0 +1,36 @@ +{ + "name": "SnipeIT", + "slug": "snipeit", + "categories": [ + 8 + ], + "date_created": "2024-25-11", + "type": "ct", + "updateable": false, + "privileged": false, + "interface_port": null, + "documentation": null, + "website": "https://snipe-it.readme.io/docs/introduction", + "logo": "https://github.com/snipe/snipe-it/blob/master/public/img/logo.png", + "description": "This is a FOSS project for asset management in IT Operations. Knowing who has which laptop, when it was purchased in order to depreciate it correctly, handling software licenses, etc.", + "install_methods":{ + "type": "default", + "script": "ct/snipeit.sh", + "resources": { + "cpu": "2", + "ram": "2048", + "hdd": "20", + "os": "debian", + "version": "12" + } + }, + "default_credentials": { + "username": null, + "password": null + }, + "notes": + { + "text": "If the LXC is created Privileged, the script will automatically set up USB passthrough.", + "type": "warning" + } +}