Skip to content

Instantly share code, notes, and snippets.

@NicoVarg99
Created August 26, 2020 07:34
Show Gist options
  • Save NicoVarg99/ceee8dfface32621e54b8873a5881c9e to your computer and use it in GitHub Desktop.
Save NicoVarg99/ceee8dfface32621e54b8873a5881c9e to your computer and use it in GitHub Desktop.
site-migrate
#!/bin/bash
## Nicola Salsotto 25/08/2020
if [[ $EUID -ne 0 ]]; then
echo "Questo script deve essere eseguito come root"
exit 1
fi
###Crea utente
echo 'Inserisci il sito completo (www.example.com) :'
read NEWSITE
echo 'Inserisci il nome utente (example) :'
read NEWUSER
NEWPASS=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''`
echo "La password di $NEWUSER è $NEWPASS"
adduser $NEWUSER
echo "$NEWUSER:$NEWPASS" | chpasswd
mkdir /home/$NEWUSER/log
mkdir /home/$NEWUSER/public
### Configura Apache
#Copia file di configurazione
cp /root/site-template.conf /home/$NEWUSER/site.conf
#Sostituisce i placeholder con i valori corretti
sed -i "s/USERNAMEPLACEHOLDER/$NEWUSER/g" /home/$NEWUSER/site.conf
sed -i "s/SITEPLACEHOLDER/$NEWSITE/g" /home/$NEWUSER/site.conf
#Abilita il nuovo sito
echo "Include /home/$NEWUSER/site.conf" >> /etc/httpd/conf/httpd.conf
systemctl reload httpd
cp /root/offline.html /home/$NEWUSER/public/index.html
chown $NEWUSER:$NEWUSER /home/$NEWUSER/public/index.html
chmod 755 /home/$NEWUSER #Aggiunge il permesso di accesso ad Apache
echo "Sito creato. Posiziona i file in /home/$NEWUSER/public"
echo "Per copiare dal vecchio server: scp -r anaunia.net:/home/$NEWSITE/* /home/$NEWUSER/public"
echo "Per creare un alias, modifica /home/$NEWUSER/site.conf e riavvia Apache."
echo "Per abilitare HTTPS, configura i DNS e poi usa certbot."
<!doctype html>
<!-- Nicola Salsotto 25/08/2020 -->
<meta charset="utf-8" />
<title>Sito offline</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
<article>
<h1>Sito offline</h1>
<div>
<p>
Il sito richiesto è al momento offline per una manutenzione programmata.
<br>
Per favore, riprova tra qualche minuto.
</p>
</div>
</article>
#Template sito - Nicola Salsotto 25/08/2020
<VirtualHost *>
DocumentRoot "/home/USERNAMEPLACEHOLDER/public"
ServerName SITEPLACEHOLDER
# ServerAlias sito senza www
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/svg+xml
<Directory "/home/USERNAMEPLACEHOLDER/public">
allow from all
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /home/USERNAMEPLACEHOLDER/log/error.log
CustomLog /home/USERNAMEPLACEHOLDER/log/access.log combined
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment