I installed ProFTPD by source compilation and has worked successfully, but I'm thinking, instead of separately doing the all steps, the entire installation can be done by using bash scripting, but I had less knowledge in shell scripting. Please help. These are the following commands I had executed to build and configure ProFTPD:
tar -xzf proftpd-1.3.3e.tar.gz
cd proftpd-1.3.3e
./configure –sysconfdir=/etc
make
make install
ln -s /usr/local/sbin/proftpd /usr/sbin/proftpd
groupadd ftpgroup
useradd -G ftpgroup onedomain -s /sbin/nologin -d /home/onedomain/public_html/
vim /etc/proftpd.conf
Here I had given username, groupname, server name
vim /etc/init.d/proftpd
#!/bin/sh
case $1 in
'start' )
/usr/local/sbin/proftpd
;;
'stop' )
kill `ps -ef | grep proftpd | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
;;
*)
echo "usage: $0 {start|stop}"
esac
Started the service by using /etc/init.d/proftpd start
.
What commands did you type to compile the code? Those are the commands you need in the first version of the shell script.
Subsequent versions will allow you to change the name of the archive containing the source (new versions of the software), and the directory which the source is extracted into (ditto), and the installation directory, and so on. But the first step is to get what you typed into the shell script.
I've not looked at the syntax for the ProFTP config file, so you'll need to rewrite that bit correctly. Use 'here documents' to create the configuration and control files (remembering to set permissions correctly on the files afterwards).
tar -xzf proftpd-1.3.3e.tar.gz || exit
cd proftpd-1.3.3e || exit
./configure –sysconfdir=/etc || exit
make || exit
make install || exit
rm -f /usr/sbin/proftpd
ln -s /usr/local/sbin/proftpd /usr/sbin/proftpd
# Check whether these exist before adding them?
groupadd ftpgroup
useradd -G ftpgroup onedomain -s /sbin/nologin -d /home/onedomain/public_html/
# Maybe save old version before overwriting with new?
cat >/etc/proftpd.conf <<'EOF'
username=onedomain
groupname=ftpgroup
servername=localserver
EOF
chmod 644 /etc/proftpd.conf
# Maybe save old version before overwriting with new?
# Maybe add 'restart' option to stop and start?
cat >/etc/init.d/proftpd <<'EOF'
#!/bin/sh
case $1 in
'start')
/usr/local/sbin/proftpd
;;
'stop')
kill $(ps -ef | grep proftpd | grep -v grep | awk '{print $2}') > /dev/null 2>&1
;;
*)
echo "usage: $0 {start|stop}" >&2
;;
esac
EOF
chmod 755 /etc/init.d/proftpd
/etc/init.d/proftpd start # restart
From here, every time a name is repeated, it should be made into a variable and then the variable used in the rest of the script.
INIT_SCRIPT=/etc/init.d/proftpd
CONF_FILE=/etc/proftpd.conf
BASE_VERSION=proftpd-1.3.3e
tar -xf "${BASE_VERSION}.tar.gz" || exit
Use double quotes around the variable names so things work even if the file path name has spaces in it.
Note that the bits that are most likely to fail — those extracting the code and building the software — are protected by || exit
so if something goes wrong, the script exits without damaging the setup.
I would tend to separate the extract and build phase from the install and configure phase, so I can run the first part as me and only run the installation and configuration as root
. Doing development as root
is dangerous, in my book (or, if you prefer, I take the view that root
should not run a compiler). It's an over-simplification, but moderately sensible. You can do immense damage as root
; minimize the chance of doing so. Building reliable third-party software is different from root
doing development — and more excusable. But you should do as little as possible with root
(superuser) privileges.