initial commit of already existing scripts
This commit is contained in:
20
server/backup.sh
Executable file
20
server/backup.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
# echo "0 11 * * * root /root/scripts/backup.sh" > /etc/cron.d/backup
|
||||
|
||||
BAKDIR=/root/backup/configsave
|
||||
|
||||
# List here all files/dirs which should be backupped
|
||||
BAKS="/root/scripts
|
||||
/etc/apache2/sites-available
|
||||
/etc/samba/smb.conf \
|
||||
/etc/apt-cacher-ng/acng.conf \
|
||||
"
|
||||
|
||||
if [ ! -e $BAKDIR ]; then
|
||||
mkdir -p $BAKDIR
|
||||
fi
|
||||
|
||||
DATE=$(date +%y%m%d-%H%M)
|
||||
|
||||
tar cfvz $BAKDIR/"$DATE".tgz $BAKS
|
||||
40
server/del-web-user.sh
Executable file
40
server/del-web-user.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
WEBROOT="/var/www"
|
||||
DATASHEETS="/root/datasheets"
|
||||
|
||||
function checkwait {
|
||||
read -p "Continue? Press Ctrl+C to cancel." END
|
||||
}
|
||||
|
||||
read -p "Name of the user which should be deleted: " USER
|
||||
WEBDIR="$WEBROOT/$USER"
|
||||
|
||||
if [ "$USER" == "" ]; then
|
||||
echo "User is empty. Abort."
|
||||
exit 1
|
||||
elif [ $(grep -q "$USER" /etc/passwd; echo $?) == "1" ]; then
|
||||
echo "User does not exist. Abort."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[INFO] Deleting website..."
|
||||
chattr -i -V $WEBDIR/php-fcgi/php-fcgi-starter
|
||||
rm -rf $WEBDIR
|
||||
rm -f /etc/apache2/sites-available/$USER.conf
|
||||
a2dissite $USER.conf
|
||||
service apache2 restart
|
||||
|
||||
echo "[INFO] Deleting MySQL databases and user..."
|
||||
echo "DROP DATABASE $USER;" | mysql
|
||||
echo "DROP USER '$USER'@'localhost';" | mysql
|
||||
|
||||
echo "[INFO] Deleting datasheets..."
|
||||
rm -f $DATASHEETS/datasheet-$USER.*
|
||||
rm -f /var/share/teachers/datasheet-$USER.pdf
|
||||
|
||||
echo "[INFO] Deleting user and all its files from system..."
|
||||
deluser --remove-home $USER
|
||||
groupdel $USER
|
||||
|
||||
echo "[INFO] Done."
|
||||
193
server/new-web-user.sh
Executable file
193
server/new-web-user.sh
Executable file
@@ -0,0 +1,193 @@
|
||||
#!/bin/bash
|
||||
|
||||
DOMAINROOT="mit.tareo-tz.org"
|
||||
WEBROOT="/var/www"
|
||||
DATASHEETS="/root/datasheets"
|
||||
|
||||
function checkwait {
|
||||
read -p "Continue? Press Ctrl+C to cancel." END
|
||||
}
|
||||
|
||||
# BASIC QUESTIONS
|
||||
read -p "Name of the new user: " USER
|
||||
|
||||
if [ "$USER" == "" ]; then
|
||||
echo "User is empty. Abort."
|
||||
exit 1
|
||||
elif [ $(grep -q "$USER" /etc/passwd; echo $?) == "0" ]; then
|
||||
echo "User already exists. Abort."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Password of $USER: " PASS
|
||||
|
||||
DOMAIN="$USER.$DOMAINROOT"
|
||||
echo "The new user's domain will be $DOMAIN"
|
||||
read -p "Is that ok? [Y/n]" yn
|
||||
if [ "$yn" == "n" ]; then
|
||||
read -p "Type in custom domain: " DOMAIN
|
||||
fi
|
||||
|
||||
WEBDIR="$WEBROOT/$USER"
|
||||
echo "The new user's web directory will be $WEBDIR"
|
||||
read -p "Is that ok? [Y/n]" yn
|
||||
if [ "$yn" == "n" ]; then
|
||||
read -p "Type in custom web directory: " WEBDIR
|
||||
fi
|
||||
|
||||
checkwait
|
||||
|
||||
# ADDING USER
|
||||
echo "[INFO] Adding user..."
|
||||
adduser $USER
|
||||
echo $USER:$PASS | chpasswd
|
||||
adduser www-data $USER
|
||||
chmod go-rwx /home/$USER # Prevent other users to look into home directory. Webdir will be safe anyway.
|
||||
|
||||
echo "[INFO] Creating necessary directories..."
|
||||
mkdir -p $WEBDIR/conf
|
||||
mkdir $WEBDIR/html
|
||||
mkdir $WEBDIR/logs
|
||||
mkdir $WEBDIR/tmp
|
||||
mkdir $WEBDIR/php-fcgi
|
||||
chown root:$USER $WEBDIR
|
||||
chmod 750 $WEBDIR
|
||||
chown $USER:$USER $WEBDIR/*
|
||||
chmod 750 $WEBDIR/*
|
||||
chmod 550 $WEBDIR/conf
|
||||
|
||||
checkwait
|
||||
|
||||
# PHP-STUFF
|
||||
echo "[INFO] Configuring PHP..."
|
||||
|
||||
cp /etc/php5/cgi/php.ini $WEBDIR/conf/
|
||||
|
||||
sed -r -i \
|
||||
-e "s|;?open_basedir =.*|open_basedir = $WEBDIR/html/:$WEBDIR/tmp/|" \
|
||||
-e "s|;?upload_tmp_dir =.*|upload_tmp_dir = $WEBDIR/tmp|" \
|
||||
-e "s|;?session.save_path =.*|session.save_path = $WEBDIR/tmp|" \
|
||||
$WEBDIR/conf/php.ini
|
||||
|
||||
chown $USER:$USER $WEBDIR/conf/php.ini
|
||||
chmod 440 $WEBDIR/conf/php.ini
|
||||
|
||||
checkwait
|
||||
|
||||
# PHP-FCGI
|
||||
echo "[INFO] Configuring PHP-FCGI..."
|
||||
|
||||
cat > $WEBDIR/php-fcgi/php-fcgi-starter << EOF
|
||||
#!/bin/sh
|
||||
export PHPRC="$WEBDIR/conf"
|
||||
export TMPDIR="$WEBDIR/tmp"
|
||||
export USER="$USER"
|
||||
exec /usr/bin/php5-cgi
|
||||
EOF
|
||||
|
||||
chown $USER:$USER $WEBDIR/php-fcgi/php-fcgi-starter
|
||||
chmod 750 $WEBDIR/php-fcgi/php-fcgi-starter
|
||||
chattr +i -V $WEBDIR/php-fcgi/php-fcgi-starter # Immutable bit to prevent user changes
|
||||
|
||||
checkwait
|
||||
|
||||
# APACHE
|
||||
echo "[INFO] Configuring Apache VirtualHost..."
|
||||
|
||||
cat > /etc/apache2/sites-available/$USER.conf << EOF
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin info@tareo-tz.org
|
||||
ServerName $USER.server.local
|
||||
ServerAlias $DOMAIN
|
||||
SuexecUserGroup $USER $USER
|
||||
AddHandler fcgid-script .php
|
||||
DocumentRoot $WEBDIR/html
|
||||
DirectoryIndex index.htm index.html index.php default.html
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
</Directory>
|
||||
<Directory "$WEBDIR/html">
|
||||
Options -Indexes +MultiViews +FollowSymLinks +ExecCGI
|
||||
FCGIWrapper $WEBDIR/php-fcgi/php-fcgi-starter .php
|
||||
Order allow,deny
|
||||
allow from all
|
||||
</Directory>
|
||||
ErrorLog $WEBDIR/logs/error.log
|
||||
LogLevel warn
|
||||
CustomLog $WEBDIR/logs/access.log combined
|
||||
ServerSignature On
|
||||
</VirtualHost>
|
||||
EOF
|
||||
|
||||
cat > $WEBDIR/html/default.html << EOF
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome!</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Welcome to $USER's website.</p>
|
||||
<p>This is a placeholder. Please upload content via an SFTP program.</p>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
chown $USER:$USER $WEBDIR/html/default.html
|
||||
|
||||
ln -s $WEBDIR/ /home/$USER/webspace
|
||||
|
||||
a2ensite $USER.conf
|
||||
service apache2 restart
|
||||
|
||||
checkwait
|
||||
|
||||
# MYSQL
|
||||
echo "[INFO] Creating MySQL database and user..."
|
||||
|
||||
echo "CREATE DATABASE $USER;" | mysql
|
||||
echo "GRANT usage on *.* to $USER@localhost identified by '$PASS';" | mysql
|
||||
echo "GRANT all privileges on $USER.* to $USER@localhost;" | mysql
|
||||
echo "FLUSH privileges;" | mysql
|
||||
|
||||
|
||||
# DOCS
|
||||
echo "[INFO] Creating datasheets..."
|
||||
|
||||
if [ ! -e $DATASHEETS ]; then
|
||||
mkdir $DATASHEETS
|
||||
fi
|
||||
|
||||
cat > $DATASHEETS/datasheet-$USER.txt << EOF
|
||||
################################
|
||||
### MIT DATASHEET for '$USER'
|
||||
################################
|
||||
|
||||
# Webserver
|
||||
URL: $DOMAIN
|
||||
|
||||
# FTP (Use FileZilla)
|
||||
Server: http://$DOMAIN
|
||||
Port: 22
|
||||
Protocol: SFTP
|
||||
Logon type: Normal
|
||||
User: $USER
|
||||
Pass: $PASS
|
||||
|
||||
Please place your files in $WEBDIR/html/
|
||||
|
||||
# Database (MySQL)
|
||||
Database name: $USER
|
||||
User Name: $USER
|
||||
Password: $PASS
|
||||
Database Host: localhost
|
||||
|
||||
phpMyAdmin: http://pma.$DOMAINROOT
|
||||
EOF
|
||||
|
||||
enscript -p $DATASHEETS/datasheet-$USER.ps $DATASHEETS/datasheet-$USER.txt
|
||||
ps2pdf $DATASHEETS/datasheet-$USER.ps $DATASHEETS/datasheet-$USER.pdf
|
||||
rm $DATASHEETS/datasheet-$USER.ps
|
||||
|
||||
cp $DATASHEETS/datasheet-$USER.pdf /var/share/teachers/
|
||||
|
||||
echo "[INFO] Done."
|
||||
37
server/refresh-web-user.sh
Executable file
37
server/refresh-web-user.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
WEBROOT="/var/www"
|
||||
|
||||
read -p "Name of the user which should be refreshed: " USER
|
||||
WEBDIR="$WEBROOT/$USER"
|
||||
|
||||
if [ "$USER" == "" ]; then
|
||||
echo "User is empty. Abort."
|
||||
exit 1
|
||||
elif [ $(grep -q "$USER" /etc/passwd; echo $?) == "1" ]; then
|
||||
echo "User does not exist. Abort."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[INFO] Deleting website..."
|
||||
rm -rf $WEBDIR/html/*
|
||||
rm -rf $WEBDIR/html/.*
|
||||
|
||||
cat > $WEBDIR/html/default.html << EOF
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome!</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Welcome to $USER's website.</p>
|
||||
<p>This is a placeholder. Please upload content via an SFTP program.</p>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
|
||||
chown $USER:$USER $WEBDIR/html/default.html
|
||||
|
||||
echo "[INFO] Cleaning MySQL database..."
|
||||
mysql -Nse "show tables" $USER | while read table; do mysql -e "drop table $table" $USER; done
|
||||
|
||||
echo "[INFO] Done."
|
||||
9
server/sync-public.sh
Executable file
9
server/sync-public.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# echo "* * * * * root /root/scripts/sync-public.sh" > /etc/cron.d/sync-public
|
||||
|
||||
for ((i = 1; i <= 4; i++)); do # Execute 4 times in a row
|
||||
# echo $(date) >> /var/share/cron.log
|
||||
rsync -a --delete --exclude=".*" /var/share/teachers/public/ /var/share/public/
|
||||
sleep 15 # Wait 15 seconds after completion
|
||||
done
|
||||
Reference in New Issue
Block a user