-
Notifications
You must be signed in to change notification settings - Fork 0
/
samba_optimize.sh
executable file
·110 lines (96 loc) · 2.7 KB
/
samba_optimize.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/zsh
set -e
NSMB_TMP=/etc/nsmb.conf_tmp
NSMB=/etc/nsmb.conf
ID=`whoami`
SELF=$0
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
init() {
echo "Checking UID"
if [[ $ID == "root" ]]; then
echo "The script must be ran with user permissions, not root"
echo
exit 2
else
echo "Your user is: $ID. Proceeding"
echo
fi
echo "Writting desktopservices plist"
echo
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
echo "Checking for sudoers records to run sysctl, please enter your password if asked"
echo
set +e
sudo grep -E "^$ID\s+.*\/usr\/sbin\/sysctl" /etc/sudoers &> /dev/null
sudo_check_exit_code=$?
set -e
if [ $sudo_check_exit_code -ne 0 ]; then
echo "sudo sudo bootstrap needed"
echo "$ID ALL = (ALL) NOPASSWD: /usr/sbin/sysctl" | sudo tee -a /etc/sudoers
echo
else
echo "no sudo bootstrap needed"
echo
fi
echo "Writing nsmb.conf"
echo
sudo rm -fv $NSMB_TMP
echo "[default]" | sudo tee -a $NSMB_TMP
echo "dir_cache_off=yes" | sudo tee -a $NSMB_TMP
echo "signing_required=no" | sudo tee -a $NSMB_TMP
sudo mv -fv $NSMB_TMP $NSMB
echo "Generating launchd plist from template"
echo
rm -fv com.samba_optimize.plist
cp -fv com.samba_optimize.plist_tpl com.samba_optimize.plist
sed -i '' -e "s/<PATHTOFILE>/${SCRIPTPATH//\//\\/}/g" com.samba_optimize.plist
mv -fv com.samba_optimize.plist ~/Library/LaunchAgents/
echo "Adding to launchd configuration"
launchctl load -w ~/Library/LaunchAgents/com.samba_optimize.plist
launchctl list | grep -i samba_optimize
echo "All set!"
}
run() {
echo "Setting desktop services network browsing detault"
echo
echo "Removing MacOS IO throttling"
sudo /usr/sbin/sysctl debug.lowpri\_throttle_enabled=0
}
remove() {
echo "Removing nsmb.conf file"
sudo rm -fv $NSMB
echo "Resetting default network folders browsing conf"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool FALSE
defaults read com.apple.desktopservices DSDontWriteNetworkStores
echo "Removing samba_optimize from auto start"
set +e
launchctl remove com.samba_optimize
set -e
rm -fv ~/Library/LaunchAgents/com.samba_optimize.plist
echo "Removing logs"
set +e
rm -fv $SCRIPTPATH/*.std*
set -e
echo "Removing sudoers record"
sudo sed -i '' "/^$ID.*\/usr\/sbin\/sysctl$/d" /etc/sudoers
echo "Resetting IO throttling back to enabled"
sudo /usr/sbin/sysctl debug.lowpri\_throttle_enabled=1
echo "Done"
}
main() {
echo \[`date`\] "Staring samba_optimize"
echo $SCRIPTPATH/$SELF
case "$1" in
"init" )
init;;
"remove" )
remove;;
"run" )
run;;
*)
echo "Usage: (init|remove|run)"
exit 2
;;
esac
}
main $1;