|
|
Line 3: |
Line 3: |
| * [http://wiki.itcollege.ee/index.php/Skriptimiskeeled_aine_aruanded_2010_s%C3%BCgis/SigmarMuuga/Python Python] | | * [http://wiki.itcollege.ee/index.php/Skriptimiskeeled_aine_aruanded_2010_s%C3%BCgis/SigmarMuuga/Python Python] |
| * [http://wiki.itcollege.ee/index.php/Skriptimiskeeled_aine_aruanded_2010_s%C3%BCgis/SigmarMuuga/Poweshell Poweshell] | | * [http://wiki.itcollege.ee/index.php/Skriptimiskeeled_aine_aruanded_2010_s%C3%BCgis/SigmarMuuga/Poweshell Poweshell] |
|
| |
| ===Tunnitööd - failijagaja ===
| |
| <source lang="bash">
| |
| #!/bin/bash
| |
|
| |
| # Skript, mis jagaks etteantud grupile uue kausta
| |
| #
| |
| # Autor: Sigmar Muuga DK31
| |
| #
| |
| # Kasutamine: jaga.sh KAUST GRUPP <JAGATUD KAUST>
| |
| #
| |
| # Skript teeb järgnevat
| |
| # paigaldab samba (see osa pole kohustuslik)
| |
| # loob kausta KAUST (kui vaja)
| |
| # loob grupi GRUPP (kui vaja)
| |
| # lisab grupile sobivad read smb.conf faili ja teeb failiserveri teenusele #reload'i
| |
|
| |
| usage="Usage: jaga.sh <yourfolder> <yourgroup>"
| |
| smb_conf="smb.conf"
| |
| smb_conf_new=$smb_conf".new"
| |
|
| |
| # kaust peab olema m22ratud
| |
| if [ -z "$1" ]; then
| |
| echo "No folder specified."
| |
| echo $usage
| |
| exit 0
| |
| fi
| |
|
| |
| # grupp peab olema m22ratud
| |
| if [ -z "$2" ]; then
| |
| echo "No group specified."
| |
| echo $usage
| |
| exit 0
| |
| fi
| |
|
| |
| folder=$1
| |
| group=$2
| |
|
| |
| # kontrollime, kas kaust on olemas ja kui pole, siis teeme selle
| |
| if [ ! -e $folder ]
| |
| then
| |
| echo "Folder does not exists, creating it now.."
| |
| mkdir $folder
| |
| echo "Folder created"
| |
| fi
| |
|
| |
| group_count=$(grep -c --word-regexp $group "/etc/group")
| |
|
| |
| # kontrollime, kas grupp on olemas, kui pole, loob selle
| |
| if [ $group_count -lt 1 ]
| |
| then
| |
| echo "Group "$group" does not exist, creating it..."
| |
| groupadd $group
| |
| echo "Group created"
| |
| fi
| |
|
| |
| echo "So far so good, lets smash the smb.conf...\n"
| |
|
| |
| cp $smb_conf $smb_conf_new
| |
|
| |
| echo "["$folder"]" >> $smb_conf_new
| |
| echo " comment = "$folder" access share" >> $smb_conf_new
| |
| echo " path="$folder >> $smb_conf_new
| |
| echo " browseable = yes" >> $smb_conf_new
| |
| echo " valid users = @"$group >> $smb_conf_new
| |
|
| |
|
| |
| echo "Share added to smb.conf, now testing the conf..."
| |
|
| |
| testparm -s $smb_conf_new
| |
|
| |
| mv $smb_conf_new $smb_conf
| |
|
| |
| echo "Restarting samba"
| |
|
| |
| /etc.init.d/samba restart
| |
|
| |
| echo "Folder shared!"
| |
| </source>
| |