summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage32/module.build
blob: f20c519670582762c7281e1d15eccea0a5736780 (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
#!/bin/bash
#!/bin/bash
fetch_source() {
	:
}

build() {
	if [ ! -z "$REQUIRED_CONTENT_PACKAGES" ]; then
		local COPYLIST="list_dpkg_output"
		[ -e "${COPYLIST}" ] && rm "${COPYLIST}"
		list_packet_files >> "${COPYLIST}"
		tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}"
	fi

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

	# Get ldconfig
	mkdir -p "$MODULE_BUILD_DIR/sbin"
	local LOC=$(which ldconfig.real)
	[ -z "$LOC" ] && LOC=$(which ldconfig)
	[ -z "$LOC" ] && perror "Cannot find ldconfig"
	pdebug "Picking ldconfig from $LOC"
	cp "$LOC" "$MODULE_BUILD_DIR/sbin/ldconfig"

	pinfo "Searching binaries from config file in system..."
	for BIN in ${REQUIRED_BINARIES}
	do
		[ -n "$(find "$MODULE_BUILD_DIR" -name "$BIN")" ] && continue
		BIN_LOCATION="$(which "$BIN")"
		if [ ! -z "$BIN_LOCATION" -a -e "$BIN_LOCATION" ]; then
			get_link_chain "$BIN_LOCATION" >> "$FILELIST"
		else
			perror "${BIN} not found on the system! Please install it."
		fi
	done

	pinfo "Searching libraries from config file in system... (could take some time)"
	for LIB in ${REQUIRED_LIBRARIES}
	do
		# lib + lib64: Ugly hack, will be replaced by a better solution
		for LIB_LOCATION in $(find /lib/ /lib64/ -name "${LIB}.so*")
		do
			get_link_chain "${LIB_LOCATION}" >> "${FILELIST}"
		done
	done

	for FILE in /etc/ssl/certs
	do
		[ ! -d ${FILE} ] && perror "Missing required directory $FILE"
		echo ${FILE} >> "${FILELIST}"
		(
			IFS=$'\n'
			for file in $(find "${FILE}" -type l); do
				get_link_chain "${file}" >> "${FILELIST}"
			done
		)
	done
	for FILE in ${REQUIRED_FILES}
	do
		[ ! -f ${FILE} ] && perror "Missing required file $FILE"
		echo ${FILE} >> "${FILELIST}"
	done
	# Grab gconv .so files, required by vmware, mtools and maybe some more tools
	find /usr/lib/ /usr/lib64 -name gconv -type d | grep -v debug >> "${FILELIST}"

	local NUMFILES=$(cat "${FILELIST}" | wc -l)
	if [ "x$NUMFILES" != "x" -a "x$NUMFILES" != "x0" ]; then
		pinfo "File list generated at ${MODULE_BUILD_DIR}/${FILELIST} ($NUMFILES entries)"
		pinfo "If something fails here, try to clean this module first."
		tarcopy "$(cat "${FILELIST}")" "${MODULE_BUILD_DIR}"
	fi
}

post_copy() {
	# symlink for more
	if [ ! -e "$TARGET_BUILD_DIR/bin/more" ]; then
		[ -e "$TARGET_BUILD_DIR/bin/less" ] && ln -s /bin/less "$TARGET_BUILD_DIR/bin/more"
		[ -e "$TARGET_BUILD_DIR/usr/bin/less" ] && ln -s /usr/bin/less "$TARGET_BUILD_DIR/bin/more"
	fi
	# same hack for mount
	[ ! -e "$TARGET_BUILD_DIR/bin/mount" ] && ln -s /usr/bin/mount "$TARGET_BUILD_DIR/bin/mount"
	
	# make basic directory structure
	mkdir -p "$TARGET_BUILD_DIR"/{bin,dev,proc,lib,etc,mnt,run,sys,var,opt/openslx/mnt}
	ln -s -n -f -t "$TARGET_BUILD_DIR/var" "../run/lock" "../run"

	# set /etc/environment to include /opt/openslx/bin and /opt/openslx/sbin
	#add_env PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/openslx/sbin:/opt/openslx/bin"
	add_env PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/openslx/sbin:/opt/openslx/bin"
	# set terminal to linux as it defaults to xterm which messes up ssh sessions
	add_env TERM "linux"

	# quick fix for /etc/fstab
	[ ! -e "${TARGET_BUILD_DIR}/etc/fstab" ] && echo "# no configuration" > "${TARGET_BUILD_DIR}/etc/fstab"

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

	# passwd, group, shadow
	init_users_and_groups

	# quick fix for missing group in /etc/group
	add_group "lock"
	add_group "nogroup" 65534
	USERID=65534 GROUPID=65534 add_user "nobody"

	# setup root account
	PASSWORD= USER=root add_user
	DEMO_ID="$(USER=demo PASSWORD= USERHOME=/home/demo USERSHELL=/bin/bash add_user)"

	mkdir -p "${TARGET_BUILD_DIR}/root"
	mkdir -p "${TARGET_BUILD_DIR}/home/demo"
	chown "$DEMO_ID:$DEMO_ID" "${TARGET_BUILD_DIR}/home/demo"
	sed -i -r 's/^blacklist.*pcspkr/#&/g' "$TARGET_BUILD_DIR/etc/modprobe.d/blacklist.conf"

	echo "minilinux-$(hostname)" > "${TARGET_BUILD_DIR}/etc/hostname"


	# copy kernel, modules and firmware
	copy_kernel_modules
	copy_kernel

}