From cbb93d35a6013c30896614dbd989b7d259b1d4fc Mon Sep 17 00:00:00 2001
From: Sebastien Luttringer <sebastien.luttringer@smartjog.com>
Date: Wed, 28 Dec 2011 16:04:14 +0100
Subject: [PATCH] add tools used on Smartjog builder and repository

---
 tools/clean-staging | 37 +++++++++++++++++++++++++++++++++++++
 tools/clean-testing | 34 ++++++++++++++++++++++++++++++++++
 tools/new-image     | 40 ++++++++++++++++++++++++++++++++++++++++
 tools/staging       | 29 +++++++++++++++++++++++++++++
 4 files changed, 140 insertions(+)
 create mode 100755 tools/clean-staging
 create mode 100755 tools/clean-testing
 create mode 100755 tools/new-image
 create mode 100755 tools/staging

diff --git a/tools/clean-staging b/tools/clean-staging
new file mode 100755
index 0000000..8b3b20c
--- /dev/null
+++ b/tools/clean-staging
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import os
+import json
+from subprocess import Popen, PIPE, check_call
+from installsystems.printer import arrow
+
+def get_image_list(repo):
+	p = Popen(['is', '--no-color', '--quiet', '--repo-search', '',
+		'list', '-j', '%s/*' % repo], stdout=PIPE)
+	stdout, stderr = p.communicate()
+	if p.returncode != 0:
+		exit('Unable to get %s list' % repo)
+	img = json.loads(stdout)
+	d = {}
+	for k,v in img.items():
+		d[v['md5']] = k
+	return d
+
+
+arrow('Getting staging images list')
+staging_imgs=get_image_list('staging')
+arrow('Getting stable images list')
+stable_imgs=get_image_list('stable')
+arrow('Getting testing images list')
+testing_imgs=get_image_list('testing')
+
+official=set(stable_imgs) | set(testing_imgs)
+to_remove=set(staging_imgs) & official
+
+arrow('Removing staging images in stable or testing')
+for md5 in to_remove:
+	name=staging_imgs[md5]
+	arrow('%s (%s)' % (name, md5), 1)
+	check_call(['is', 'del', '-f', name])
+
+# vim:set ts=2 sw=2 ft=python noet:
diff --git a/tools/clean-testing b/tools/clean-testing
new file mode 100755
index 0000000..046c8ed
--- /dev/null
+++ b/tools/clean-testing
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+import os
+import json
+from subprocess import Popen, PIPE, check_call
+from installsystems.printer import arrow
+
+def get_image_list(repo):
+	p = Popen(['is', '--no-color', '-q', 'list', '-j', '%s/*' % repo], stdout=PIPE)
+	stdout, stderr = p.communicate()
+	if p.returncode != 0:
+		exit('Unable to get %s list' % repo)
+	img = json.loads(stdout)
+	d = {}
+	for k,v in img.items():
+		d[v['md5']] = k
+	return d
+
+
+arrow('Getting stable images list')
+stable_imgs=get_image_list('stable')
+arrow('Getting testing images list')
+testing_imgs=get_image_list('testing')
+
+official=set(stable_imgs)
+to_remove=set(testing_imgs) & official
+
+arrow('Removing testing images in stable')
+for md5 in to_remove:
+	name=testing_imgs[md5]
+	arrow('%s (%s)' % (name, md5), 1)
+	check_call(['is', 'del', '-f', name])
+
+# vim:set ts=2 sw=2 ft=python noet:
diff --git a/tools/new-image b/tools/new-image
new file mode 100755
index 0000000..7cf0060
--- /dev/null
+++ b/tools/new-image
@@ -0,0 +1,40 @@
+#!/bin/bash
+# A seblu script
+
+usage() {
+  echo "usage: ${0##*/} image_name" >&2
+  exit 1
+}
+
+image_path='/root/images'
+image_name="$1"
+
+cd "$image_path"
+
+# check image already exists
+[[ -d "$image_name" ]] && echo "Image $image_name already exists" >&2 && exit 2
+
+# create image
+is new "$image_name"
+
+cd "$image_name"
+
+# customize description
+sed -ri "s/\s*name\s*=.*/name = $image_name/" description
+sed -ri "s/\s*version\s*=.*/version = 0/" description
+
+# create git
+git init
+
+# add gitignore
+cat > .gitignore << EOF
+*.isimage
+*.isdata
+payload
+EOF
+
+git add .gitignore
+git add description changelog
+git ci -m 'Initial commit'
+
+# vim:set ts=2 sw=2 ft=sh et:
diff --git a/tools/staging b/tools/staging
new file mode 100755
index 0000000..8797681
--- /dev/null
+++ b/tools/staging
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+usage() {
+	echo "usage: $0 [build_options]" >&2
+}
+
+repo=$(basename $0)
+(( $# > 0 )) && build_options=("$@") || build_options=('-f')
+
+[[ ! -r description ]] && echo 'Invalid source image' >&2 && usage && exit 2
+
+imgname=$(sed -rn  's/^[[:space:]]*name[[:space:]]*=[[:space:]]*([^[:space:]]+)[[:space:]]*/\1/p' description)
+imgver=$(sed -rn  's/^[[:space:]]*version[[:space:]]*=[[:space:]]*([^[:space:]]+)[[:space:]]*/\1/p' description)
+
+echo "Building image $imgname v$imgver and pushing it on repo $repo"
+
+# build new version
+is build "${build_options[@]}" || exit 1
+
+# is v5 doesn't return != 0 if ctrl+c is pressed, we check manually
+[[ -f "$imgname-$imgver.isimage" ]] || exit 1
+
+# delete old version
+is del -fp "$repo/$imgname:$imgver"
+
+# add new version
+is add "$repo" "$imgname-$imgver.isimage"
+
+# vim:set ts=2 sw=2 ft=sh noet:
-- 
GitLab