summaryrefslogtreecommitdiffstats
path: root/mltk
blob: ed05a8195b3b3b89dbb53e4daea347c0415c5d19 (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
#!/bin/bash
# -----------------------------------------------------------------------------
# 
# Copyright (c) 2011 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
#				
#				Mini-Linux Toolkit
#				
# -----------------------------------------------------------------------------

SELF=$(readlink -f $0)
ROOT_DIR=$(dirname ${SELF})

. ${ROOT_DIR}/helper/functions.common.sh
. "${ROOT_DIR}/helper/useradd.inc"

banner () {
	echo -e "\033[38;5;202m\t           __   __   __    "
	echo -e "\033[38;5;202m\t.--------.|  | |  |_|  |--."
	echo -e "\033[38;5;208m\t|        ||  |_|   _|    < "
	echo -e "\033[38;5;214m\t|__|__|__||____|____|__|__|"
	echo -e "\033[38;5;214m\t "
	echo -e "\033[38;5;220m\t                     ** OpenSLX Project // 2013 **"
	echo -e "\033[38;5;226m\t                        http://lab.openslx.org/"
	echo -e "\033[0m"
}

print_usage() {
	echo "Toolkit for creating preboot mini-linux for OpenSLX NG (mltk)"
	echo "Usage: $(basename ${SELF}) MODULE [OPTIONS]"
	echo -e ""
	echo -e "  MODULE:"
	echo -e "     core \t minimal initramfs (stage 3.1) to mount the system-container (stage 3.2)."
	echo -e "     tools \t minimal systemd-based rootfs including basic tools."
	echo -e "     all \t all of the above."
	echo -e ""
	echo -e "  OPTIONS:"
	echo -e "     build, -b \t builds [MODULE]"
	echo -e "     clean, -c \t clean build files for [MODULE]"
	echo -e "     debug, -d \t activates debug output."
	echo -e ""
	echo -e "  Module specific options:"
	echo -e "     tools [OPTION] [TOOL]"
	echo -e "        TOOL can be: \t $(echo $(ls ${ROOT_DIR}/remote/tools))"
}

initial_checks() {
	if [ "x$(whoami)" != "xroot" ]; then
		perror "ERROR: You need to have root rights to install packages."
		exit 1
	else
		banner
	fi
	
	# setup_tools and build_core
	BUILD_CORE=${ROOT_DIR}/server/build_core
	SETUP_TOOLS=${ROOT_DIR}/remote/setup_tools

	[ ! -e ${BUILD_CORE} ] && echo "Missing script build_core, re-clone. Exiting." && exit 1
	[ ! -e ${SETUP_TOOLS} ] && echo "Missing script setup_tools, re-clone. Exiting." && exit 1
}

read_params() {
	MODULE=$1
	case "$1" in
	        core)
	                TARGET_CORE=1
	                ;;
	        tools)
	                TARGET_TOOLS=1
	                ;;
	        all)
	                TARGET_CORE=1
	                TARGET_TOOLS=1
	                ;;
	        *)
	                print_usage
	                exit 1
	                ;;
	esac
	shift

	while true ; do
        	case "$1" in
	                -c|clean)
	                        CLEAN=1
	                        shift
	                        ;;
	                -b|build)
	                        BUILD=1
	                        shift
	                        ;;
			-d|debug)
				DEBUG=1
				shift
				;;
	                *)
				break
                	        ;;
	        esac
	done

	# exit if no command
	[ "x$BUILD" = "x" -a "x$CLEAN" = "x" ] && print_usage && exit 1
	
	TOOLS="$@"	
}

run() {
	if [ $TARGET_TOOLS ]; then
		. ${SETUP_TOOLS}
	        [ $CLEAN ] && clean_tools $TOOLS
	        [ $BUILD ] && generate_stage32 $TOOLS
	fi
	if [ $TARGET_CORE ]; then
		. ${BUILD_CORE}
	        [ $CLEAN ] && clean_core
	        [ $BUILD ] && generate_stage31
	fi
}

initial_checks
read_params $@

#exec 6>&1 > stdout.log
#exec 2> stderr.log

run