|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: Nícolas Pastorello (opastorello) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | + |
| 7 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 8 | +color |
| 9 | +verb_ip6 |
| 10 | +catch_errors |
| 11 | +setting_up_container |
| 12 | +network_check |
| 13 | +update_os |
| 14 | + |
| 15 | +msg_info "Installing Dependencies" |
| 16 | +$STD apt-get install -y \ |
| 17 | + curl \ |
| 18 | + sudo \ |
| 19 | + mc \ |
| 20 | + nginx \ |
| 21 | + php8.2-fpm \ |
| 22 | + php8.2-{common,cli,gd,mbstring,xml,fpm,curl,zip} \ |
| 23 | + unzip \ |
| 24 | + openssl |
| 25 | +msg_ok "Installed Dependencies" |
| 26 | + |
| 27 | +msg_info "Installing PrivateBin" |
| 28 | +RELEASE=$(curl -s https://api.github.com/repos/PrivateBin/PrivateBin/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') |
| 29 | +echo "${RELEASE}" >/opt/${APPLICATION}_version.txt |
| 30 | +mkdir -p /opt/privatebin |
| 31 | +cd /opt/privatebin |
| 32 | +wget -q "https://github.com/PrivateBin/PrivateBin/archive/refs/tags/${RELEASE}.zip" |
| 33 | +$STD unzip -q ${RELEASE}.zip |
| 34 | +mv PrivateBin-${RELEASE}/* . |
| 35 | +msg_ok "Installed PrivateBin" |
| 36 | + |
| 37 | +msg_info "Generating Universal SSL Certificate" |
| 38 | +mkdir -p /etc/ssl/privatebin |
| 39 | +$STD openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \ |
| 40 | + -keyout /etc/ssl/privatebin/key.pem \ |
| 41 | + -out /etc/ssl/privatebin/cert.pem \ |
| 42 | + -subj "/CN=PrivateBin" |
| 43 | +msg_ok "Certificate Generated" |
| 44 | + |
| 45 | +msg_info "Configuring Environment" |
| 46 | +mkdir -p /opt/privatebin/data |
| 47 | +cp cfg/conf.sample.php /opt/privatebin/cfg/conf.php |
| 48 | +sed -i "s|// 'traffic'|'traffic'|g" /opt/privatebin/cfg/conf.php |
| 49 | +chown -R www-data:www-data /opt/privatebin |
| 50 | +chmod -R 0755 /opt/privatebin/data |
| 51 | +msg_ok "Configured Environment" |
| 52 | + |
| 53 | +msg_info "Configuring PHP" |
| 54 | +sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/8.2/fpm/php.ini |
| 55 | +systemctl restart php8.2-fpm |
| 56 | +msg_ok "Configured PHP" |
| 57 | + |
| 58 | +msg_info "Configuring Universal Nginx" |
| 59 | +cat <<EOF >/etc/nginx/sites-available/privatebin.conf |
| 60 | +server { |
| 61 | + listen 80 default_server; |
| 62 | + listen [::]:80 default_server; |
| 63 | + return 301 https://\$host\$request_uri; |
| 64 | +} |
| 65 | +
|
| 66 | +server { |
| 67 | + listen 443 ssl default_server; |
| 68 | + listen [::]:443 ssl default_server; |
| 69 | + |
| 70 | + ssl_certificate /etc/ssl/privatebin/cert.pem; |
| 71 | + ssl_certificate_key /etc/ssl/privatebin/key.pem; |
| 72 | + |
| 73 | + root /opt/privatebin; |
| 74 | + index index.php; |
| 75 | +
|
| 76 | + location / { |
| 77 | + try_files \$uri \$uri/ /index.php\$is_args\$args; |
| 78 | + } |
| 79 | +
|
| 80 | + location ~ \.php\$ { |
| 81 | + include snippets/fastcgi-php.conf; |
| 82 | + fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; |
| 83 | + fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; |
| 84 | + include fastcgi_params; |
| 85 | + } |
| 86 | +
|
| 87 | + location ~ /\.ht { |
| 88 | + deny all; |
| 89 | + } |
| 90 | +
|
| 91 | + add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"; |
| 92 | + add_header X-Content-Type-Options nosniff; |
| 93 | + add_header X-Frame-Options "SAMEORIGIN"; |
| 94 | + add_header X-XSS-Protection "1; mode=block"; |
| 95 | +} |
| 96 | +EOF |
| 97 | +ln -s /etc/nginx/sites-available/privatebin.conf /etc/nginx/sites-enabled/ |
| 98 | +rm -f /etc/nginx/sites-enabled/default |
| 99 | +systemctl reload nginx |
| 100 | +msg_ok "Nginx Configured" |
| 101 | + |
| 102 | +msg_info "Cleaning up" |
| 103 | +rm -rf /opt/privatebin/${RELEASE}.zip |
| 104 | +rm -rf /opt/privatebin/PrivateBin-${RELEASE} |
| 105 | +$STD apt-get -y autoremove |
| 106 | +$STD apt-get -y autoclean |
| 107 | +msg_ok "Cleaned" |
| 108 | + |
| 109 | +motd_ssh |
| 110 | +customize |
0 commit comments