summaryrefslogtreecommitdiffstats
path: root/tools/installer
blob: 92ece80d75f76b212bfa4983da23630a356fbf13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/bin/bash

. tools/inc/colors

DISTRO=$(lsb_release -i| sed 's/^[^:]*:\t//' | tr '[:upper:]' '[:lower:]')

[ -z $USR_BIN_PATH ]       && USR_BIN_PATH=/usr/bin
[ -z $SLX_CONFIG_PATH ]    && SLX_CONFIG_PATH=/etc/opt/openslx
[ -z $SLX_BASE_PATH ]      && SLX_BASE_PATH=/opt/openslx
[ -z $SLX_PRIVATE_PATH ]   && SLX_PRIVATE_PATH=/var/opt/openslx
[ -z $SLX_PUBLIC_PATH ]    && SLX_PUBLIC_PATH=/srv/openslx
[ -z $SLX_TEMP_PATH ]      && SLX_TEMP_PATH=/tmp
[ -z $SLX_INSTALL_LOG ]    && SLX_INSTALL_LOG=install.log

PREPARE_INSTALL_TARGET="./_install/"

# helper functions:
git_version()
{
    GITVERSION=`git describe`
    GITMODIFIED=`(git status | grep "modified:\|added:\|deleted:" -q) && echo "-M"`
    echo $GITVERSION$GITMODIFIED
}

check_perl()
{
	echo -n " * checking perl"
    if ! perl -e '$x=42' 2>>${SLX_INSTALL_LOG} ; then
    	echo -e " [${LightRed}failed${NC}]"
		echo "  Perl is required, please install it.";
		exit 1;
	else
		echo -e " [${LightGreen}ok${NC}]"
	fi;
}
	

check_perl_dep()
{
	echo -n " * checking perl module dependencies"
    PERL_MODULES=$(cat tools/inc/perl.modules.base)
    [ -e .perl_modules_missing ] && rm .perl_modules_missing
    [ -e .perl_deps_guess ] && rm .perl_deps_guess
    for pm in $PERL_MODULES; do
    	perl -e "use $pm" 2>>/dev/null || echo $pm >> .perl_modules_missing;
    done
    if [ -e .perl_modules_missing ]; then
    	echo -e " [${LightRed}failed${NC}]"
    	echo "   Following perl modules are required and could not be found on your system:"
    	for pm in $(cat .perl_modules_missing); do
    		echo -n "     $pm"
    		if [ -e tools/inc/perl.modules.$DISTRO ]; then
    			GUESS_INSTALL=$(cat tools/inc/perl.modules.$DISTRO|grep $pm| awk '{print $2}')
    			if [ ! -z $GUESS_INSTALL ]; then 
    				echo " ($GUESS_INSTALL)"
    				echo "$GUESS_INSTALL" >> .perl_deps_guess
    			else
    			    echo ""
    			fi
    		else 
    			echo ""
    		fi
    	done
    	if [ -e .perl_deps_guess ]; then
	    	echo "   To install the missing dependencies run:"
    		echo -n "     apt-get install"
    		for d in $(cat .perl_deps_guess | sort -u); do
    			echo -n " $d"
    		done
    		echo ""
    		exit 1
    	fi
	else
		echo -e " [${LightGreen}ok${NC}]"
    fi
}

check_perl_db()
{
	echo -n " * checking perl db abstraction"
	DEFAULT_DB_TYPE="";
	if test -e ${SLX_CONFIG_PATH}/settings; then
    	sed ${SLX_CONFIG_PATH}/settings -e "s,=,=\"," -e "s,$,\"," > /tmp/slxsettings;
		. /tmp/slxsettings;
        rm /tmp/slxsettings;
	fi;
	
	for m in ${SLX_DB_TYPE} SQLite mysql; do
		if ! perl -Isrc/lib -Isrc/config-db -e "use OpenSLX::MetaDB::$m" 2>>${SLX_INSTALL_LOG} ; then
			echo -e "  'DBD::$m' not found (or too old), so $m-databases will not be supported.";
		else
			if test "${DEFAULT_DB_TYPE}X" = "X"; then
				DEFAULT_DB_TYPE=$m;
				echo -e " [${LightGreen}ok${NC}]"
				echo " * selected db backend: $m";
				break;
			fi;
		fi;
	done;
	if test "${DEFAULT_DB_TYPE}X" = "X"; then
		echo -e " [${LightRed}failed${NC}]"
		echo "  None of the DB-modules is available! Please install one of them.";
		exit 1;
	else
		echo $${DEFAULT_DB_TYPE} >DEFAULT-DB-TYPE;
	fi;
}	

