Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- dryrun="false"
- if [ ! -z $1 ]; then
- if [ $1 == "dryrun" ]; then
- dryrun="true"
- fi
- fi
- if [ "$(whoami)" == "root" ] ; then
- echo "Sei root, bene."
- else
- echo "Per favore, esegui lo script con sudo"
- exit 1
- fi
- apt-get install dialog
- rootorig=""
- ischroot
- if [ $? -eq 0 ]; then
- echo "Sei in un chroot, considero / come percorso di origine."
- else
- rootorig=$(/usr/bin/dialog --stdout --title " Seleziona cartella di origine" --clear --dselect "/" 20 30 10)
- if [ ! $? -eq 0 ]; then
- echo "Chiudo il programma"
- exit 0
- fi
- fi
- serverslist=$(/usr/bin/dialog --stdout --title " Scegli cosa copiare" --clear --checklist "Che tipo di server vuoi realizzare? \n(spostati con freccia su e giù, scegli con Spazio, conferma con Invio)" 20 30 10 \
- "Utenti" "" off \
- "Cartella_Home" "" off \
- "FStab" "" off \
- "CUPS" "" off \
- "SANED" "" off \
- "Apache" "" off \
- "MySQL" "" off \
- "SAMBA" "" off \
- "Rete" "" off \
- "Lista_pacchetti" "" off \
- )
- #cron, fail2ban, systemd
- if [ ! $? -eq 0 ]; then
- echo "Chiudo il programma"
- exit 0
- fi
- rootdest=$(/usr/bin/dialog --stdout --title " Seleziona cartella di destinazione" --clear --dselect "/" 20 30 10)
- if [ ! $? -eq 0 ]; then
- echo "Chiudo il programma"
- exit 0
- fi
- /usr/bin/dialog --stdout --title " Conferma" --clear --yesno "Vuoi controllare la dimensione delle cartelle?" 6 30
- check=$?
- for opzioneserver in $serverslist
- do
- echo "Hai scelto: $opzioneserver"
- excl="--exclude="
- declare -a source=()
- if [ $opzioneserver == "Utenti" ] ; then
- source=( "${source[@]}" "$rootorig/etc/passwd" )
- source=( "${source[@]}" "$rootorig/etc/shadow" )
- source=( "${source[@]}" "$rootorig/etc/group" )
- source=( "${source[@]}" "$rootorig/etc/gshadow" )
- source=( "${source[@]}" "$rootorig/etc/sudoers" )
- source=( "${source[@]}" "$rootorig/etc/sudoers.d" )
- excl=""
- fi
- if [ $opzioneserver == "Cartella_Home" ] ; then
- source=( "${source[@]}" "$rootorig/home/" )
- excl=""
- fi
- if [ $opzioneserver == "FStab" ] ; then
- source=( "${source[@]}" "$rootorig/etc/fstab" )
- excl=""
- fi
- if [ $opzioneserver == "CUPS" ] ; then
- source=( "${source[@]}" "$rootorig/etc/cups" )
- excl=""
- fi
- if [ $opzioneserver == "SANED" ] ; then
- source=( "${source[@]}" "$rootorig/etc/sane.d" )
- excl=""
- fi
- if [ $opzioneserver == "Apache" ] ; then
- source=( "${source[@]}" "$rootorig/etc/apache2" )
- source=( "${source[@]}" "$rootorig/var/www" )
- excl=""
- fi
- if [ $opzioneserver == "MySQL" ] ; then
- source=( "${source[@]}" "$rootorig/var/lib/mysql" )
- source=( "${source[@]}" "$rootorig/etc/mysql" )
- excl=""
- fi
- if [ $opzioneserver == "SAMBA" ] ; then
- source=( "${source[@]}" "$rootorig/etc/samba/" )
- excl=""
- fi
- if [ $opzioneserver == "Rete" ] ; then
- source=( "${source[@]}" "$rootorig/etc/hosts" )
- source=( "${source[@]}" "$rootorig/etc/network" )
- source=( "${source[@]}" "$rootorig/etc/resolv.conf" )
- excl=""
- fi
- if [ $opzioneserver == "Lista_pacchetti" ] ; then
- source=( "${source[@]}" "$rootorig/etc/apt" )
- ischroot
- if [ $? -eq 0 ]; then
- dpkg --get-selections > "$rootdest/packages.txt"
- else
- echo "Non sei in un chroot, non posso estrarre la lista dei pacchetti."
- fi
- excl=""
- fi
- for s in "${source[@]}"
- do
- dest=$rootdest$s
- if [[ $check -eq 0 && $s != "" && $rootdest != "" ]] ; then
- if [[ $(du -k $s | cut -f1) -gt $(df -Pk $rootdest | tail -1 | awk '{print $4}') ]] ; then #Confronto in KB
- echo "Spazio non sufficiente"
- exit 1
- fi
- fi
- if [ $dryrun == "true" ]; then
- echo "rsync -avr --progress --delete $s $dest"
- else
- if [[ -d $s ]]; then
- mkdir -p $dest
- else
- mkdir -p $(dirname "$dest")
- fi
- rsync -avr --progress --delete $s $dest
- fi
- done
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement