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
|
#!/bin/bash
ROOT_DIR="/home/joe/work/tm-scripts"
MODULE_DIR="${ROOT_DIR}/remote"
STAGE31_DIR="${MODULE_DIR}/stage3.1"
MODULE_LIST="${MODULE_DIR}/core/stage31.modules"
FIRMWARE_LIST="${MODULE_DIR}/core/stage31.firmware"
. "${ROOT_DIR}/helper/logging.inc"
. "${ROOT_DIR}/helper/string.inc"
. "${ROOT_DIR}/helper/fileutil.inc"
. "${ROOT_DIR}/helper/system.inc"
. "${ROOT_DIR}/helper/binutil.inc"
initial_checks() {
[ ! -z "${KERNEL_VERSION}" ] || perror "No kernel version, cannot proceed."
[ ! -z "${ARCH_TRIPLET}" ] || perror "No arch triplet, cannot proceed."
[ -f "${MODULE_LIST}" ] || perror "No list for stage3.1 kernel modules found."
[ -f "${FIRMWARE_LIST}" ] || perror "No list for stage3.1 firmware found."
[ -d "${STAGE31_DIR}" ] || mkdir -p "${STAGE31_DIR}"
[ ! -z "$(which depmod)" ] || perror "No 'depmod' found on this systemd."
[ -d ""${MODULE_DIR}"/tools/busybox/build" ] || perror "No busybox found. Build it first."
}
read_config() {
local CORE_CONFIG="${MODULE_DIR}/core/core.conf"
[ ! -e "${CORE_CONFIG}" ] && perror "${MODULE_DIR}/core/core.conf not found."
. "${CORE_CONFIG}" || perror "Sourcing "${MODULE_DIR}"/core/core.conf failed."
}
copy_kernel_modules() {
local MODLIST="stage31_modules_list"
[ -e $MODLIST ] && rm -f $MODLIST
# process modules list
for MOD in ${REQUIRED_MODULES}; do
local MOD_PATH="/lib/modules/${KERNEL_VERSION}/${MOD}"
if [ ! -e "${MOD_PATH}" ]; then
pwarning "Module $MOD not found. Skipping. (might cause problem on certain clients!)"
continue
else
pdebug "Copying "${MOD_PATH}""
echo "${MOD_PATH}" >> "${MODLIST}"
fi
done
if [ -s "$MODLIST" ]; then
local MODLISTCOUNT=$(cat "$MODLIST" | wc -l)
pinfo "Copying $MODLISTCOUNT modules to stage 3.1 target directory."
tarcopy "$(cat "$MODLIST")" "${STAGE31_DIR}"
fi
}
generate_modules_map_files() {
# first strip modules.order of all the modules we don't use
cat /lib/modules/"${KERNEL_VERSION}"/modules.order | grep -E $(tr '\n' '|' < $MODULE_LIST) \
>> "${STAGE31_DIR}"/lib/modules/"${KERNEL_VERSION}"/modules.order
# copy list of builtin kernel modules
cp /lib/modules/"${KERNEL_VERSION}"/modules.builtin "${STAGE31_DIR}"/lib/modules/"${KERNEL_VERSION}"
# with modules.order and modules.builtin, we can run depmod for the rest of the files
depmod -b "${STAGE31_DIR}"
}
copy_firmware() {
local FWLIST="stage31_firmware_list"
[ -e $FWLIST ] && rm -f $FWLIST
local FW_PATH="/lib/firmware"
# process firmware list
pinfo "Copying firmware from system..."
for FW in ${REQUIRED_FIRMWARE}; do
local FOUND=0
if [ -e "${FW_PATH}"/"${FW}" ]; then
pdebug "Copying "${FW_PATH}"/"${FW}""
echo "${FW_PATH}"/"${FW}" >> "$FWLIST"
FOUND=1
fi
if [ -e "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}" ]; then
pdebug "Copying "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}""
echo "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}" >> "$FWLIST"
FOUND=1
fi
[ $FOUND -ne 1 ] && pwarning "Neither "${FW_PATH}"/"${FW}" nor "${FW_PATH}"/"${KERNEL_VERSION}"/"${FW}" found on the system."
done
if [ -s "${FWLIST}" ]; then
local FWLISTCOUNT=$(cat "$FWLIST"|wc -l)
pinfo "Copying $FWLISTCOUNT firmware to stage 3.1 target directory."
tarcopy "$(cat "$FWLIST")" "${STAGE31_DIR}"
fi
}
generate_rootfs() {
# create basic directory structure
mkdir -p "${STAGE31_DIR}"/{bin,dev,proc,run,etc,mnt,sys} || perror "Cannot create basic directory structure in '${STAGE31_DIR}'"
# copy device files from running system
cp -a /dev/{console,kmsg,mem,null,tty,tty0,tty1,tty9,urandom,zero} \
"${STAGE31_DIR}"/dev || perror "Cannot copy devices from running system"
# copy libc and ld-linux
tarcopy "$(list_basic_libs)" "${STAGE31_DIR}"
# copy required files
tarcopy "${REQUIRED_FILES}" "${STAGE31_DIR}"
# copy static data
cp -r "${MODULE_DIR}"/core/data/* "${STAGE31_DIR}"
}
get_basic_tools() {
# get busybox from tools/ we checked earlier if its there.
cp -r "${MODULE_DIR}"/tools/busybox/build/openslx/* "${STAGE31_DIR}"
# get hwinfo and the required libx86emu
[ ! -d "${MODULE_DIR}"/core/src ] && mkdir -p "${MODULE_DIR}"/core/src
cd "${MODULE_DIR}"/core/src
# start with libx86emu
git clone git://gitorious.org/x86emu/libx86emu.git
cd libx86emu
make || perror "[libx86emu] make failed."
#make install || perror "[libx86emu] make install to system failed."
DESTDIR="${MODULE_DIR}"/core/build make install || perror "[libx86emu] make install to "${STAGE31_DIR}" failed."
cd - &> /dev/null
# now hwinfo
git clone git://gitorious.org/opensuse/hwinfo.git
cd hwinfo
make || perror "[hwinfo] make failed."
DESTDIR="${MODULE_DIR}"/core/build make install || perror "[hwinfo] make install failed."
cd - &> /dev/null
# get dependencies of hwinfo
cd "${MODULE_DIR}"/core/build
HWINFO=$(find . -type f -name hwinfo -executable)
get_link_chain "${MODULE_DIR}"/core/build/"${HWINFO}" "${MODULE_DIR}"/core/build >> list_wanted_stage3.1
get_dynamic_dependencies -l "${MODULE_DIR}"/core/build "${MODULE_DIR}"/core/build/"${HWINFO}" >> list_wanted_stage3.1
tarcopy "$(cat list_wanted_stage3.1)" "${STAGE31_DIR}"
cd - &> /dev/null
}
generate_stage31() {
pinfo "Generating stage 3.1 file system..."
cd "${MODULE_DIR}"/core
initial_checks
read_config
copy_kernel_modules
generate_modules_map_files
copy_firmware
generate_rootfs
get_basic_tools
cd - &> /dev/null
}
|