check_helper_apps()
{
	echo -n " * checking for required linux tools"
	if ! which rsync >/dev/null 2>&1; then
		echo -e " [${LightRed}failed${NC}]"
		echo "  rsync is required, please install it.";
		exit 1;
	fi;
    echo -e " [${LightGreen}ok${NC}]"
}

_install(){
    FILE=$1
    BASE_TARGET=$2
    ADDOPTS=$3
    [ "$BASE_TARGET" = "config" ] && BASE_TARGET_PATH=${PREPARE_INSTALL_TARGET}${SLX_CONFIG_PATH}
    [ "$BASE_TARGET" = "base" ] && BASE_TARGET_PATH=${INSTALL_BASE}
	while read TYPE SOURCE TARGET; do
		if [ "$TYPE" = "f" ]; then
			cp src/${SOURCE} ${BASE_TARGET_PATH}/${TARGET}
		elif [ "$TYPE" = "d" ]; then
		    SOURCE_DIRNAME=$(echo $SOURCE | sed -e 's,^.*/,,' )
		    SOURCE_BASE=$(echo $SOURCE | sed -e 's,\(^.*/\).*,\1,')
		    [ "$SOURCE_DIRNAME" = "$SOURCE" ] && SOURCE_BASE=""
     		tar -cp $ADDOPTS -C src/${SOURCE_BASE} ${SOURCE_DIRNAME} \
     		| tar -xp -C ${BASE_TARGET_PATH}/$TARGET
		fi
	done < $FILE
	
}

