From 07e165f27e00db9dbf3ee5e1617dc718e08a9c96 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Tue, 18 Sep 2018 09:14:50 +0200
Subject: [PATCH] Clean in a crontab

---
 postinstall_partage.sh       |  6 ++++++
 registry/scripts/clean.sh    | 28 ++++++++++++++++++++++++++++
 registry/scripts/registry.sh | 10 ++--------
 3 files changed, 36 insertions(+), 8 deletions(-)
 create mode 100755 registry/scripts/clean.sh

diff --git a/postinstall_partage.sh b/postinstall_partage.sh
index 7afa6c9..f2c4137 100755
--- a/postinstall_partage.sh
+++ b/postinstall_partage.sh
@@ -16,6 +16,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+DIR=$(dirname $0)
+
 cd /opt
 
 apt-get update
@@ -34,3 +36,7 @@ do
     systemctl enable $service
 done
 
+# Add registry clean to cronab
+
+line="0 1 1 * * $DIR/registry/scripts/clean.sh > /dev/null 2>&1"
+(crontab -l; echo "${line}") | crontab -
diff --git a/registry/scripts/clean.sh b/registry/scripts/clean.sh
new file mode 100755
index 0000000..a3993cd
--- /dev/null
+++ b/registry/scripts/clean.sh
@@ -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/>.
+
+conf_dir="/etc/registry"
+conf_file="$conf_dir/hosts"
+while read line
+do
+    if [ "$(echo $line | cut -d ' ' -f 1)" -gt "$(date -d '-6 month' +%Y%m%d)" ]
+    then
+        LINES="$LINES\n$(date +%Y%m%d) $(echo $line | cut -d ' ' -f 2-)"
+    fi
+done < $conf_file
+echo -e $LINES > $conf_file
diff --git a/registry/scripts/registry.sh b/registry/scripts/registry.sh
index 80c8fbf..95ac8bb 100755
--- a/registry/scripts/registry.sh
+++ b/registry/scripts/registry.sh
@@ -25,6 +25,7 @@ IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1)
 port=9998
 conf_dir="/etc/registry"
 conf_file="$conf_dir/hosts"
+DIR=$(dirname $0)
 
 if [ ! -d $conf_dir ]
 then
@@ -33,14 +34,7 @@ then
     ssh-keygen -P "" -f /root/.ssh/id_rsa
 else
     # Clean
-    while read line
-    do
-        if [ "$(echo $line | cut -d ' ' -f 1)" -gt "$(date -d '-6 month' +%Y%m%d)" ]
-        then
-            LINES="$LINES\n$(date +%Y%m%d) $(echo $line | cut -d ' ' -f 2-)"
-        fi
-    done < $conf_file
-    echo -e $LINES > $conf_file
+    $DIR/clean.sh
 fi
 
 while true
-- 
GitLab