|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: Kristian Skov |
| 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 update |
| 17 | +$STD apt-get install -y \ |
| 18 | + ssh \ |
| 19 | + software-properties-common |
| 20 | +$STD add-apt-repository -y ppa:dotnet/backports |
| 21 | +$STD apt-get install -y \ |
| 22 | + dotnet-sdk-9.0 \ |
| 23 | + vsftpd \ |
| 24 | + nginx |
| 25 | +msg_ok "Installed Dependencies" |
| 26 | + |
| 27 | +msg_info "Configure Application" |
| 28 | +var_project_name="default" |
| 29 | +read -r -p "Type the assembly name of the project: " var_project_name |
| 30 | +echo "Target assembly: '${var_project_name}'" |
| 31 | +msg_ok "Application Configured" |
| 32 | + |
| 33 | +msg_info "Setting up FTP Server" |
| 34 | +useradd ftpuser |
| 35 | +FTP_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) |
| 36 | +usermod --password $(echo ${FTP_PASS} | openssl passwd -1 -stdin) ftpuser |
| 37 | +mkdir -p /var/www/html |
| 38 | +usermod -d /var/www/html ftp |
| 39 | +usermod -d /var/www/html ftpuser |
| 40 | +chown ftpuser /var/www/html |
| 41 | + |
| 42 | +sed -i "s|#write_enable=YES|write_enable=YES|g" /etc/vsftpd.conf |
| 43 | +sed -i "s|#chroot_local_user=YES|chroot_local_user=NO|g" /etc/vsftpd.conf |
| 44 | + |
| 45 | +systemctl restart -q vsftpd.service |
| 46 | + |
| 47 | +{ |
| 48 | + echo "FTP-Credentials" |
| 49 | + echo "Username: ftpuser" |
| 50 | + echo "Password: $FTP_PASS" |
| 51 | +} >> ~/ftp.creds |
| 52 | + |
| 53 | +msg_ok "FTP server setup completed" |
| 54 | + |
| 55 | +msg_info "Setting up Nginx Server" |
| 56 | +rm -f /var/www/html/index.nginx-debian.html |
| 57 | + |
| 58 | +sed "s/\$var_project_name/$var_project_name/g" >myfile <<'EOF' >/etc/nginx/sites-available/default |
| 59 | +map $http_connection $connection_upgrade { |
| 60 | + "~*Upgrade" $http_connection; |
| 61 | + default keep-alive; |
| 62 | +} |
| 63 | +server { |
| 64 | + listen 80; |
| 65 | + server_name $var_project_name.com *.$var_project_name.com; |
| 66 | + location / { |
| 67 | + proxy_pass http://127.0.0.1:5000/; |
| 68 | + proxy_http_version 1.1; |
| 69 | + proxy_set_header Upgrade $http_upgrade; |
| 70 | + proxy_set_header Connection $connection_upgrade; |
| 71 | + proxy_set_header Host $host; |
| 72 | + proxy_cache_bypass $http_upgrade; |
| 73 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 74 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 75 | + } |
| 76 | +} |
| 77 | +EOF |
| 78 | +systemctl reload nginx |
| 79 | +msg_ok "Nginx Server Created" |
| 80 | + |
| 81 | +msg_info "Creating Service" |
| 82 | +cat <<EOF >/etc/systemd/system/kestrel-aspnetapi.service |
| 83 | +[Unit] |
| 84 | +Description=.NET Web API App running on Linux |
| 85 | +
|
| 86 | +[Service] |
| 87 | +WorkingDirectory=/var/www/html |
| 88 | +ExecStart=/usr/bin/dotnet /var/www/html/$var_project_name.dll |
| 89 | +Restart=always |
| 90 | +# Restart service after 10 seconds if the dotnet service crashes: |
| 91 | +RestartSec=10 |
| 92 | +KillSignal=SIGINT |
| 93 | +SyslogIdentifier=dotnet-${var_project_name} |
| 94 | +User=root |
| 95 | +Environment=ASPNETCORE_ENVIRONMENT=Production |
| 96 | +Environment=DOTNET_NOLOGO=true |
| 97 | +
|
| 98 | +[Install] |
| 99 | +WantedBy=multi-user.target |
| 100 | +EOF |
| 101 | +systemctl enable -q --now kestrel-aspnetapi.service |
| 102 | +msg_ok "Created Service" |
| 103 | + |
| 104 | +motd_ssh |
| 105 | +customize |
| 106 | + |
| 107 | +msg_info "Cleaning up" |
| 108 | +$STD apt-get -y autoremove |
| 109 | +$STD apt-get -y autoclean |
| 110 | +msg_ok "Cleaned" |
0 commit comments