create_cifs_mounts.sh 2.61 KB
Newer Older
David Beniamine's avatar
David Beniamine committed
1
#!/bin/bash
David Beniamine's avatar
David Beniamine committed
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

# Remove all ^//ecole-dc lines in fstab
sed -i.bak '/^\/\/ecole-dc/d' /etc/fstab

declare -A LEVELS
David Beniamine's avatar
David Beniamine committed
12
LEVELS=(['01-mini']='cp' ['02-super']='ce' ['03-maxi']='cm')
David Beniamine's avatar
David Beniamine committed
13
CLASSES=(['01-mini']='01-cp' ['02-super']='02-ce1-ce2' ['03-maxi']='03-cm1-cm2')
David Beniamine's avatar
David Beniamine committed
14 15 16 17 18

# Students
for usr in 01-mini 02-super 03-maxi
do
    mkdir -p /home/shares/$usr/ELEVES
David Beniamine's avatar
David Beniamine committed
19
    mkdir -p /home/shares/$usr/PROFESSEURS
20
    chown -R $usr:$usr /home/shares/$usr
David Beniamine's avatar
Fixup  
David Beniamine committed
21
    lvl=${LEVELS[$usr]}
David Beniamine's avatar
David Beniamine committed
22 23
    if [ $lvl != 'cp' ]
    then
David Beniamine's avatar
Fixup  
David Beniamine committed
24
        lvl2="${lvl}1-${lvl}2"
David Beniamine's avatar
David Beniamine committed
25 26 27
    else
        lvl2=$lvl
    fi
David Beniamine's avatar
David Beniamine committed
28
    cat <<EOF>>/etc/fstab
David Beniamine's avatar
David Beniamine committed
29 30
//ecole-dc/$lvl2/donnees /home/shares/$usr/PROFESSEURS/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/$lvl,uid=$usr,gid=$usr 0 0
//ecole-dc/$lvl2/travail /home/shares/$usr/ELEVES/ cifs _netdev,users,noauto,credentials=/etc/cifs/secrets/$lvl,uid=$usr,gid=$usr 0 0
David Beniamine's avatar
David Beniamine committed
31 32 33
EOF
done
# profs
David Beniamine's avatar
David Beniamine committed
34
for usr in prof direction
David Beniamine's avatar
David Beniamine committed
35
do
David Beniamine's avatar
David Beniamine committed
36
    mkdir -p /home/shares/$usr/SCAN
David Beniamine's avatar
David Beniamine committed
37
    for classe in 01-cp 02-ce1-ce2 03-cm1-cm2
David Beniamine's avatar
David Beniamine committed
38 39 40
    do
        mkdir -p /home/shares/$usr/$classe/PROFESSEURS
        mkdir -p /home/shares/$usr/$classe/ELEVES
David Beniamine's avatar
Fixup  
David Beniamine committed
41
        lvl=`echo $classe | sed 's/^[0-9]*-//'`
David Beniamine's avatar
David Beniamine committed
42
        # Should not be prof-cp
David Beniamine's avatar
David Beniamine committed
43
        cat <<EOF>>/etc/fstab
David Beniamine's avatar
David Beniamine committed
44 45
//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
46 47
EOF
    done
David Beniamine's avatar
David Beniamine committed
48 49
    chown -R $usr:$usr /home/shares/$usr
    cat <<EOF>>/etc/fstab
David Beniamine's avatar
David Beniamine committed
50
//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
51
EOF
David Beniamine's avatar
David Beniamine committed
52 53 54 55
done

# Confidential
mkdir -p /home/shares/prof/CONFIDENTIEL
David Beniamine's avatar
David Beniamine committed
56 57
mkdir -p /home/shares/direction/CONFIDENTIEL_PROFESSEURS
mkdir -p /home/shares/direction/CONFIDENTIEL_DIRECTION
David Beniamine's avatar
David Beniamine committed
58
cat <<EOF>>/etc/fstab
David Beniamine's avatar
David Beniamine committed
59 60 61
//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
62
EOF
63 64 65 66 67

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