#!/bin/sh
# 
#
# +---------------------------------------------------------------------------------------------+
# | Raphael Santamaria (Dexinou) / dexinou@generation-linux.net                                 |
# | Script d'installation automatique de Pure-FTPd 1.0.21                                       |
# |                                                                                             |
# | Ce script est distribué sans garantie et à vos risques et périls.                           |
# | Si ce script fait péter votre machine ça ne sera pas de ma faute :-)                        |
# |                                                                                             |
# | Il a été testé sur Debian Sarge et Etch avec succès.                                        |
# | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
# | Vous pouvez modifier ce script et/ou le redistribué en laissant la licence intacte          |
# | celle que vous êtes en train de lire en ce moment.                                          |
# | La licence devra toujours être affichée...				                        |
# |                                                                                             |
# | Toutes suggestions sont les bienvenues...                                                   |
# +---------------------------------------------------------------------------------------------+
#
# $Author: dexinou $
# $Revision: 0.1b $
# $Date: 2007-06-25 08:39:10 GMT +0100 (lun, 25 Juin 2007) $
# comment le lancer ?
# Placez le dans le dossier /root et faites ceci:
# mv pure-ftpd.txt pure-ftpd.sh
# chmod +x pure-ftpd.sh
# ./pure-ftpd.sh
# Quand l'installe est terminée tappez : ftp localhost
# Utilisateur = domain
# Mot de passe = celui qu'il vous a demandé ;-)

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

### variables ###

update="/usr/bin/apt-get update"

prerequis="apt-get install build-essential libpam-dev ftp openssl libssl-dev libxcrypt-dev libmysqlclient15-dev libpq-dev libpqxx-dev libldap2-dev"

configure="./configure --prefix=/usr/local/pureftpd --without-inetd --without-capabilities --with-mysql --with-ldap \
--with-pgsql --with-paranoidmsg --with-altlog --with-pam --with-puredb --with-cookie --with-throttling \
--with-ratios --with-quotas --with-ftpwho --with-welcomemsg --with-extauth --with-uploadscript --with-virtualhosts \
--with-virtualchroot --with-diraliases --with-peruserlimits --with-language=french --with-tls --with-boring"

### Variables a modifier si necessaire ###

user=domain                		# nom d'utilisateur
folder=/var/www/domain.com 		# espace ftp
vuserid=ftpuser            		# utilisateur physique associé a l'utilisateur virtuel
vgroupid=ftpgroup          		# groupe physique associé a l'utilisateur virtuel
quota=100                  		# quota utilisateur

# Check if pure-ftpd is installed

if ! test -e /usr/local/pureftpd/sbin/pure-ftpd && test -e /usr/sbin/pure-ftpd && test -e /usr/sbin/pure-ftpd-mysql && test -e /usr/local/sbin/pure-ftpd

then 
   echo -e "Warning! Pure-FTPd is installed!, deinstall pure-ftpd first! "
exit 1

echo
echo "Install prerequis..."
echo
sleep 2

$update
$prerequis 

echo "Create user and group for Pure-FTPd..."
echo
sleep 2

groupadd -g 2001 $vgroupid
useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g $vgroupid $vuserid
useradd -g $vgroupid -d /home/ftp -s /bin/false ftp

echo "Done!"
echo
sleep 2
echo "Install Pure-FTPd..."
echo
sleep 2

mkdir /usr/local/src/tar
cd /usr/local/src/tar
wget http://download.generation-linux.net/pureftpd/pure-ftpd-1.0.21.tar.gz
cd ../
tar -zxf tar/pure-ftpd-1.0.21.tar.gz
cd pure-ftpd-1.0.21
$configure
make && make install

echo "Done!"
echo
sleep 2
echo "Create files and folders..."
echo
sleep 2

mkdir /var/lock/subsys
mkdir /var/log/pure-ftpd
mkdir /usr/local/pureftpd/etc
cd configuration-file/
cp pure-config.pl /usr/local/pureftpd/sbin/
cd /usr/local/pureftpd/etc/
wget http://download.generation-linux.net/pureftpd/pure-ftpd.conf
cp /usr/local/src/pure-ftpd-1.0.21/pam/ftpusers /usr/local/pureftpd/etc/
cp /usr/local/src/pure-ftpd-1.0.21/pam/ftpusers /etc/
cp /usr/local/src/pure-ftpd-1.0.21/pam/pure-ftpd /usr/local/pureftpd/etc/
cp /usr/local/src/pure-ftpd-1.0.21/pam/pure-ftpd /etc/
chmod +x /usr/local/pureftpd/sbin/pure-config.pl

echo "Done!"
echo
sleep 2
echo "Create boot and runlevels..."
echo
sleep 2

cd /etc/init.d/
wget http://download.generation-linux.net/pureftpd/pure-ftpd
chmod +x pure-ftpd
update-rc.d pure-ftpd defaults

echo "Done!"
echo
sleep 2
echo "Install tls/ssl..."
echo
sleep 

mkdir -p /etc/ssl/private
openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
chmod 600 /etc/ssl/private/*.pem

echo "Done!"
echo
sleep 2
echo "Create the first virtualuser..."
echo
sleep

/usr/local/pureftpd/bin/pure-pw useradd $user -u $vuserid -g $vgroupid -d $folder -N $quota 
/usr/local/pureftpd/bin/pure-pw mkdb

echo "Done!"
echo
sleep 2
echo "Starting Pure-FTPd..."
echo
sleep 2

/etc/init.d/pure-ftpd start 

echo "Congratulations ! Pure-FTPd is sucessfully installed and running!"
echo
sleep 2