prepare_install()
{
	echo -n " * prepare OpenSLX installation"
	[ "${TRACE_INSTALLATION}" = "1" ] && set -x
	INSTALL_BASE=${PREPARE_INSTALL_TARGET}${SLX_BASE_PATH}
	[ -e $PREPARE_INSTALL_TARGET ] && rm -rf $PREPARE_INSTALL_TARGET
	mkdir -p ${PREPARE_INSTALL_TARGET}
	mkdir -p ${PREPARE_INSTALL_TARGET}${SLX_CONFIG_PATH}/boot-env/syslinux/themes \
	      -p ${INSTALL_BASE}/lib \
	      -p ${INSTALL_BASE}/bin \
	      -p ${INSTALL_BASE}/share/boot-env \
	      -p ${INSTALL_BASE}/share/initramfs \
	      -p ${INSTALL_BASE}/share/squashfs \
	      -p ${INSTALL_BASE}/share/templates \
	      -p ${INSTALL_BASE}/share/ramfstools \
	      -p ${PREPARE_INSTALL_TARGET}${USR_BIN_PATH} \
	      -p ${PREPARE_INSTALL_TARGET}/lib;
	      
	# copy license
	cp COPYING ${INSTALL_BASE}/
	
	#### copy OpenSLX perl scripts & required modules ####
   	_install ./tools/inc/files.core base
   	
   	#### copy OpenSLX shared data ####
    opts="--exclude=OpenSLX --exclude=*.example" # --strip-components 1"
   	_install ./tools/inc/files.share base $opts

   	#### copy OpenSLX config data ####
    opts="--exclude=OpenSLX"
   	_install ./tools/inc/files.config config $opts

    # copy distro-info
	tar --exclude=*.example -cp -C src/lib distro-info \
	  | tar -xp -C ${PREPARE_INSTALL_TARGET}${SLX_BASE_PATH}/share
	tar --exclude=prereqfiles --exclude=trusted-package-keys/* \
	    --exclude=*.default --exclude=mirrors \
	    -cp -C src/lib distro-info \
	  | tar -xp -C ${PREPARE_INSTALL_TARGET}${SLX_CONFIG_PATH}

    ### link slx binarires ###
	ln -sf ${SLX_BASE_PATH}/bin/slx* ${PREPARE_INSTALL_TARGET}${USR_BIN_PATH}/
	
	### deprecated.. ###
	ln -sf ${SLX_BASE_PATH}/share/uclib-rootfs/lib/ld-uClibc.so.0 \
		${PREPARE_INSTALL_TARGET}/lib/ld-uClibc.so.0

	echo -e " [${LightGreen}ok${NC}]"

}

make_install_tarball()
{
    local COMPRESSION=$1
	[ "x$COMPRESSION" = "x" ] && \
		echo -n " * create OpenSLX install tarball"
	[ "x$COMPRESSION" = "x" ] || \
		echo -n " * create OpenSLX install tarball (compressed with $COMPRESSION)"
	VERSIONSTRING="openslx-$(git_version)"
	cd $PREPARE_INSTALL_TARGET 
	tar cf ../$VERSIONSTRING.tar *
	cd - 2>&1 >/dev/null
    [ "x$COMPRESSION" = "x" ] || $COMPRESSION -f $VERSIONSTRING.tar
	echo -e " [${LightGreen}ok${NC}]"
}	

make_source_tarball()
{
    local COMPRESSION=$1
	[ "x$COMPRESSION" = "x" ] && \
		echo -n " * create OpenSLX source tarball"
	[ "x$COMPRESSION" = "x" ] || \
		echo -n " * create OpenSLX source tarball (compressed with $COMPRESSION)"
	VERSIONSTRING="openslx-$(git_version)-src"
	git archive --format=tar --prefix=$VERSIONSTRING/ -o $VERSIONSTRING.tar HEAD
    [ "x$COMPRESSION" = "x" ] || $COMPRESSION -f $VERSIONSTRING.tar
	echo -e " [${LightGreen}ok${NC}]"
}

prepare_upgrade()
{
	echo -n " * cleanup old OpenSLX installation before upgrade"
	rm -rf ${SLX_BASE_PATH}
	rm -f ${USR_BIN_PATH}/slx*
	echo -e " [${LightGreen}ok${NC}]"
}

do_install()
{
	echo -n " * installing OpenSLX"
	if [ ! "$(whoami)" = "root" ]; then
		echo -e " [${LightRed}failed${NC}]"
		echo "   you need to be root"
		exit 1
	fi
	check_upgrade
	make_install_tarball
	VERSIONSTRING="openslx-$(git_version)"
	check_upgrade
	INSTALL_HOME=$(pwd)
	cd ${SLX_BUILD_PATH}/; tar xf $INSTALL_HOME/$VERSIONSTRING.tar
	cd $INSTALL_HOME
}

uninstall()
{
	echo -n " * Uninstalling OpenSLX project files but keeping configs and stage1"
	rm -rf ${SLX_BASE_PATH}
	rm -rf ${SLX_PUBLIC_PATH}
	rm -f ${USR_BIN_PATH}/slx*
	rm -f /lib/ld-uClibc.so.0
	echo -e " [${LightGreen}ok${NC}]"
	echo "    left config files in ${SLX_CONFIG_PATH} untouched"
	echo "    left config files in ${SLX_PRIVATE_PATH} untouched"
}

mrproper()
{
	echo -n " * Wiping all!"
	rm -rf ${SLX_BASE_PATH}
	rm -rf ${SLX_CONFIG_PATH}
	rm -rf ${SLX_PRIVATE_PATH}
	rm -rf ${SLX_PUBLIC_PATH}
	rm -f ${USR_BIN_PATH}/slx*
	echo -e " [${LightGreen}ok${NC}]"
}

check_upgrade()
{
	# find out if there is an older version installed and, if so, clean that
	INSTALLED_VERSION=$(slxversion 2>/dev/null)
	if ! test -z "${INSTALLED_VERSION}"; then
		if test -e REVISION; then
			. REVISION
		else
			OPENSLX_VERSION_REV=$(git_version)
		fi;
		test "${OPENSLX_SVN_SNAPSHOT}" = "0" &&
			unset OPENSLX_SVN_SNAPSHOT || OPENSLX_SVN_SNAPSHOT="1"
		. ./VERSIONS;
		if test ${INSTALLED_VERSION} != ${OPENSLX_VERSION_STRING}; then
			echo " * preparing upgrade from version (${INSTALLED_VERSION})"
			prepare_upgrade;
		fi;
	fi
}

clean()
{
	echo -n " * Cleanup OpenSLX source directory"
	for file in ${SLX_INSTALL_LOG} openslx-*.tar.bz2; do
		rm -f ${file}
	done
	echo -e " [${LightGreen}ok${NC}]"
}



check_perl
check_perl_dep
check_perl_db
check_helper_apps
prepare_install
#make_install_tarball
#make_install_tarball gzip
#make_install_tarball bzip2
#make_install_tarball lzma
#make_source_tarball
#make_source_tarball gzip
#make_source_tarball bzip2
#make_source_tarball lzma
do_install
git_version