~ibm-demo/charms/trusty/vsftpd/trunk

« back to all changes in this revision

Viewing changes to hooks/config-changed

  • Committer: Nathan Williams
  • Date: 2012-05-03 22:26:30 UTC
  • Revision ID: nathan@nathanewilliams.com-20120503222630-zfh9na9zla2o4bbd
re-introduced config-changed hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
ftp_user=`config-get ftp_user`
 
4
ftp_passwd=`config-get ftp_passwd`
 
5
ftp_port=`config-get port`
 
6
ftp_throttle=`config-get ftp_throttle`
 
7
 
 
8
if [ ! -z "$ftp_user" ]; then
 
9
    if [ ! -z "$ftp_passwd" ]; then
 
10
        # Create the passwd file if this is the first user
 
11
        if [ ! -f /etc/ftpd.passwd ]; then
 
12
            htpasswd -b -c -d /etc/ftpd.passwd $ftp_user $ftp_passwd
 
13
        else
 
14
        # Add the user
 
15
            htpasswd -b -d /etc/ftpd.passwd $ftp_user $ftp_passwd
 
16
        fi
 
17
        # Set up user directories
 
18
        mkdir -p /srv/ftp/$ftp_user/ftp
 
19
        chown -R ftp:ftp /srv/ftp/$ftp_user
 
20
        chmod -w /srv/ftp/$ftp_user
 
21
    else
 
22
        echo "Must provide a password. Skipping user creation"
 
23
    fi
 
24
fi
 
25
 
 
26
if [ ! -z "$ftp_port" ]; then
 
27
    sed -i "s/^listen_port\=.*$/listen_port\=${ftp_port}/" /etc/vsftpd.conf
 
28
fi
 
29
 
 
30
if [ ! -z "$ftp_throttle" ]; then
 
31
    sed -i "s/^local_max_rate\=.*$/local_max_rate\=${ftp_throttle}/" /etc/vsftpd.conf
 
32
fi
 
33
 
 
34
if [ ! -z "$ftp_port" || ! -z "$ftp_throttle" ]; then
 
35
    service vsftpd status
 
36
    is_running=$?
 
37
    if [ "$is_running" -eq 100 ]; then
 
38
        service vsftpd restart
 
39
    fi
 
40
fi