-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
154 lines (127 loc) · 5.13 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# Ubuntu 20.04 - Install script
# To execute this install script, open a terminal and type: chmod +x install.sh && ./install.sh (don't use sudo, use the xtraupload user)
# Install dotnet runtime (Ubuntu)
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1 && \
sudo apt-get install -y aspnetcore-runtime-3.1
# Install MySql
function updateMySqlAuth
{
read -p "Enter new MySql password: " -s mySqlPassword && printf '\n'
read -p "Confirm new password: " -s retypePassword && printf '\n'
if [ $mySqlPassword == $retypePassword ]; then
sudo mysql << EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$mySqlPassword';
FLUSH PRIVILEGES;
exit;
EOF
read -p "Please update the [XtraUpload.WebApi/appsettings.json] with the new database password, once it is done press [Enter] to continue." waiting
else
echo "Confirmation password does not match, try again"
updateMySqlAuth
fi
}
read -p "Do you want to install MySql database? (Y/N): " confirmMySql
if [ $confirmMySql == "Y" ] || [ $confirmMySql == "y" ]; then
sudo apt-get install mysql-server && \
mysql_secure_installation && \
updateMySqlAuth
else
read -p "Please update the [XtraUpload.WebApi/appsettings.json] with the database password, once it is done press [Enter] to continue." waiting
fi
# Install nginx
sudo apt install nginx &&
sudo systemctl enable nginx
sudo ufw allow 'Nginx HTTP' && \
sudo ufw allow 'Nginx HTTPS'
# Install nodejs to build the Angular App
sudo apt install nodejs && \
sudo apt install npm
# Build the solution
buildDir="/var/www/xtraupload"
sudo install -d -m 755 -o $USER $buildDir
if [ ! -d $buildDir ]; then
echo "Directory ${buildDir} DOES NOT exists."
exit 1
fi
dotnet publish --configuration Release -o $buildDir
# Install entity framewrok tools to generate migrations and update the db
dotnet tool install --global dotnet-ef
dotnet ef migrations add initCommit -p ./Database/XtraUpload.Database.Migrations -s XtraUpload.WebApi
dotnet ef database update initCommit -p ./Database/XtraUpload.Database.Migrations -s XtraUpload.WebApi
# Uncomment if you want to generate the db manually
# dotnet ef migrations script -o ./Database/XtraUpload.Database.Migrations/script.sql -p ./Database/XtraUpload.Database.Migrations -s XtraUpload.WebApi
# mv ./Database/XtraUpload.Database.Migrations/script.sql $buildDir
mv "${buildDir}/AngularApp/dist/*" "${buildDir}/AngularApp" && rm "${buildDir}/AngularApp/dist"
# generate ssl certs for localhost. if you don't plan on using a reverse proxy, you can supply certs signed a by public CA (letsencrypt for exemple)
certDir="/home/certificates/localhost"
sudo install -d -m 755 -o $USER $certDir && cd $_
if [ ! -d $certDir ]; then
echo "Directory ${certDir} DOES NOT exists."
exit 1
fi
sudo cat <<EOF >/$certDir/https.config
[req]
default_bits = 2048
default_md = sha256
default_keyfile = key.pem
prompt = no
encrypt_key = no
distinguished_name = req_distinguished_name
req_extensions = v3_req
x509_extensions = v3_ca
[req_distinguished_name]
commonName = "XtraUpload localhost"
[v3_req]
subjectAltName = @alt_ca_main
basicConstraints = critical, CA:false
keyUsage = critical, keyEncipherment
extendedKeyUsage = critical, 1.3.6.1.5.5.7.3.1
[v3_ca]
basicConstraints = critical, CA:TRUE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always, issuer:always
subjectAltName = @alt_ca_main
keyUsage = critical, cRLSign, digitalSignature, keyCertSign
[alt_ca_main]
DNS.1 = localhost
IP.1 = 127.0.0.1
EOF
if [ ! -f $certDir/https.config ]; then
echo $certDir"/https.config does not exist."
exit 1
fi
sudo openssl req -config https.config -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout localhost.key -days 3650 -out localhost.crt
sudo openssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.crt -password pass:";xE)^C8wUH#vP)@5.YGpzv"
sudo chmod 644 localhost.crt localhost.pfx
# Trusting the self signed root certificate
sudo cp localhost.crt /usr/share/ca-certificates && sudo update-ca-certificates
# Generate a monitoring service
sudo bash -c 'cat <<EOF >/etc/systemd/system/api-xtraupload.service
[Unit]
Description=XtraUpload Api Service
[Service]
WorkingDirectory=/var/www/xtraupload
ExecStart=/usr/bin/dotnet /var/www/xtraupload/XtraUpload.WebApi.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=$USER
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
EOF'
if [ ! -f /etc/systemd/system/api-xtraupload.service ]; then
echo "/etc/systemd/system/api-xtraupload.service does not exist."
exit 1
fi
sudo systemctl enable api-xtraupload.service
sudo systemctl start api-xtraupload