-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig-smb
66 lines (52 loc) · 1.94 KB
/
config-smb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
smbfile="/etc/samba/smb.conf"
if [[ "$1" == "add" ]]; then
if [[ -n "$2" ]] && [[ -n "$3" ]]; then
echo "[`date`] Add SAMBA share name = $2, share path = $3"
comment=" comment = $2 produced by config-smb"
exist=`cat ${smbfile} | grep "${comment}"`
if [[ "${#exist}" != "0" ]]; then
echo "- ${2} is exist"
exit 1
fi
share_name="[$2]"
share_path=" path = ${3}"
share_mode=" create mode = 0777"
share_directory_mode=" directory mode = 0777"
share_guest_ok=" guest ok = Yes"
share_guest_only=" guest only = Yes"
share_writable=" writable = Yes"
share_opts=("$share_name" "$share_path" "$share_mode" "$share_directory_mode" "$share_guest_ok" "$share_guest_only" "$share_writable" "$comment")
echo "- add follow new section and options."
for ((i = 0; i < ${#share_opts[@]}; i++)); do
echo "${share_opts[$i]}" | tee -a ${smbfile}
done
else
echo " - missing share name and path. Eg. ./config-smb add myshare /mnt/myshare"
fi
elif [[ "$1" == "del" ]]; then
if [[ -n "$2" ]]; then
echo "[`date`] Del SAMBA share name = $2"
share_name="[$2]"
comment=" comment = $2 produced by config-smb"
start_section=0
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ "$line" == "$share_name" ]]; then
start_section="1"
continue
elif [[ "$line" == "$comment" ]]; then
start_section="0"
continue
fi
if [[ "${start_section}" != "1" ]]; then
echo "$line" >> ${smbfile}.tmp
fi
done < "$smbfile"
mv ${smbfile}.tmp ${smbfile}
else
echo " - missing share name."
fi
else
echo "[`date`] Get SAMBA config."
cat ${smbfile}
fi