Files
uberspace-setup/uber-standardsetup.sh
2015-12-06 22:25:00 +01:00

120 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
########################################################################
# Copyright (C) 2014 Max Mehl <mail@mehl.mx>
########################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
#
# This script enables users to quickly setup a new Uberspace.de host
# with domains, symlinks etc.
# Afterwards it creates a handy datasheet (which was the main reason for
# writing this script)
#
########################################################################
SERVER=$(echo $HOSTNAME | sed -e 's/.uberspace.de//g')
VIRTUAL=/var/www/virtual/$USER
MYSQLPASS=$(awk '/^\[client\]/,/^password=/' ~/.my.cnf | grep "password=" | sed -e 's/password=//g' | sed -e 's/[ \t].*//g')
# In older hosts, there's only 1 MySQL password and not 2
if [ "$MYSQLPASS" == "" ]; then
MYSQLPASS=$(grep "password=" ~/.my.cnf | sed -e 's/password=//g' | sed -e 's/[ \t].*//g')
fi
read -p "Domain: " DOMAIN
read -p "SSH Passwort: " SSHPASS
IP=$(wget -q -O - http://ip4.nandus.net)
echo "User: $USER" # user in system
echo "Hostname: $HOSTNAME" # e.g. cetus.uberspace.de
echo "Homedir: $HOME" # Homedir
echo "Server: $SERVER" # e.g. cetus
echo "Domain: $DOMAIN"
echo "IP: $IP"
echo "Virtualdir: $VIRTUAL"
echo "MySQL Password: $MYSQLPASS"
echo "SSH Password: $SSHPASS"
echo ""
read -p "All correct? If not, cancel now." END
# Setup domain
uberspace-add-domain -d $DOMAIN -w
uberspace-add-domain -d "*.$DOMAIN" -w
uberspace-add-domain -d $DOMAIN -m
# Setup basic directories
mkdir ~/backup
mkdir -p ~/bin ~/lib/python2.4 ~/lib/python2.6
# Setup softlinks
ln -s $VIRTUAL ~/virtual
# Mail
vsetup
## PHP
# Piwik and WP don't work smoothly with PHP 5.6, so switch to 5.5
cp $HOME/etc/phpversion $HOME/etc/phpversion.original
echo "PHPVERSION=5.5" > $HOME/etc/phpversion
# Webmail
mkdir $VIRTUAL/webmail.$DOMAIN
echo "RedirectPermanent / https://webmail.$HOSTNAME" > $VIRTUAL/webmail.$DOMAIN/.htaccess
# Web administration panel
read -p "Should the web administration panel be installed? [y/N] " YN
if [ "$YN" == "y" ]; then
SENDMAILPATH=$(which sendmail)
read -p "TO which email should reports be sent?" TOEMAIL
read -p "FROM which email should reports be sent?" FREMAIL
git clone http://src.mehl.mx/git/uberspace-webadmin.git $VIRTUAL/panel.$DOMAIN
# Create and edit config.cfg
cp $VIRTUAL/panel.$DOMAIN/config.cfg.sample $VIRTUAL/panel.$DOMAIN/config.cfg
sed -r -i \
-e "s|DOMAIN=.*|DOMAIN=$DOMAIN|" \
-e "s|TOEMAIL=.*|DOMAIN=$DOMAIN|" \
-e "s|FREMAIL=.*|DOMAIN=$DOMAIN|" \
-e "s|SENDMAILPATH=.*|DOMAIN=$DOMAIN|" \
$VIRTUAL/panel.$DOMAIN/config.cfg
# Set htaccess and htpasswd
cp $VIRTUAL/panel.$DOMAIN/.htaccess.sample $VIRTUAL/panel.$DOMAIN/.htaccess
sed -r -i \
-e "s|AuthUserFile.*|AuthUserFile $VIRTUAL/panel.$DOMAIN/.htpasswd|" \
$VIRTUAL/panel.$DOMAIN/.htaccess
htpasswd -b -c $VIRTUAL/panel.$DOMAIN/.htpasswd $USER $SSHPASS
# Install dependencies
pip install pexpect --user
fi
# Create datasheet
sed -e 's/SEDDOMAIN/'$DOMAIN'/g' \
-e 's/SEDIP/'$IP'/g' \
-e 's/SEDUSER/'$USER'/g' \
-e 's/SEDHOSTNAME/'$HOSTNAME'/g' \
-e 's/SEDMYSQLPASS/'$MYSQLPASS'/g' \
-e 's/SEDSSHPASS/'$SSHPASS'/g' \
uber-datenblatt-template.txt > $HOME/$USER-Notes.txt