Added directory purge tool
authorOlev Kartau <olev.kartau@intel.com>
Thu, 12 Feb 2015 14:43:08 +0000 (16:43 +0200)
committerOlev Kartau <olev.kartau@intel.com>
Thu, 12 Feb 2015 18:44:56 +0000 (20:44 +0200)
This shell script scans Tizen release directories, removes
entries old enough based on policy given by env.variables

Change-Id: I6ee22c578748d2f9ec1d93c5cdb4e119f978d812

dir-purge-tool.sh [new file with mode: 0755]
packaging/jenkins-scripts.spec

diff --git a/dir-purge-tool.sh b/dir-purge-tool.sh
new file mode 100755 (executable)
index 0000000..1e2e4e0
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Delete Tizen older directories based on policy
+#
+
+remove_old() {
+path=$1
+maxage=$(($2 * 86400))
+dirlist=`find $path -type d -regextype posix-awk -regex $PURGE_PATTERN`
+now=`date +"%s"`
+for dir in $dirlist; do
+  dirn=`dirname $dir`
+  basen=`basename $dir`
+  latest=$dirn/latest
+  if [ -L $latest ]; then
+    link=`readlink $latest`
+    [ $basen = ${link%/} ] && continue
+  fi
+  tsext="${dir##$path*/tizen*_}"
+  timestamp="${tsext%%.*}"
+  reltime=`date --date=$timestamp +"%s"`
+  if [ $((now - reltime)) -gt $maxage ]; then
+    echo "# Remove $dir"
+    [ $PURGE_DRY_RUN -eq "0" ] && rm -fr $dir
+  fi
+done
+}
+
+[ $PURGE_DRY_RUN != 0 ] && echo "Dry run, nothing will be deleted"
+
+read -a paths <<< $PURGE_PATHS
+read -a ages <<< $PURGE_AGES
+for ((i=0;i<${#paths[@]};i++)); do
+  remove_old ${paths[$i]} ${ages[$i]}
+done
index db185a4..961de38 100644 (file)
@@ -66,7 +66,7 @@ Isolated job_submitobs to avoid package installation conflicts
 
 %install
 install -d %{buildroot}%{destdir}
-cp -r job_*.py common obs_requests templates %{buildroot}%{destdir}/
+cp -r job_*.py dir-purge-tool.sh common obs_requests templates %{buildroot}%{destdir}/
 
 %post common
 if [ ! -d /var/lib/jenkins/userContent ]; then
@@ -133,6 +133,7 @@ fi
 %{destdir}/templates/index.html
 %{destdir}/job_update_local_git.py
 %{destdir}/job_monitor_scm_meta_git.py
+%{destdir}/dir-purge-tool.sh
 
 %files tzs
 %defattr(-,jenkins,jenkins)