summaryrefslogtreecommitdiffstats
path: root/remote/tools/base/base.build
blob: 569d4e15b6a3c0a344431a1fbd2ddae17de11ce1 (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
#!/bin/bash
fetch_source() {
	:
}

build() {

	BUILDDIR="${TOOL_DIR}/${TOOL}/build"
        mkdir -p "${BUILDDIR}"

	FILELIST="list_binaries_and_files"
	[ -e "${FILELIST}" ] && rm "${FILELIST}"

	for BIN in ${REQUIRED_BINARIES}
	do
		BIN_LOCATION=$(which ${BIN})
		if [ ! -z ${BIN_LOCATION} -a -e ${BIN_LOCATION} ];
		then
			pdebug "Processing $BIN at $BIN_LOCATION ..."
			get_link_chain ${BIN_LOCATION} >> "${FILELIST}"
		else
			perror "${BIN} not found on the system! Please install it."
		fi
	done

	for LIB in ${REQUIRED_LIBRARIES}
	do
		for LIB_LOCATION in $(find /lib/ -name "${LIB}.so*")
		do
			get_link_chain "${LIB_LOCATION}" >> "${FILELIST}"
		done
	done

	for FILE in ${REQUIRED_DIRECTORIES}
	do
		[ ! -d ${FILE} ] && perror "Missing required directory $FILE"
		echo ${FILE} >> "${FILELIST}"
	done
	for FILE in ${REQUIRED_FILES}
	do
		[ ! -f ${FILE} ] && perror "Missing required file $FILE"
		echo ${FILE} >> "${FILELIST}"
	done

	local NUMFILES=$(cat "${FILELIST}" | wc -l)
	if [ "x$NUMFILES" != "x" -a "x$NUMFILES" != "x0" ]; then
		pinfo "File list generated at ${BUILDDIR}/${FILELIST} ($NUMFILES entries)"
		tarcopy "$(cat "${FILELIST}")" "${BUILDDIR}"
	fi
}

post_copy() {
	
	# make basic directory structure
	mkdir -p "${INIT_DIR}"/{bin,dev,proc,lib,etc,mnt,sys,var/run,var/lock,var/log,run/lock,run/shm,openslx/mnt}

	# copy devices from running system
	cp -a /dev/{console,kmsg,mem,null,shm,tty,tty0,tty1,tty9,fb0,urandom,zero} \
		"${INIT_DIR}"/dev || perror "Copying devices from running system failed."

	# set /etc/environment to include /openslx/bin and /openslx/sbin
	echo "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/openslx/sbin:/openslx/bin\"" \
        	> "${INIT_DIR}/etc/environment"

	# copy static files
	cp -r "${TOOL_DIR}/${TOOL}"/data/* "${INIT_DIR}" || perror "Copying static files from data/* failed."

	# better: dirname $(ldd $SHELL|grep libc | awk -F " " '{print $3}')
	# copy pam modules, TODO: better way to find arch-dependant interfix...
        tarcopy "$(dirname $(locate pam_unix.so | grep ^/lib/))" "${INIT_DIR}"

	# quick fix for /etc/fstab
	echo "# no configuration" >> "${INIT_DIR}/etc/fstab"

	# link /etc/mtab, needed for systemd
	[ ! -e ${INIT_DIR}/etc/mtab ] && ln -s /proc/self/mounts ${INIT_DIR}/etc/mtab

	# passwd, group, shadow
	init_users_and_groups

	# quick fix for missing group in /etc/group
	add_group "lock"

	# setup root accoun
	USER=root PASSWORD='!r00t' add_user

	mkdir -p ${INIT_DIR}/root

	echo "minilinux-$(hostname)" > "${INIT_DIR}/etc/hostname"
	#check for kernel modules, if not present copy from system
	if [ ! -d ${INIT_DIR}/lib/modules ];
	then
		pinfo "Copying modules for kernel $(uname -r)..."
		mkdir -p "${INIT_DIR}/lib/modules" || perror "Cannot create '${INIT_DIR}/lib/modules'"
		cp -r "/lib/modules/$(uname -r)" "${INIT_DIR}/lib/modules/" || perror "Cannot copy kernel modules from '/lib/modules/$(uname -r)' '${INIT_DIR}/lib/modules/'"
	else
		pinfo "Not copying kernel modules from system, as '${INIT_DIR}/lib/modules/' already exists."
	fi

	#check for firmware, if not present copy from system
	if [ ! -d ${INIT_DIR}/lib/firmware ];
	then
		pinfo "Copying firmware for kernel $(uname -r)..."
		cp -r "/lib/firmware" "${INIT_DIR}/lib/" || perror "Cannot copy kernel modules from '/lib/firmware' '${INIT_DIR}/lib/'"
	else
		pinfo "Not copying firmware from system, as '${INIT_DIR}/lib/firmware' already exists."
	fi	

}