create_cifs_mounts.sh 2.83 KB
Newer Older
David Beniamine's avatar
David Beniamine committed
1
#!/bin/bash
2 3 4 5 6
if [ `dpkg -l | egrep -c "cifs-utils|smbclient"` -lt 2 ]
then
    apt-get update
    apt-get -y install cifs-utils smbclient
fi
David Beniamine's avatar
David Beniamine committed
7

8 9 10 11 12 13 14
for d in /home/shares/*/*
do
    umount $d > /dev/null 2>&1 || umount $d/* > /dev/null 2>&1
    rmdir $d/* > /dev/null 2>&1
    rmdir $d > /dev/null 2>&1
done

David Beniamine's avatar
David Beniamine committed
15 16 17 18
# Remove all ^//ecole-dc lines in fstab
sed -i.bak '/^\/\/ecole-dc/d' /etc/fstab

declare -A LEVELS
19 20
LEVELS=(['01-mini']='CP' ['02-super']='CE' ['03-maxi']='CM')
CLASSES=(['01-mini']='01-CP' ['02-super']='02-CE1-CE2' ['03-maxi']='03-CM1-CM2')
David Beniamine's avatar
David Beniamine committed
21 22 23 24 25

# Students
for usr in 01-mini 02-super 03-maxi
do
    mkdir -p /home/shares/$usr/ELEVES
David Beniamine's avatar
David Beniamine committed
26
    mkdir -p /home/shares/$usr/PROFESSEURS
27
    chown -R $usr:$usr /home/shares/$usr
David Beniamine's avatar
David Beniamine committed
28
    lvl=${LEVELS[$usr]}
29
    if [ $lvl != 'CP' ]
David Beniamine's avatar
David Beniamine committed
30
    then
David Beniamine's avatar
David Beniamine committed
31
        lvl2="${lvl}1-${lvl}2"
David Beniamine's avatar
David Beniamine committed
32 33 34
    else
        lvl2=$lvl
    fi
35
    lvlcred=$(echo "$lvl" | awk '{print tolower($0)}')
David Beniamine's avatar
David Beniamine committed
36
    cat <<EOF>>/etc/fstab
37 38
//ecole-dc/$lvl2/donnees /home/shares/$usr/PROFESSEURS/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/$lvlcred,uid=$usr,gid=$usr 0 0
//ecole-dc/$lvl2/travail /home/shares/$usr/ELEVES/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/$lvlcred,uid=$usr,gid=$usr 0 0
David Beniamine's avatar
David Beniamine committed
39 40 41
EOF
done
# profs
David Beniamine's avatar
David Beniamine committed
42
for usr in prof direction
David Beniamine's avatar
David Beniamine committed
43
do
David Beniamine's avatar
David Beniamine committed
44
    mkdir -p /home/shares/$usr/SCAN
45
    for classe in 01-CP 02-CE1-CE2 03-CM1-CM2
David Beniamine's avatar
David Beniamine committed
46 47 48
    do
        mkdir -p /home/shares/$usr/$classe/PROFESSEURS
        mkdir -p /home/shares/$usr/$classe/ELEVES
David Beniamine's avatar
David Beniamine committed
49
        lvl=`echo $classe | sed 's/^[0-9]*-//'`
David Beniamine's avatar
David Beniamine committed
50
        # Should not be prof-cp
David Beniamine's avatar
David Beniamine committed
51
        cat <<EOF>>/etc/fstab
52 53
//ecole-dc/profs-$lvl/classe/donnees /home/shares/$usr/$classe/PROFESSEURS/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/prof,uid=$usr,gid=$usr 0 0
//ecole-dc/profs-$lvl/classe/travail /home/shares/$usr/$classe/ELEVES/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/prof,uid=$usr,gid=$usr 0 0
David Beniamine's avatar
David Beniamine committed
54 55
EOF
    done
David Beniamine's avatar
David Beniamine committed
56 57
    chown -R $usr:$usr /home/shares/$usr
    cat <<EOF>>/etc/fstab
David Beniamine's avatar
David Beniamine committed
58
//ecole-dc/SCAN /home/shares/$usr/SCAN/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/prof,uid=$usr,gid=$usr 0 0
David Beniamine's avatar
David Beniamine committed
59
EOF
David Beniamine's avatar
David Beniamine committed
60 61 62 63
done

# Confidential
mkdir -p /home/shares/prof/CONFIDENTIEL
David Beniamine's avatar
David Beniamine committed
64 65
mkdir -p /home/shares/direction/CONFIDENTIEL_PROFESSEURS
mkdir -p /home/shares/direction/CONFIDENTIEL_DIRECTION
David Beniamine's avatar
David Beniamine committed
66
cat <<EOF>>/etc/fstab
67 68 69
//ecole-dc/svc-prof/perso /home/shares/prof/CONFIDENTIEL/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/prof,uid=prof,gid=prof 0 0
//ecole-dc/svc-prof/perso /home/shares/direction/CONFIDENTIEL_PROFESSEURS/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/prof,uid=direction,gid=direction 0 0
//ecole-dc/svc-dir/perso /home/shares/direction/CONFIDENTIEL_DIRECTION/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/dir,uid=direction,gid=direction 0 0
David Beniamine's avatar
David Beniamine committed
70
EOF
71 72 73 74 75

cp `dirname $0`/mount_shares.service /etc/systemd/system/
systemctl daemon-reload
systemctl start mount_shares.service
systemctl enable mount_shares.service