From b370727f0229a17732fbaf3acc2d41d927b693f4 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Mon, 26 Feb 2018 18:18:51 +0100
Subject: [PATCH] Better deploy and reset

---
 deploy.sh       | 27 ++++++++-------------------
 post-smb-config | 28 ++++++++++++++++++++++++++++
 reset.sh        | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 19 deletions(-)
 create mode 100644 post-smb-config
 create mode 100644 reset.sh

diff --git a/deploy.sh b/deploy.sh
index 1e055700..cd7d935d 100755
--- a/deploy.sh
+++ b/deploy.sh
@@ -1,8 +1,4 @@
 #!/bin/bash
-usage(){
-    echo "Usage $0 NbMaxconnections"
-    echo "Set the LCS maximum number of samba connection to NbMaxconnections"
-}
 
 # Copyright (C) 2018  Tetras Libre <Contact@Tetras-Libre.fr>
 # Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr>
@@ -23,23 +19,16 @@ usage(){
 if [[ ! "`hostname`" =~ "lcs" ]]
 then
     echo "This script should be run on the LCS"
-    usage
     exit 1
 fi
 
-if [ -z "$1" ]
+DIR=`dirname $0`
+
+if [ -f "/usr/local/sbin/post-smb-config" ] && \
+    [ ! -f "/usr/local/sbin/post-smb-config" ]
 then
-    usage
-    exit 1
+    cp /usr/local/sbin/post-smb-config /usr/local/sbin/post-smb-config.old
 fi
-
-DIR=`dirname $0`
-# Update lcs-smb-config then run it to force max connections to 1
-set -x
-awk "BEGIN{PRINT=1;FOUND=0} \
-    /^[\";]*$/{if(IN){IN=0;if(FOUND==0){print \"\tmax connections = $1\";FOUND=1}}} \
-    /^\[homes\]/{IN=1} /max connections/{if(IN){FOUND=1;PRINT=0; print \"\tmax connections = $1\"}} \
-    {if(PRINT){print \$0};PRINT=1}" \
-        /usr/share/lcs/sbin/lcs-smb-config > /usr/share/lcs/sbin/lcs-smb-config.new
-cp /usr/share/lcs/sbin/lcs-smb-config.new /usr/share/lcs/sbin/lcs-smb-config
-/usr/share/lcs/sbin/lcs-smb-config
+cp $DIR/post-smb-config /usr/local/sbin/post-smb-config
+/usr/local/sbin/post-smb-config
+service samba restart
diff --git a/post-smb-config b/post-smb-config
new file mode 100644
index 00000000..42dc2469
--- /dev/null
+++ b/post-smb-config
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Copyright (C) 2018  Tetras Libre <Contact@Tetras-Libre.fr>
+# Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+awk "BEGIN{PRINT=1;FOUND=0} \
+    /^$/{if(IN){IN=0;if(FOUND==0){print \"\tmax connections = 1\";FOUND=1}}} \
+    /^\[homes\]/{IN=1} /max connections/{if(IN){FOUND=1;PRINT=0; print \"\tmax connections = 1\"}} \
+    {if(PRINT){print \$0};PRINT=1}" \
+        /etc/samba/smb.conf > /etc/samba/smb.conf.new
+if [ ! -f "/etc/samba/smb.conf.old" ]
+then
+    cp /etc/samba/smb.conf /etc/samba/smb.conf.old
+fi
+mv /etc/samba/smb.conf.new /etc/samba/smb.conf
diff --git a/reset.sh b/reset.sh
new file mode 100644
index 00000000..f8643667
--- /dev/null
+++ b/reset.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# Copyright (C) 2018  Tetras Libre <Contact@Tetras-Libre.fr>
+# Author: Beniamine, David <David.Beniamine@Tetras-Libre.fr>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if [[ ! "`hostname`" =~ "lcs" ]]
+then
+    echo "This script should be run on the LCS"
+    exit 1
+fi
+
+DIR=`dirname $0`
+if [ -f "/usr/local/sbin/post-smb-config.old" ]
+then
+    cp /usr/local/sbin/post-smb-config.old /usr/local/sbin/post-smb-config
+else
+    rm /usr/local/sbin/post-smb-config
+fi
+awk "BEGIN{PRINT=1;FOUND=0} \
+    /^$/{if(IN){IN=0;if(FOUND==0){print \"\tmax connections = 30\";FOUND=1}}} \
+    /^\[homes\]/{IN=1} /max connections/{if(IN){FOUND=1;PRINT=0; print \"\tmax connections = 30\"}} \
+    {if(PRINT){print \$0};PRINT=1}" \
+        /etc/samba/smb.conf > /etc/samba/smb.conf.new
+if [ ! -f "/etc/samba/smb.conf.old" ]
+then
+    cp /etc/samba/smb.conf /etc/samba/smb.conf.old
+fi
+mv /etc/samba/smb.conf.new /etc/samba/smb.conf
+service samba restart
+
-- 
GitLab