more clean up and indentation

This commit is contained in:
Daniel Hansson 2017-01-16 20:48:58 +01:00 committed by GitHub
parent 484ad593d0
commit dee9a6eb82

View File

@ -4,7 +4,8 @@
## Variable's
# Docker URL
SUBDOMAIN=$(whiptail --title "Techandme.se Collabora" --inputbox "Collabora subdomain eg: office.yourdomain.com" "$WT_HEIGHT" "$WT_WIDTH" 3>&1 1>&2 2>&3)
NCDOMAIN=$(whiptail --title "Techandme.se Collabora" --inputbox "Nextcloud url, make sure it looks like this: cloud\\.yourdomain\\.com" "$WT_HEIGHT" "$WT_WIDTH" cloud\\.yourdomain\\.com 3>&$
# Nextcloud Main Domain
NCDOMAIN=$$(whiptail --title "Techandme.se Collabora" --inputbox "Nextcloud url, make sure it looks like this: cloud\\.yourdomain\\.com" "$WT_HEIGHT" "$WT_WIDTH" cloud\\.yourdomain\\.com 3>&1 1>&2 2>&3)
# Vhost
HTTPS_CONF="/etc/apache2/sites-available/$SUBDOMAIN.conf"
# Letsencrypt
@ -15,6 +16,15 @@ WANIP4=$(dig +short myip.opendns.com @resolver1.opendns.com)
# Misc
SCRIPTS=/var/scripts
# Check if root
if [ "$(whoami)" != "root" ]
then
echo
echo -e "\e[31mSorry, you are not root.\n\e[0mYou must type: \e[36msudo \e[0mbash $SCRIPTS/collabora.sh"
echo
exit 1
fi
# Whiptail auto size
calc_wt_size() {
WT_HEIGHT=17
@ -33,38 +43,53 @@ calc_wt_size() {
whiptail --msgbox "Please before you start make sure port 443 is directly forwarded to this machine or open!" "$WT_HEIGHT" "$WT_WIDTH"
# Check if 443 is open using nmap, if not notify the user
if [ $(dpkg-query -W -f='${Status}' nmap 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
if [ $(dpkg-query -W -f='${Status}' nmap 2>/dev/null | grep -c "ok installed") -eq 1 ]
then
echo "nmap is already installed..."
clear
else
apt install nmap -y
fi
if [ $(nmap -sS -p 443 "$WANIP4" | grep -c "open") -eq 1 ]; then
echo "Port is open"
if [ $(nmap -sS -p 443 "$WANIP4" | grep -c "open") -eq 1 ]
then
echo -e "\e[32mPort 443 is open!\e[0m"
apt remove --purge nmap -y
else
whiptail --msgbox "Port 443 is not open..." "$WT_HEIGHT" "$WT_WIDTH"
apt remove --purge nmap -y
exit
exit 1
fi
# Check if Nextcloud is installed
echo "Checking if Nextcloud is installed..."
curl -s https://$DOMAIN/status.php | grep -q 'installed":true'
if [ $? -eq 0 ]
then
sleep 1
else
echo "It seems like Nextcloud is not installed or that you don't use https on your domain."
echo "Please install Nextcloud or activate SSL on your installation to be able to run this script"
exit 1
fi
# Update & upgrade
apt update
apt upgrade -y
apt -f install -y
# Check if docker is installed
if [ $(dpkg-query -W -f='${Status}' docker.io 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
echo "Docker.io is installed..."
if [ $(dpkg-query -W -f='${Status}' docker.io 2>/dev/null | grep -c "ok installed") -eq 1 ]
then
sleep 1
else
apt install docker.io -y
apt install docker.io -y
fi
if [ $(dpkg-query -W -f='${Status}' git 2>/dev/null | grep -c "ok installed") -eq 1 ]; then
echo "Git is installed..."
if [ $(dpkg-query -W -f='${Status}' git 2>/dev/null | grep -c "ok installed") -eq 1 ]
then
sleep 1
else
apt install git -y
apt install git -y
fi
# Install Collabora docker
@ -72,11 +97,10 @@ docker pull collabora/code
docker run -t -d -p 127.0.0.1:9980:9980 -e "domain=$NCDOMAIN" --restart always --cap-add MKNOD collabora/code
# Install Apache2
if [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 1 ];
if [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 1 ]
then
echo "Apache2 is installed..."
echo "Apache2 is installed..."
else
{
i=1
while read -r line; do
@ -84,7 +108,6 @@ else
echo $i
done < <(apt install apache2 -y)
} | whiptail --title "Progress" --gauge "Please wait while installing Apache2" 6 60 0
fi
# Enable Apache2 module's
@ -96,10 +119,9 @@ a2enmod ssl
# Create Vhost for Collabora online in Apache2
if [ -f "$HTTPS_CONF" ];
then
echo "Virtual Host exists"
echo "Virtual Host exists"
else
touch "$HTTPS_CONF"
touch "$HTTPS_CONF"
cat << HTTPS_CREATE > "$HTTPS_CONF"
<VirtualHost *:443>
ServerName $SUBDOMAIN:443
@ -142,17 +164,17 @@ else
# Download as, Fullscreen presentation and Image upload operations
ProxyPass /lool https://127.0.0.1:9980/lool
ProxyPassReverse /lool https://127.0.0.1:9980/lool
ProxyPassReverse /lool https://127.0.0.1:9980/lool
</VirtualHost>
HTTPS_CREATE
if [ -f "$HTTPS_CONF" ];
then
echo "$HTTPS_CONF was successfully created"
sleep 2
echo "$HTTPS_CONF was successfully created"
sleep 2
else
echo "Unable to create vhost, exiting..."
exit
echo "Unable to create vhost, exiting..."
exit
fi
fi
@ -162,7 +184,6 @@ fi
# Stop Apache to aviod port conflicts
a2dissite 000-default.conf
sudo service apache2 stop
############################### Still need to rewrite test-new-config.sh for collabora domain and add more tries for letsencrypt
# Generate certs
cd /etc