Revision 3179b447
/dev/null | ||
---|---|---|
1 |
Nikos Skalkotos <skalkoto@grnet.gr> |
|
2 |
Constantinos Venetsanopoulos <cven@grnet.gr> |
/dev/null | ||
---|---|---|
1 |
commondir=$(datarootdir)/$(PACKAGE) |
|
2 |
scriptsdir=$(libdir)/$(PACKAGE) |
|
3 |
tasksdir=$(scriptsdir)/tasks |
|
4 |
export commondir scriptsdir tasksdir |
|
5 |
|
|
6 |
SUBDIRS = tasks |
|
7 |
|
|
8 |
dist_doc_DATA = COPYING AUTHORS ChangeLog |
|
9 |
dist_bin_SCRIPTS = snf-image-helper |
|
10 |
dist_scripts_SCRIPTS= snf-passtohash.py |
|
11 |
dist_common_DATA = common.sh |
|
12 |
|
|
13 |
edit = sed \ |
|
14 |
-e 's|@commondir[@]|$(commondir)|g' \ |
|
15 |
-e 's|@scriptsdir[@]|$(scriptsdir)|g' \ |
|
16 |
-e 's|@tasksdir[@]|$(tasksdir)|g' \ |
|
17 |
-e 's|@RESIZE2FS[@]|$(RESIZE2FS)|g' \ |
|
18 |
-e 's|@XMLSTARLET[@]|$(XMLSTARLET)|g' |
|
19 |
|
|
20 |
%:%.in Makefile |
|
21 |
rm -f $@ $@.tmp |
|
22 |
srcdir=''; \ |
|
23 |
test -f ./$@.in || srcdir=$(srcdir)/; \ |
|
24 |
$(edit) $${srcdir}$@.in >$@.tmp |
|
25 |
mv $@.tmp $@ |
|
26 |
|
|
27 |
CLEANFILES = snf-image-helper |
/dev/null | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
|
|
3 |
if test ! -f configure.ac ; then |
|
4 |
echo "You must execute this script from the top level directory." |
|
5 |
exit 1 |
|
6 |
fi |
|
7 |
|
|
8 |
set -e |
|
9 |
|
|
10 |
rm -rf config.cache autom4te.cache |
|
11 |
mkdir -p autotools |
|
12 |
|
|
13 |
${ACLOCAL:-aclocal} -I autotools |
|
14 |
${AUTOCONF:-autoconf} |
|
15 |
${AUTOMAKE:-automake} --add-missing |
|
16 |
|
|
17 |
rm -rf autom4te.cache |
/dev/null | ||
---|---|---|
1 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or without |
|
4 |
# modification, are permitted provided that the following conditions |
|
5 |
# are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above copyright |
|
8 |
# notice, this list of conditions and the following disclaimer. |
|
9 |
# |
|
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
11 |
# notice, this list of conditions and the following disclaimer in the |
|
12 |
# documentation and/or other materials provided with the distribution. |
|
13 |
# |
|
14 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
15 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
16 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
17 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
18 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
19 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
20 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
21 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
22 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
23 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
24 |
# SUCH DAMAGE. |
|
25 |
# |
|
26 |
# The views and conclusions contained in the software and documentation are |
|
27 |
# those of the authors and should not be interpreted as representing official |
|
28 |
# policies, either expressed or implied, of GRNET S.A. |
|
29 |
|
|
30 |
RESULT=/dev/ttyS1 |
|
31 |
FLOPPY_DEV=/dev/fd0 |
|
32 |
|
|
33 |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin |
|
34 |
|
|
35 |
# Programs |
|
36 |
XMLSTARLET=xmlstarlet |
|
37 |
RESIZE2FS=resize2fs |
|
38 |
|
|
39 |
CLEANUP=( ) |
|
40 |
|
|
41 |
log_error() { |
|
42 |
echo "ERROR: $@" | tee $RESULT >&2 |
|
43 |
exit 1 |
|
44 |
} |
|
45 |
|
|
46 |
get_base_distro() { |
|
47 |
local root_dir=$1 |
|
48 |
|
|
49 |
if [ -e "$root_dir/etc/debian_version" ]; then |
|
50 |
echo "debian" |
|
51 |
elif [ -e "$root_dir/etc/redhat-release" ]; then |
|
52 |
echo "redhat" |
|
53 |
elif [ -e "$root_dir/etc/slackware-version" ]; then |
|
54 |
echo "slackware" |
|
55 |
elif [ -e "$root_dir/SuSE-release" ]; then |
|
56 |
echo "suse" |
|
57 |
elif [ -e "$root_dir/gentoo-release" ]; then |
|
58 |
echo "gentoo" |
|
59 |
fi |
|
60 |
} |
|
61 |
|
|
62 |
get_distro() { |
|
63 |
local root_dir=$1 |
|
64 |
|
|
65 |
if [ -e "$root_dir/etc/debian_version" ]; then |
|
66 |
distro="debian" |
|
67 |
if [ -e ${root_dir}/etc/lsb-release ]; then |
|
68 |
ID=$(grep $DISTRIB_ID=${root_dir}/etc/lsb-release | cut -d= -f2) |
|
69 |
if [ "x$ID" = "xUbuntu" ]; then |
|
70 |
distro="ubuntu" |
|
71 |
fi |
|
72 |
fi |
|
73 |
echo "$distro" |
|
74 |
elif [ -e "$root_dir/etc/fedora-release" ]; then |
|
75 |
echo "fedora" |
|
76 |
elif [ -e "$root_dir/etc/centos-release" ]; then |
|
77 |
echo "centos" |
|
78 |
elif [ -e "$root_dir/etc/redhat-release" ]; then |
|
79 |
echo "redhat" |
|
80 |
elif [ -e "$root_dir/etc/slackware-version" ]; then |
|
81 |
echo "slackware" |
|
82 |
elif [ -e "$root_dir/SuSE-release" ]; then |
|
83 |
echo "suse" |
|
84 |
elif [ -e "$root_dir/gentoo-release" ]; then |
|
85 |
echo "gentoo" |
|
86 |
fi |
|
87 |
} |
|
88 |
|
|
89 |
cleanup() { |
|
90 |
# if something fails here, it souldn't call cleanup again... |
|
91 |
trap - EXIT |
|
92 |
|
|
93 |
if [ ${#CLEANUP[*]} -gt 0 ]; then |
|
94 |
LAST_ELEMENT=$((${#CLEANUP[*]}-1)) |
|
95 |
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0) |
|
96 |
for i in $REVERSE_INDEXES; do |
|
97 |
# If something fails here, it's better to retry it for a few times |
|
98 |
# before we give up with an error. This is needed for kpartx when |
|
99 |
# dealing with ntfs partitions mounted through fuse. umount is not |
|
100 |
# synchronous and may return while the partition is still busy. A |
|
101 |
# premature attempt to delete partition mappings through kpartx on a |
|
102 |
# device that hosts previously mounted ntfs partition may fail with |
|
103 |
# an `device-mapper: remove ioctl failed: Device or resource busy' |
|
104 |
# error. A sensible workaround for this is to wait for a while and |
|
105 |
# then try again. |
|
106 |
local cmd=${CLEANUP[$i]} |
|
107 |
$cmd || for interval in 0.25 0.5 1 2 4; do |
|
108 |
echo "Command $cmd failed!" |
|
109 |
echo "I'll wait for $interval secs and will retry..." |
|
110 |
sleep $interval |
|
111 |
$cmd && break |
|
112 |
done |
|
113 |
test $? -eq 1 && { echo "Giving Up..."; exit 1; } |
|
114 |
done |
|
115 |
fi |
|
116 |
} |
|
117 |
|
|
118 |
trap cleanup EXIT |
|
119 |
|
|
120 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
AC_PREREQ(2.59) |
|
2 |
AC_INIT(snf-image-helper, 0.1, synnefo@lists.grnet.gr) |
|
3 |
|
|
4 |
AC_CONFIG_AUX_DIR(autotools) |
|
5 |
AC_CONFIG_SRCDIR(configure) |
|
6 |
|
|
7 |
AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability]) |
|
8 |
AM_INIT_AUTOMAKE([subdir-objects]) |
|
9 |
|
|
10 |
# Check common programs |
|
11 |
AC_PROG_INSTALL |
|
12 |
AC_PROG_LN_S |
|
13 |
AC_PROG_AWK |
|
14 |
AC_PROG_MKDIR_P |
|
15 |
|
|
16 |
AC_PATH_PROG(XMLSTARLET, [xmlstarlet], [], [$PATH:/usr/sbin:/sbin]) |
|
17 |
if test -z "$XMLSTARLET" ; then |
|
18 |
AC_MSG_ERROR([xmlstarlet not found in $PATH]) |
|
19 |
fi |
|
20 |
|
|
21 |
AC_PATH_PROG(RESIZE2FS, [resize2fs], [], [$PATH:/usr/sbin:/sbin]) |
|
22 |
if test -z "$RESIZE2FS" ; then |
|
23 |
AC_MSG_ERROR([resize2fs not found in $PATH]) |
|
24 |
fi |
|
25 |
|
|
26 |
AC_CONFIG_FILES([ |
|
27 |
Makefile |
|
28 |
tasks/Makefile |
|
29 |
]) |
|
30 |
AC_OUTPUT |
|
31 |
|
|
32 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
|
|
3 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
4 |
# |
|
5 |
# Redistribution and use in source and binary forms, with or without |
|
6 |
# modification, are permitted provided that the following conditions |
|
7 |
# are met: |
|
8 |
# |
|
9 |
# 1. Redistributions of source code must retain the above copyright |
|
10 |
# notice, this list of conditions and the following disclaimer. |
|
11 |
# |
|
12 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
13 |
# notice, this list of conditions and the following disclaimer in the |
|
14 |
# documentation and/or other materials provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
17 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
20 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
21 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
22 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
23 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
24 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
25 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
26 |
# SUCH DAMAGE. |
|
27 |
# |
|
28 |
# The views and conclusions contained in the software and documentation are |
|
29 |
# those of the authors and should not be interpreted as representing official |
|
30 |
# policies, either expressed or implied, of GRNET S.A. |
|
31 |
|
|
32 |
. @commondir@/common.sh |
|
33 |
|
|
34 |
set -e |
|
35 |
|
|
36 |
# terminate helper vm when the script exits |
|
37 |
CLEANUP+=("telinit 0") |
|
38 |
|
|
39 |
if [ ! -b $FLOPPY_DEV ]; then |
|
40 |
log_error "Floppy device is not present!" |
|
41 |
fi |
|
42 |
|
|
43 |
floppy=$(mktemp -d --tmpdir floppy.XXXXXXXX) |
|
44 |
CLEANUP+=("rmdir $floppy") |
|
45 |
|
|
46 |
mount $FLOPPY_DEV $floppy |
|
47 |
CLEANUP+=("umount $floppy") |
|
48 |
|
|
49 |
if [ -f $floppy/rules ]; then |
|
50 |
source $floppy/rules |
|
51 |
else |
|
52 |
log_error "Floppy does not contain \`rules\' file" |
|
53 |
fi |
|
54 |
|
|
55 |
# Image mount point... |
|
56 |
target=$(mktemp -d --tmpdir target.XXXXXXXX) |
|
57 |
CLEANUP+=("rmdir $target") |
|
58 |
|
|
59 |
export SNF_IMAGE_TARGET=$target |
|
60 |
|
|
61 |
if [ ! -d "/usr/lib/snf-image/tasks" ]; then |
|
62 |
log_error "snf-image/tasks directory is missing" |
|
63 |
fi |
|
64 |
|
|
65 |
RUN_PARTS=$(which run-parts) |
|
66 |
if [ -z "$RUN_PARTS" ]; then |
|
67 |
log_error "run-parts programe is missing from the system" |
|
68 |
fi |
|
69 |
|
|
70 |
echo "Execute all snf-image tasks...." |
|
71 |
$RUN_PARTS -v --exit-on-error "@tasksdir@" |
|
72 |
|
|
73 |
echo "SUCCESS" > $RESULT |
|
74 |
|
|
75 |
cleanup |
|
76 |
trap - EXIT |
|
77 |
|
|
78 |
# never called... |
|
79 |
exit 0 |
|
80 |
|
|
81 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
# |
|
3 |
# Copyright (c) 2011 Greek Research and Technology Network |
|
4 |
# |
|
5 |
"""Generate a Hash from a given Password |
|
6 |
|
|
7 |
This program takes a Password as an argument and |
|
8 |
returns to standard output a hash followed by a newline. |
|
9 |
To do this, it generates internally a random salt. |
|
10 |
|
|
11 |
""" |
|
12 |
|
|
13 |
import sys |
|
14 |
import crypt |
|
15 |
|
|
16 |
from string import ascii_letters, digits |
|
17 |
from random import choice |
|
18 |
from os.path import basename |
|
19 |
from optparse import OptionParser |
|
20 |
|
|
21 |
|
|
22 |
# This dictionary maps the hashing algorithm method |
|
23 |
# with its <ID> as documented in: |
|
24 |
# http://www.akkadia.org/drepper/SHA-crypt.txt |
|
25 |
HASH_ID_FROM_METHOD = { |
|
26 |
'md5': '1', |
|
27 |
'blowfish': '2a', |
|
28 |
'sun-md5': 'md5', |
|
29 |
'sha256': '5', |
|
30 |
'sha512': '6' |
|
31 |
} |
|
32 |
|
|
33 |
def random_salt(length=8): |
|
34 |
pool = ascii_letters + digits + "/" + "." |
|
35 |
return ''.join(choice(pool) for i in range(length)) |
|
36 |
|
|
37 |
|
|
38 |
def parse_arguments(input_args): |
|
39 |
usage = "usage: %prog [-h] [-m encrypt-method] <password>" |
|
40 |
parser = OptionParser(usage=usage) |
|
41 |
parser.add_option("-m", "--encrypt-method", |
|
42 |
dest="encrypt_method", |
|
43 |
type='choice', |
|
44 |
default="sha512", |
|
45 |
choices=HASH_ID_FROM_METHOD.keys(), |
|
46 |
help="encrypt password with ENCRYPT_METHOD [%default] \ |
|
47 |
(supported: " + ", ".join(HASH_ID_FROM_METHOD.keys()) +")", |
|
48 |
) |
|
49 |
|
|
50 |
(opts, args) = parser.parse_args(input_args) |
|
51 |
|
|
52 |
if len(args) != 1: |
|
53 |
parser.error('password is missing') |
|
54 |
|
|
55 |
return (args[0], opts.encrypt_method) |
|
56 |
|
|
57 |
|
|
58 |
def main(): |
|
59 |
(password, method) = parse_arguments(sys.argv[1:]) |
|
60 |
salt = random_salt() |
|
61 |
hash = crypt.crypt(password, "$"+HASH_ID_FROM_METHOD[method]+"$"+salt) |
|
62 |
sys.stdout.write("%s\n" % (hash)) |
|
63 |
return 0 |
|
64 |
|
|
65 |
if __name__ == "__main__": |
|
66 |
sys.exit(main()) |
|
67 |
|
|
68 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: ResizeUnmounted |
|
5 |
# RunBefore: MountImage |
|
6 |
# Short-Description: Resize filesystem to use all the available space |
|
7 |
### END TAST INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. @commondir@/common.sh |
|
11 |
|
|
12 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
13 |
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" |
|
14 |
|
|
15 |
fi |
|
16 |
if [ -z "$SNF_IMAGE_TYPE" ]; then |
|
17 |
log_error "Image type does not exist" |
|
18 |
fi |
|
19 |
|
|
20 |
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
21 |
$RESIZE2FS $SNF_IMAGE_DEV |
|
22 |
fi |
|
23 |
|
|
24 |
exit 0 |
|
25 |
|
|
26 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: MountImage |
|
5 |
# RunBefore: UmountImage |
|
6 |
# Short-Description: Mount the partition that hosts the image |
|
7 |
### END TAST INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. @commondir@/common.sh |
|
11 |
|
|
12 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
13 |
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing" |
|
14 |
fi |
|
15 |
|
|
16 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
17 |
log_error "Device file:\`$SNF_IMAGE_DEV' is not a block device" |
|
18 |
fi |
|
19 |
|
|
20 |
mount $SNF_IMAGE_DEV $SNF_IMAGE_TARGET |
|
21 |
|
|
22 |
exit 0 |
|
23 |
|
|
24 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: AddDeleteUnattendScript |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Script that removes Unattend.xml after setup has finished |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
|
18 |
# Make sure Unattend.xml is removed after setup has finished |
|
19 |
mkdir -p "$SNF_IMAGE_TARGET/Windows/Setup/Scripts" |
|
20 |
echo "del /Q /F C:\Unattend.xml" > "$SNF_IMAGE_TARGET/Windows/Setup/Scripts/SetupComplete.cmd" |
|
21 |
fi |
|
22 |
|
|
23 |
exit 0 |
|
24 |
|
|
25 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: DeleteSSHKeys |
|
5 |
# Requires: MountImage |
|
6 |
# Short-Description: Remove ssh keys if present. |
|
7 |
### END TAST INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. @commondir@/common.sh |
|
11 |
|
|
12 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
13 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing." |
|
14 |
fi |
|
15 |
|
|
16 |
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
17 |
HOST_KEY="/etc/ssh/ssh_host_key" |
|
18 |
RSA_KEY="/etc/ssh/ssh_host_rsa_key" |
|
19 |
DSA_KEY="/etc/ssh/ssh_host_dsa_key" |
|
20 |
|
|
21 |
for key in $HOST_KEY $RSA_KEY $DSA_KEY ; do |
|
22 |
if [ -f "${SNF_IMAGE_TARGET}/${key}" ] ; then |
|
23 |
rm -f ${SNF_IMAGE_TARGET}/${key}* |
|
24 |
fi |
|
25 |
done |
|
26 |
fi |
|
27 |
|
|
28 |
cleanup |
|
29 |
trap - EXIT |
|
30 |
|
|
31 |
exit 0 |
|
32 |
|
|
33 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: InstallUnattend |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Installs Unattend.xml for unattended windows setup |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
if [ -z "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ "$SNF_IMAGE_TYPE" != "ntfsdump" ]; then |
|
18 |
exit 0 |
|
19 |
fi |
|
20 |
|
|
21 |
if [ -e /usr/share/snf-image/unattend.xml ]; then |
|
22 |
cat /usr/share/snf-image/unattend.xml > $SNF_IMAGE_TARGET/Unattend.xml |
|
23 |
fi |
|
24 |
|
|
25 |
exit 0 |
|
26 |
|
|
27 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: ResizeMounted |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Resize filesystem to use all the available space |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target directory \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
|
18 |
# Write a diskpart script to %SystemDrive%\Windows\SnfScripts. Sysprep will |
|
19 |
# try to execute this script during the specialize pass. |
|
20 |
mkdir -p "$SNF_IMAGE_TARGET/Windows/SnfScripts" |
|
21 |
cat > "$SNF_IMAGE_TARGET/Windows/SnfScripts/ExtendFilesystem" <<EOF |
|
22 |
select disk 0 |
|
23 |
select volume 1 |
|
24 |
extend filesystem |
|
25 |
exit |
|
26 |
EOF |
|
27 |
fi |
|
28 |
|
|
29 |
cleanup |
|
30 |
trap - EXIT |
|
31 |
|
|
32 |
exit 0 |
|
33 |
|
|
34 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: SELinuxAutorelabel |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Force the system to relabel at next boot |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
18 |
distro=$(get_base_distro $SNF_IMAGE_TARGET) |
|
19 |
|
|
20 |
if [ "$distro" = "redhat" ]; then |
|
21 |
# we have to force a filesystem relabeling for SELinux after messing |
|
22 |
# around with the filesystem in redhat derived OSs |
|
23 |
echo "Enforce an automatic relabeling in the initial boot process..." |
|
24 |
touch $SNF_IMAGE_TARGET/.autorelabel |
|
25 |
fi |
|
26 |
fi |
|
27 |
|
|
28 |
exit 0 |
|
29 |
|
|
30 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: AssignHostname |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: InstallUnattend |
|
7 |
# Short-Description: Assign the Hostname of Computer Name in the instance |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
windows_hostname() { |
|
14 |
local target=$1 |
|
15 |
local password=$2 |
|
16 |
|
|
17 |
local tmp_unattend=`mktemp` || exit 1 |
|
18 |
CLEANUP+=("rm $tmp_unattend") |
|
19 |
|
|
20 |
echo -n "Assigning new computer name..." |
|
21 |
|
|
22 |
local namespace="urn:schemas-microsoft-com:unattend" |
|
23 |
|
|
24 |
$XMLSTARLET ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:ComputerName" -v $password "$target/Unattend.xml" > $tmp_unattend |
|
25 |
|
|
26 |
cat $tmp_unattend > "$target/Unattend.xml" |
|
27 |
echo done |
|
28 |
} |
|
29 |
|
|
30 |
linux_hostname() { |
|
31 |
local target=$1 |
|
32 |
local hostname=$2 |
|
33 |
|
|
34 |
local distro=$(get_base_distro $target) |
|
35 |
|
|
36 |
case "$distro" in |
|
37 |
debian) |
|
38 |
echo "$hostname" > $target/etc/hostname;; |
|
39 |
redhat) |
|
40 |
sed -ie "s/HOSTNAME=.*$/HOSTNAME=$hostname/g" $target/etc/sysconfig/network;; |
|
41 |
slackware|suse) |
|
42 |
#local domain=$(sed -e 's/^[^\.]*//g' < /etc/HOSTNAME) |
|
43 |
|
|
44 |
# In slackware hostname and domain name are joined together. For now I |
|
45 |
# will not retain the domain name. |
|
46 |
|
|
47 |
echo $hostname > ${target}/etc/HOSTNAME;; |
|
48 |
gentoo) |
|
49 |
sed -ie "s/\(\(HOSTNAME\)\|\(hostname\)\)=.*$/\1=\"$hostname\"/" $target/etc/conf.d/hostname;; |
|
50 |
esac |
|
51 |
|
|
52 |
# Some Linux distributions assign the hostname to 127.0.1.1 in order to be |
|
53 |
# resolvable to an IP address. Lets replace this if found in /etc/hosts |
|
54 |
sed -ie "s/^[[:blank:]]*127\.0\.1\.1[[:blank:]].\+$/127.0.1.1\t$hostname/" $target/etc/hosts |
|
55 |
} |
|
56 |
|
|
57 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
58 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
|
59 |
fi |
|
60 |
|
|
61 |
if [ -z "$SNF_IMAGE_HOSTNAME" ]; then |
|
62 |
log_error "Hostname is missing" |
|
63 |
fi |
|
64 |
|
|
65 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
|
66 |
windows_hostname $SNF_IMAGE_TARGET $SNF_IMAGE_HOSTNAME |
|
67 |
elif [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
68 |
linux_hostname $SNF_IMAGE_TARGET $SNF_IMAGE_HOSTNAME |
|
69 |
fi |
|
70 |
|
|
71 |
cleanup |
|
72 |
trap - EXIT |
|
73 |
|
|
74 |
exit 0 |
|
75 |
|
|
76 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
|
77 |
|
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: ChangePassword |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: InstallUnattend |
|
7 |
# Short-Description: Changes Password for specified users |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
windows_password() { |
|
14 |
local target=$1 |
|
15 |
local password=$2 |
|
16 |
|
|
17 |
local tmp_unattend=`mktemp` || exit 1 |
|
18 |
CLEANUP+=("rm $tmp_unattend") |
|
19 |
|
|
20 |
echo -n "Installing new admin password..." |
|
21 |
|
|
22 |
local namespace="urn:schemas-microsoft-com:unattend" |
|
23 |
|
|
24 |
$XMLSTARLET ed -N x=$namespace -u "/x:unattend/x:settings/x:component/x:UserAccounts/x:AdministratorPassword/x:Value" -v $password "$target/Unattend.xml" > $tmp_unattend |
|
25 |
|
|
26 |
cat $tmp_unattend > "$target/Unattend.xml" |
|
27 |
echo done |
|
28 |
} |
|
29 |
|
|
30 |
linux_password() { |
|
31 |
local target=$1 |
|
32 |
local password=$2 |
|
33 |
|
|
34 |
local hash=$(@commondir@/snf-passtohash.py $password) |
|
35 |
if [ ! -e ${target}/etc/shadow ]; then |
|
36 |
log_error "No /etc/shadow found!" |
|
37 |
fi |
|
38 |
|
|
39 |
declare -a users=("root") |
|
40 |
|
|
41 |
local distro=$(get_distro $target) |
|
42 |
|
|
43 |
if [ "x$disto" = "xubuntu" -o \ |
|
44 |
"x$disto" = "xfedora" ] ; then |
|
45 |
users+=("user") |
|
46 |
fi |
|
47 |
|
|
48 |
for i in $(seq 0 1 $((${#users[@]}-1))); do |
|
49 |
local tmp_shadow=$(mktemp) |
|
50 |
CLEANUP+=("rm $tmp_shadow") |
|
51 |
|
|
52 |
echo -n "Setting ${users[$i]} password..." |
|
53 |
|
|
54 |
echo "${users[$i]}:$hash:15103:0:99999:7:::" > $tmp_shadow |
|
55 |
grep -v "${users[$i]}" ${TARGET}/etc/shadow >> $tmp_shadow |
|
56 |
cat $tmp_shadow > ${target}/etc/shadow |
|
57 |
echo "done" |
|
58 |
done |
|
59 |
} |
|
60 |
|
|
61 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
62 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
|
63 |
fi |
|
64 |
|
|
65 |
if [ -z "$SNF_IMAGE_PASSWORD" ]; then |
|
66 |
log_error "Password is missing" |
|
67 |
fi |
|
68 |
|
|
69 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
|
70 |
windows_password $SNF_IMAGE_TARGET $SNF_IMAGE_PASSWORD |
|
71 |
elif [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
72 |
linux_password $SNF_IMAGE_TARGET $SNF_IMAGE_PASSWORD |
|
73 |
fi |
|
74 |
|
|
75 |
echo "done" |
|
76 |
|
|
77 |
cleanup |
|
78 |
trap - EXIT |
|
79 |
|
|
80 |
exit 0 |
|
81 |
|
|
82 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
|
83 |
|
/dev/null | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
# |
|
3 |
# Copyright (c) 2011 Greek Research and Technology Network |
|
4 |
# |
|
5 |
"""Personalize an Image by injecting files |
|
6 |
|
|
7 |
This hook injects files into the filesystem of an Image. |
|
8 |
The files are passed to the hook through the Ganeti |
|
9 |
OS interface and found in the variable OSP_IMG_PERSONALITY. |
|
10 |
|
|
11 |
""" |
|
12 |
|
|
13 |
import sys |
|
14 |
import os |
|
15 |
import json |
|
16 |
import datetime |
|
17 |
import base64 |
|
18 |
|
|
19 |
|
|
20 |
def timestamp(): |
|
21 |
now = datetime.datetime.now() |
|
22 |
current_time = now.strftime("%Y%m%d.%H%M%S") |
|
23 |
return current_time |
|
24 |
|
|
25 |
|
|
26 |
def main(): |
|
27 |
if os.environ.has_key('SNF_IMAGE_PERSONALITY'): |
|
28 |
osp_img_personality = os.environ['SNF_IMAGE_PERSONALITY'] |
|
29 |
files = json.loads(osp_img_personality) |
|
30 |
for f in files: |
|
31 |
if os.path.lexists(f['path']): |
|
32 |
backup_file = f['path'] + '.bak.' + timestamp() |
|
33 |
os.rename(f['path'],backup_file) |
|
34 |
file = file(f['path'], 'w') |
|
35 |
file.write(base64.b64decode(f['contents'])) |
|
36 |
file.close() |
|
37 |
os.chmod(f['path'],0440) |
|
38 |
sys.stderr.write('Successful personalization of Image') |
|
39 |
else: |
|
40 |
sys.stderr.write('This Image has no personality (0 files to inject)') |
|
41 |
return 0 |
|
42 |
|
|
43 |
|
|
44 |
if __name__ == "__main__": |
|
45 |
sys.exit(main()) |
|
46 |
|
|
47 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: UmountImage |
|
5 |
# RunBefore: |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Umount the partition that hosts the image |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
umount $SNF_IMAGE_TARGET |
|
18 |
|
|
19 |
cleanup |
|
20 |
trap - EXIT |
|
21 |
|
|
22 |
exit 0 |
|
23 |
|
|
24 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
|
25 |
|
/dev/null | ||
---|---|---|
1 |
tasksdir=$(libdir)/$(PACKAGE)/tasks |
|
2 |
|
|
3 |
dist_tasks_SCRIPTS = \ |
|
4 |
10ResizeUnmounted \ |
|
5 |
30MountImage \ |
|
6 |
40AddDeleteUnattendScript \ |
|
7 |
40DeleteSSHKeys \ |
|
8 |
40InstallUnattend \ |
|
9 |
40ResizeMounted \ |
|
10 |
40SELinuxAutorelabel \ |
|
11 |
50AssignHostname \ |
|
12 |
50ChangePassword \ |
|
13 |
80UmountImage |
|
14 |
|
|
15 |
edit = sed \ |
|
16 |
-e 's|@sysconfdir[@]|$(sysconfdir)|g' \ |
|
17 |
-e 's|@localstatedir[@]|$(localstatedir)|g' \ |
|
18 |
-e 's|@datarootdir[@]|$(datarootdir)|g' \ |
|
19 |
-e 's|@commondir[@]|$(commondir)|g' |
|
20 |
|
|
21 |
%:%.in Makefile |
|
22 |
rm -f $@ $@.tmp |
|
23 |
srcdir=''; \ |
|
24 |
test -f ./$@.in || srcdir=$(srcdir)/; \ |
|
25 |
$(edit) $${srcdir}$@.in >$@.tmp |
|
26 |
mv $@.tmp $@ |
|
27 |
|
|
28 |
CLEANFILES = $(dist_tasks_SCRIPTS) |
b/snf-image-helper/AUTHORS | ||
---|---|---|
1 |
Nikos Skalkotos <skalkoto@grnet.gr> |
|
2 |
Constantinos Venetsanopoulos <cven@grnet.gr> |
b/snf-image-helper/COPYING | ||
---|---|---|
1 |
Copyright 2011 GRNET S.A. All rights reserved. |
|
2 |
|
|
3 |
Redistribution and use in source and binary forms, with or |
|
4 |
without modification, are permitted provided that the following |
|
5 |
conditions are met: |
|
6 |
|
|
7 |
1. Redistributions of source code must retain the above |
|
8 |
copyright notice, this list of conditions and the following |
|
9 |
disclaimer. |
|
10 |
|
|
11 |
2. Redistributions in binary form must reproduce the above |
|
12 |
copyright notice, this list of conditions and the following |
|
13 |
disclaimer in the documentation and/or other materials |
|
14 |
provided with the distribution. |
|
15 |
|
|
16 |
THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
POSSIBILITY OF SUCH DAMAGE. |
|
28 |
|
|
29 |
The views and conclusions contained in the software and |
|
30 |
documentation are those of the authors and should not be |
|
31 |
interpreted as representing official policies, either expressed |
|
32 |
or implied, of GRNET S.A. |
b/snf-image-helper/ChangeLog | ||
---|---|---|
1 |
2011-10-04 Nikos Skalkotos <skalkoto@grnet.gr> |
|
2 |
* Initial release v0.1 |
b/snf-image-helper/Makefile.am | ||
---|---|---|
1 |
commondir=$(datarootdir)/$(PACKAGE) |
|
2 |
scriptsdir=$(libdir)/$(PACKAGE) |
|
3 |
tasksdir=$(scriptsdir)/tasks |
|
4 |
export commondir scriptsdir tasksdir |
|
5 |
|
|
6 |
SUBDIRS = tasks |
|
7 |
|
|
8 |
dist_doc_DATA = COPYING AUTHORS ChangeLog |
|
9 |
dist_bin_SCRIPTS = snf-image-helper |
|
10 |
dist_scripts_SCRIPTS= snf-passtohash.py |
|
11 |
dist_common_DATA = common.sh |
|
12 |
|
|
13 |
edit = sed \ |
|
14 |
-e 's|@commondir[@]|$(commondir)|g' \ |
|
15 |
-e 's|@scriptsdir[@]|$(scriptsdir)|g' \ |
|
16 |
-e 's|@tasksdir[@]|$(tasksdir)|g' \ |
|
17 |
-e 's|@RESIZE2FS[@]|$(RESIZE2FS)|g' \ |
|
18 |
-e 's|@XMLSTARLET[@]|$(XMLSTARLET)|g' |
|
19 |
|
|
20 |
%:%.in Makefile |
|
21 |
rm -f $@ $@.tmp |
|
22 |
srcdir=''; \ |
|
23 |
test -f ./$@.in || srcdir=$(srcdir)/; \ |
|
24 |
$(edit) $${srcdir}$@.in >$@.tmp |
|
25 |
mv $@.tmp $@ |
|
26 |
|
|
27 |
CLEANFILES = snf-image-helper |
b/snf-image-helper/autogen.sh | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
|
|
3 |
if test ! -f configure.ac ; then |
|
4 |
echo "You must execute this script from the top level directory." |
|
5 |
exit 1 |
|
6 |
fi |
|
7 |
|
|
8 |
set -e |
|
9 |
|
|
10 |
rm -rf config.cache autom4te.cache |
|
11 |
mkdir -p autotools |
|
12 |
|
|
13 |
${ACLOCAL:-aclocal} -I autotools |
|
14 |
${AUTOCONF:-autoconf} |
|
15 |
${AUTOMAKE:-automake} --add-missing |
|
16 |
|
|
17 |
rm -rf autom4te.cache |
b/snf-image-helper/common.sh | ||
---|---|---|
1 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or without |
|
4 |
# modification, are permitted provided that the following conditions |
|
5 |
# are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above copyright |
|
8 |
# notice, this list of conditions and the following disclaimer. |
|
9 |
# |
|
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
11 |
# notice, this list of conditions and the following disclaimer in the |
|
12 |
# documentation and/or other materials provided with the distribution. |
|
13 |
# |
|
14 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
15 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
16 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
17 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
18 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
19 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
20 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
21 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
22 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
23 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
24 |
# SUCH DAMAGE. |
|
25 |
# |
|
26 |
# The views and conclusions contained in the software and documentation are |
|
27 |
# those of the authors and should not be interpreted as representing official |
|
28 |
# policies, either expressed or implied, of GRNET S.A. |
|
29 |
|
|
30 |
RESULT=/dev/ttyS1 |
|
31 |
FLOPPY_DEV=/dev/fd0 |
|
32 |
|
|
33 |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin |
|
34 |
|
|
35 |
# Programs |
|
36 |
XMLSTARLET=xmlstarlet |
|
37 |
RESIZE2FS=resize2fs |
|
38 |
|
|
39 |
CLEANUP=( ) |
|
40 |
|
|
41 |
log_error() { |
|
42 |
echo "ERROR: $@" | tee $RESULT >&2 |
|
43 |
exit 1 |
|
44 |
} |
|
45 |
|
|
46 |
get_base_distro() { |
|
47 |
local root_dir=$1 |
|
48 |
|
|
49 |
if [ -e "$root_dir/etc/debian_version" ]; then |
|
50 |
echo "debian" |
|
51 |
elif [ -e "$root_dir/etc/redhat-release" ]; then |
|
52 |
echo "redhat" |
|
53 |
elif [ -e "$root_dir/etc/slackware-version" ]; then |
|
54 |
echo "slackware" |
|
55 |
elif [ -e "$root_dir/SuSE-release" ]; then |
|
56 |
echo "suse" |
|
57 |
elif [ -e "$root_dir/gentoo-release" ]; then |
|
58 |
echo "gentoo" |
|
59 |
fi |
|
60 |
} |
|
61 |
|
|
62 |
get_distro() { |
|
63 |
local root_dir=$1 |
|
64 |
|
|
65 |
if [ -e "$root_dir/etc/debian_version" ]; then |
|
66 |
distro="debian" |
|
67 |
if [ -e ${root_dir}/etc/lsb-release ]; then |
|
68 |
ID=$(grep $DISTRIB_ID=${root_dir}/etc/lsb-release | cut -d= -f2) |
|
69 |
if [ "x$ID" = "xUbuntu" ]; then |
|
70 |
distro="ubuntu" |
|
71 |
fi |
|
72 |
fi |
|
73 |
echo "$distro" |
|
74 |
elif [ -e "$root_dir/etc/fedora-release" ]; then |
|
75 |
echo "fedora" |
|
76 |
elif [ -e "$root_dir/etc/centos-release" ]; then |
|
77 |
echo "centos" |
|
78 |
elif [ -e "$root_dir/etc/redhat-release" ]; then |
|
79 |
echo "redhat" |
|
80 |
elif [ -e "$root_dir/etc/slackware-version" ]; then |
|
81 |
echo "slackware" |
|
82 |
elif [ -e "$root_dir/SuSE-release" ]; then |
|
83 |
echo "suse" |
|
84 |
elif [ -e "$root_dir/gentoo-release" ]; then |
|
85 |
echo "gentoo" |
|
86 |
fi |
|
87 |
} |
|
88 |
|
|
89 |
cleanup() { |
|
90 |
# if something fails here, it souldn't call cleanup again... |
|
91 |
trap - EXIT |
|
92 |
|
|
93 |
if [ ${#CLEANUP[*]} -gt 0 ]; then |
|
94 |
LAST_ELEMENT=$((${#CLEANUP[*]}-1)) |
|
95 |
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0) |
|
96 |
for i in $REVERSE_INDEXES; do |
|
97 |
# If something fails here, it's better to retry it for a few times |
|
98 |
# before we give up with an error. This is needed for kpartx when |
|
99 |
# dealing with ntfs partitions mounted through fuse. umount is not |
|
100 |
# synchronous and may return while the partition is still busy. A |
|
101 |
# premature attempt to delete partition mappings through kpartx on a |
|
102 |
# device that hosts previously mounted ntfs partition may fail with |
|
103 |
# an `device-mapper: remove ioctl failed: Device or resource busy' |
|
104 |
# error. A sensible workaround for this is to wait for a while and |
|
105 |
# then try again. |
|
106 |
local cmd=${CLEANUP[$i]} |
|
107 |
$cmd || for interval in 0.25 0.5 1 2 4; do |
|
108 |
echo "Command $cmd failed!" |
|
109 |
echo "I'll wait for $interval secs and will retry..." |
|
110 |
sleep $interval |
|
111 |
$cmd && break |
|
112 |
done |
|
113 |
test $? -eq 1 && { echo "Giving Up..."; exit 1; } |
|
114 |
done |
|
115 |
fi |
|
116 |
} |
|
117 |
|
|
118 |
trap cleanup EXIT |
|
119 |
|
|
120 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/configure.ac | ||
---|---|---|
1 |
AC_PREREQ(2.59) |
|
2 |
AC_INIT(snf-image-helper, 0.1, synnefo@lists.grnet.gr) |
|
3 |
|
|
4 |
AC_CONFIG_AUX_DIR(autotools) |
|
5 |
AC_CONFIG_SRCDIR(configure) |
|
6 |
|
|
7 |
AM_INIT_AUTOMAKE([1.9 foreign tar-ustar -Wall -Wno-portability]) |
|
8 |
AM_INIT_AUTOMAKE([subdir-objects]) |
|
9 |
|
|
10 |
# Check common programs |
|
11 |
AC_PROG_INSTALL |
|
12 |
AC_PROG_LN_S |
|
13 |
AC_PROG_AWK |
|
14 |
AC_PROG_MKDIR_P |
|
15 |
|
|
16 |
AC_PATH_PROG(XMLSTARLET, [xmlstarlet], [], [$PATH:/usr/sbin:/sbin]) |
|
17 |
if test -z "$XMLSTARLET" ; then |
|
18 |
AC_MSG_ERROR([xmlstarlet not found in $PATH]) |
|
19 |
fi |
|
20 |
|
|
21 |
AC_PATH_PROG(RESIZE2FS, [resize2fs], [], [$PATH:/usr/sbin:/sbin]) |
|
22 |
if test -z "$RESIZE2FS" ; then |
|
23 |
AC_MSG_ERROR([resize2fs not found in $PATH]) |
|
24 |
fi |
|
25 |
|
|
26 |
AC_CONFIG_FILES([ |
|
27 |
Makefile |
|
28 |
tasks/Makefile |
|
29 |
]) |
|
30 |
AC_OUTPUT |
|
31 |
|
|
32 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/snf-image-helper.in | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
|
|
3 |
# Copyright 2011 GRNET S.A. All rights reserved. |
|
4 |
# |
|
5 |
# Redistribution and use in source and binary forms, with or without |
|
6 |
# modification, are permitted provided that the following conditions |
|
7 |
# are met: |
|
8 |
# |
|
9 |
# 1. Redistributions of source code must retain the above copyright |
|
10 |
# notice, this list of conditions and the following disclaimer. |
|
11 |
# |
|
12 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
13 |
# notice, this list of conditions and the following disclaimer in the |
|
14 |
# documentation and/or other materials provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|
17 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
18 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
19 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|
20 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
21 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
22 |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
23 |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
24 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
25 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
26 |
# SUCH DAMAGE. |
|
27 |
# |
|
28 |
# The views and conclusions contained in the software and documentation are |
|
29 |
# those of the authors and should not be interpreted as representing official |
|
30 |
# policies, either expressed or implied, of GRNET S.A. |
|
31 |
|
|
32 |
. @commondir@/common.sh |
|
33 |
|
|
34 |
set -e |
|
35 |
|
|
36 |
# terminate helper vm when the script exits |
|
37 |
CLEANUP+=("telinit 0") |
|
38 |
|
|
39 |
if [ ! -b $FLOPPY_DEV ]; then |
|
40 |
log_error "Floppy device is not present!" |
|
41 |
fi |
|
42 |
|
|
43 |
floppy=$(mktemp -d --tmpdir floppy.XXXXXXXX) |
|
44 |
CLEANUP+=("rmdir $floppy") |
|
45 |
|
|
46 |
mount $FLOPPY_DEV $floppy |
|
47 |
CLEANUP+=("umount $floppy") |
|
48 |
|
|
49 |
if [ -f $floppy/rules ]; then |
|
50 |
source $floppy/rules |
|
51 |
else |
|
52 |
log_error "Floppy does not contain \`rules\' file" |
|
53 |
fi |
|
54 |
|
|
55 |
# Image mount point... |
|
56 |
target=$(mktemp -d --tmpdir target.XXXXXXXX) |
|
57 |
CLEANUP+=("rmdir $target") |
|
58 |
|
|
59 |
export SNF_IMAGE_TARGET=$target |
|
60 |
|
|
61 |
if [ ! -d "/usr/lib/snf-image/tasks" ]; then |
|
62 |
log_error "snf-image/tasks directory is missing" |
|
63 |
fi |
|
64 |
|
|
65 |
RUN_PARTS=$(which run-parts) |
|
66 |
if [ -z "$RUN_PARTS" ]; then |
|
67 |
log_error "run-parts programe is missing from the system" |
|
68 |
fi |
|
69 |
|
|
70 |
echo "Execute all snf-image tasks...." |
|
71 |
$RUN_PARTS -v --exit-on-error "@tasksdir@" |
|
72 |
|
|
73 |
echo "SUCCESS" > $RESULT |
|
74 |
|
|
75 |
cleanup |
|
76 |
trap - EXIT |
|
77 |
|
|
78 |
# never called... |
|
79 |
exit 0 |
|
80 |
|
|
81 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/snf-passtohash.py | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
# |
|
3 |
# Copyright (c) 2011 Greek Research and Technology Network |
|
4 |
# |
|
5 |
"""Generate a Hash from a given Password |
|
6 |
|
|
7 |
This program takes a Password as an argument and |
|
8 |
returns to standard output a hash followed by a newline. |
|
9 |
To do this, it generates internally a random salt. |
|
10 |
|
|
11 |
""" |
|
12 |
|
|
13 |
import sys |
|
14 |
import crypt |
|
15 |
|
|
16 |
from string import ascii_letters, digits |
|
17 |
from random import choice |
|
18 |
from os.path import basename |
|
19 |
from optparse import OptionParser |
|
20 |
|
|
21 |
|
|
22 |
# This dictionary maps the hashing algorithm method |
|
23 |
# with its <ID> as documented in: |
|
24 |
# http://www.akkadia.org/drepper/SHA-crypt.txt |
|
25 |
HASH_ID_FROM_METHOD = { |
|
26 |
'md5': '1', |
|
27 |
'blowfish': '2a', |
|
28 |
'sun-md5': 'md5', |
|
29 |
'sha256': '5', |
|
30 |
'sha512': '6' |
|
31 |
} |
|
32 |
|
|
33 |
def random_salt(length=8): |
|
34 |
pool = ascii_letters + digits + "/" + "." |
|
35 |
return ''.join(choice(pool) for i in range(length)) |
|
36 |
|
|
37 |
|
|
38 |
def parse_arguments(input_args): |
|
39 |
usage = "usage: %prog [-h] [-m encrypt-method] <password>" |
|
40 |
parser = OptionParser(usage=usage) |
|
41 |
parser.add_option("-m", "--encrypt-method", |
|
42 |
dest="encrypt_method", |
|
43 |
type='choice', |
|
44 |
default="sha512", |
|
45 |
choices=HASH_ID_FROM_METHOD.keys(), |
|
46 |
help="encrypt password with ENCRYPT_METHOD [%default] \ |
|
47 |
(supported: " + ", ".join(HASH_ID_FROM_METHOD.keys()) +")", |
|
48 |
) |
|
49 |
|
|
50 |
(opts, args) = parser.parse_args(input_args) |
|
51 |
|
|
52 |
if len(args) != 1: |
|
53 |
parser.error('password is missing') |
|
54 |
|
|
55 |
return (args[0], opts.encrypt_method) |
|
56 |
|
|
57 |
|
|
58 |
def main(): |
|
59 |
(password, method) = parse_arguments(sys.argv[1:]) |
|
60 |
salt = random_salt() |
|
61 |
hash = crypt.crypt(password, "$"+HASH_ID_FROM_METHOD[method]+"$"+salt) |
|
62 |
sys.stdout.write("%s\n" % (hash)) |
|
63 |
return 0 |
|
64 |
|
|
65 |
if __name__ == "__main__": |
|
66 |
sys.exit(main()) |
|
67 |
|
|
68 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/tasks/10ResizeUnmounted.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: ResizeUnmounted |
|
5 |
# RunBefore: MountImage |
|
6 |
# Short-Description: Resize filesystem to use all the available space |
|
7 |
### END TAST INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. @commondir@/common.sh |
|
11 |
|
|
12 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
13 |
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" |
|
14 |
|
|
15 |
fi |
|
16 |
if [ -z "$SNF_IMAGE_TYPE" ]; then |
|
17 |
log_error "Image type does not exist" |
|
18 |
fi |
|
19 |
|
|
20 |
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
21 |
$RESIZE2FS $SNF_IMAGE_DEV |
|
22 |
fi |
|
23 |
|
|
24 |
exit 0 |
|
25 |
|
|
26 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/tasks/30MountImage.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: MountImage |
|
5 |
# RunBefore: UmountImage |
|
6 |
# Short-Description: Mount the partition that hosts the image |
|
7 |
### END TAST INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. @commondir@/common.sh |
|
11 |
|
|
12 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
13 |
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing" |
|
14 |
fi |
|
15 |
|
|
16 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
17 |
log_error "Device file:\`$SNF_IMAGE_DEV' is not a block device" |
|
18 |
fi |
|
19 |
|
|
20 |
mount $SNF_IMAGE_DEV $SNF_IMAGE_TARGET |
|
21 |
|
|
22 |
exit 0 |
|
23 |
|
|
24 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/tasks/40AddDeleteUnattendScript.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: AddDeleteUnattendScript |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Script that removes Unattend.xml after setup has finished |
|
8 |
### END TAST INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. @commondir@/common.sh |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
|
18 |
# Make sure Unattend.xml is removed after setup has finished |
|
19 |
mkdir -p "$SNF_IMAGE_TARGET/Windows/Setup/Scripts" |
|
20 |
echo "del /Q /F C:\Unattend.xml" > "$SNF_IMAGE_TARGET/Windows/Setup/Scripts/SetupComplete.cmd" |
|
21 |
fi |
|
22 |
|
|
23 |
exit 0 |
|
24 |
|
|
25 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/tasks/40DeleteSSHKeys.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: DeleteSSHKeys |
|
5 |
# Requires: MountImage |
|
6 |
# Short-Description: Remove ssh keys if present. |
|
7 |
### END TAST INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. @commondir@/common.sh |
|
11 |
|
|
12 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
13 |
log_error "Target dir: \`$SNF_IMAGE_TARGET' is missing." |
|
14 |
fi |
|
15 |
|
|
16 |
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
17 |
HOST_KEY="/etc/ssh/ssh_host_key" |
|
18 |
RSA_KEY="/etc/ssh/ssh_host_rsa_key" |
|
19 |
DSA_KEY="/etc/ssh/ssh_host_dsa_key" |
|
20 |
|
|
21 |
for key in $HOST_KEY $RSA_KEY $DSA_KEY ; do |
|
22 |
if [ -f "${SNF_IMAGE_TARGET}/${key}" ] ; then |
|
23 |
rm -f ${SNF_IMAGE_TARGET}/${key}* |
|
24 |
fi |
|
25 |
done |
|
26 |
fi |
|
27 |
|
|
28 |
cleanup |
|
29 |
trap - EXIT |
|
30 |
|
|
31 |
exit 0 |
|
32 |
|
|
33 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
Also available in: Unified diff