HomeBlogMagic

Restore Webserver from CcSync

Mit diesem Script kann ich meine Webpages, mit meinem eigenen Sync Tool, auf einem Ubuntu System wiederherstellen.

#!/bin/bash

echo "Please insert CcSync webserver login"
read CCSYNC_SERVER
echo "Please insert CcSync webserver password"
read -s CCSYNC_PASSWORD

if [ "DEBUG" = "$INSTALL_TYPE" -o "RELEASE" = "$INSTALL_TYPE" ]
then
  echo "Install type already set: $INSTALL_TYPE"
else
  read -p "Install debug version [y/N]" -n 1 -r -s REPLY
  echo ""
  if [[ $REPLY =~ ^[Yy]$ ]]
  then
    export INSTALL_TYPE="DEBUG"
  else
    export INSTALL_TYPE="RELEASE"
  fi
    echo "Install type selected: $INSTALL_TYPE"
fi

################################################################################
# Update system and remove unused packages
apt-get -y update
if [ $? -ne 0 ]; then exit 1; fi
apt-get -y upgrade
if [ $? -ne 0 ]; then exit 1; fi
apt-get -y autoremove
if [ $? -ne 0 ]; then exit 1; fi

################################################################################
# Install common tools
apt-get -y install ssh screen vim
if [ $? -ne 0 ]; then exit 1; fi
apt-get -y install git unzip net-tools
if [ $? -ne 0 ]; then exit 1; fi

################################################################################
# Setup git
git config --global user.email "coolcow_ccos@yahoo.com"
if [ $? -ne 0 ]; then exit 1; fi
git config --global user.name  "Andreas Dirmeier"
if [ $? -ne 0 ]; then exit 1; fi

################################################################################
# Install C/C++ tools
apt-get -y install build-essential cmake libssl-dev
if [ $? -ne 0 ]; then exit 1; fi
# Install C/C++ libraries
apt-get -y install libssl-dev
if [ $? -ne 0 ]; then exit 1; fi

################################################################################
# Install Web dev
PATH=/usr/sbin:$PATH
apt-get -y install apache2 mariadb-server php php-mysql certbot python3-certbot-apache
if [ $? -ne 0 ]; then exit 1; fi
# Php extensions
apt-get -y install php-curl php-dom php-mbstring php-zip php-gd php-soap php-bcmath
if [ $? -ne 0 ]; then exit 1; fi
a2enmod rewrite
if [ $? -ne 0 ]; then exit 1; fi
a2enmod actions
if [ $? -ne 0 ]; then exit 1; fi
a2enmod ssl
if [ $? -ne 0 ]; then exit 1; fi
/etc/init.d/apache2 force-reload
if [ $? -ne 0 ]; then exit 1; fi

################################################################################
# Setup firewall
iptables -F
if [ $? -ne 0 ]; then exit 1; fi
iptables -P INPUT DROP
if [ $? -ne 0 ]; then exit 1; fi
iptables -A INPUT -i lo -p all -j ACCEPT
if [ $? -ne 0 ]; then exit 1; fi
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
if [ $? -ne 0 ]; then exit 1; fi
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
if [ $? -ne 0 ]; then exit 1; fi
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
if [ $? -ne 0 ]; then exit 1; fi
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
if [ $? -ne 0 ]; then exit 1; fi
iptables -A INPUT -p tcp -m tcp --dport 27500 -j ACCEPT
if [ $? -ne 0 ]; then exit 1; fi
#iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
#iptables -A INPUT -p udp -m udp --dport 54 -j ACCEPT
iptables -A INPUT -j DROP
if [ $? -ne 0 ]; then exit 1; fi

# sudo apt install phpmyadmin
# sudo vim /etc/phpmyadmin/apache.conf
# cd /usr/share/phpmyadmin/
# sudo htpasswd -c .htpasswd Coolcow
# sudo vim .htaccess

#systemctl restart systemd-networkd
if [ $? -ne 0 ]; then exit 1; fi

echo "Wait for ip restoring"
sleep 5

systemctl restart apache2
if [ $? -ne 0 ]; then exit 1; fi

cd ~
mkdir git
cd git
git clone https://coolcow.de/projects/CcSync.git
if [ $? -ne 0 ]; then exit 1; fi
cd CcSync
cd Tools
sh build.sh
if [ $? -ne 0 ]; then exit 1; fi
sh install.sh
if [ $? -ne 0 ]; then exit 1; fi

CcSyncClient create $CCSYNC_SERVER $CCSYNC_PASSWORD
if [ $? -ne 0 ]; then exit 1; fi
CcSyncClient dirs $CCSYNC_SERVER /var
if [ $? -ne 0 ]; then exit 1; fi

if [ "RELEASE" = "$INSTALL_TYPE" ]
then
  echo "Set group and user for release mode"
  CcSyncClient groupid $CCSYNC_SERVER www-data
  if [ $? -ne 0 ]; then exit 1; fi
  CcSyncClient userid $CCSYNC_SERVER www-data
  if [ $? -ne 0 ]; then exit 1; fi
fi

if [ "DEBUG" = "$INSTALL_TYPE" ]
then
  echo "Set system settings for debug mode"
  CcSyncClient groupid $CCSYNC_SERVER 1000
  if [ $? -ne 0 ]; then exit 1; fi
  CcSyncClient userid $CCSYNC_SERVER 1000
  if [ $? -ne 0 ]; then exit 1; fi
fi

CcSyncClient once
if [ $? -ne 0 ]; then exit 1; fi

cd /var/install
if [ $? -ne 0 ]; then exit 1; fi
echo "Start installation of downloaded mode"
bash install.sh
if [ $? -ne 0 ]; then exit 1; fi

echo "Installation done"