2 ###############################################################################
3 # IPFire.org - An Open Source Firewall Solution #
4 # Copyright (C) - IPFire Development Team <info@ipfire.org> #
5 ###############################################################################
9 SCRIPT_PATH
="$(dirname "$
(readlink
-f "$0")")"
13 .
"${SCRIPT_PATH}/settings.sh"
16 .
"${SCRIPT_PATH}/functions.sh"
21 log DEBUG
"Working dir is ${WORKING_DIR}"
27 # Check that pakfire is working
30 if ! check_for_free_space
10000 "${WORKING_DIR}"; then
34 # Check that the image does not exist yet
35 if [ -f ${IMAGE_BASE_FILE} ]; then
36 log ERROR
"Image file does already exists"
40 # Check that the local repo file does not exists yet.
41 # We do not want to override custom user configurations.
42 if [ -f "${LOCAL_REPO_FILE}" ]; then
43 log ERROR
"Config file ${LOCAL_REPO_FILE} for the local repo does already exists"
47 # cd into working directory
48 cd ${WORKING_DIR} ||
exit ${EXIT_ERROR}
51 ## Create the disk image.
53 dd if=/dev
/zero of
=${IMAGE_BASE_FILE} seek
=${IMAGE_SIZE}M count
=1k bs
=1
55 # Setup the loopback device.
56 outlo
=`losetup -f --show ${IMAGE_BASE_FILE}`
58 log INFO
"Loop device is ${outlo}"
59 log INFO
"Create partions and filesystem"
61 # Create and msdos compatible table on the image.
62 parted
${outlo} mklabel msdos
64 # Add a new partition to the image.
65 parted
${outlo} mkpart primary
${FILESYSTEM} 2048k
100% -a minimal
67 # Make the primary partition bootable.
68 parted
${outlo} set 1 boot on
70 # Notify the kernel about the new partition.
74 ## Create the filesystem.
76 mkfs.
${FILESYSTEM} ${outlo}p1
79 ## Mount the filesystem.
82 log INFO
"Mount partion in ${IMAGE_MOUNT_DIR}"
84 # Afterwards mount the image.
85 mount
-t ${FILESYSTEM} ${outlo}p1 ${IMAGE_MOUNT_DIR}
88 ## Install IPFire 3.x.
91 # Add grub on x86_64 to the package list.
92 if [ "${ARCH}" == "x86_64" ] ||
[ "${ARCH}" == "i686" ]; then
93 PACKAGES
="${PACKAGES} grub"
95 # Store, that grub is present.
99 # Check if the git network stack should be installed.
100 if [ "${USE_GIT_NETWORK_STACK}" == "True" ]; then
101 GIT_REPOS
="${GIT_REPOS} git://git.ipfire.org/network.git"
103 # Add build dependencies of network package.
104 PACKAGES
="${PACKAGES} ${NETWORK_BUILD_DEPS}"
107 # Add develoment packes to the package list, if required.
108 if [ "${INSTALL_DEV_PACKAGES}" == "True" ] ||
[ ! -z "${GIT_REPOS}" ]; then
109 PACKAGES
="${PACKAGES} ${DEVELOPMENT_PACKAGES}"
112 log INFO
"Create local respository"
115 # Check if the local repo should be used.
116 if [ "${USE_LOCAL_REPO}" == "True" ]; then
117 # Create local repository.
118 mkdir
-pv "${LOCAL_REPO_DIR}"
121 if ! pakfire-server repo create
${LOCAL_REPO_DIR} ${LOCAL_REPO_SOURCE_PATH}; then
122 log ERROR
"Failed to create a local respository"
127 # Create temporary pakfire repo file.
128 echo "[repo:local]" >> "${LOCAL_REPO_FILE}"
129 echo "description = Local repository." >> "${LOCAL_REPO_FILE}"
130 echo "enabled = 0" >> "${LOCAL_REPO_FILE}"
131 echo "baseurl = ${LOCAL_REPO_DIR}" >> "${LOCAL_REPO_FILE}"
133 ENABLE_LOCAL
="--enable-repo=local"
136 # Install IPFire 3.x in the created image.
137 yes | pakfire
--root=${IMAGE_MOUNT_DIR} ${ENABLE_LOCAL} install @Base ${PACKAGES}
140 # Enable serial console
144 #echo "GRUB_TERMINAL=\"serial console\"" >> "${IMAGE_MOUNT_DIR}/etc/default/grub"
145 #echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> "${IMAGE_MOUNT_DIR}/etc/default/grub"
147 #Hack to install a /etc/default/grub file
149 cmd
cp -f "${SCRIPT_PATH}/grub" "${IMAGE_MOUNT_DIR}/etc/default"
155 # Gather the uuid of the partition.
156 FS_UUID
=$
(blkid
-o value
-s UUID
${outlo}p1
)
159 echo "UUID=${FS_UUID} / ${FILESYSTEM} defaults 0 0" > "${IMAGE_MOUNT_DIR}/etc/fstab"
161 cat "${IMAGE_MOUNT_DIR}/etc/fstab"
164 ## Remove the password for user root.
167 reset_root_password
"${IMAGE_MOUNT_DIR}"
170 ## Setup git repositories.
173 clone_git_repos
"${IMAGE_MOUNT_DIR}/build" ${GIT_REPOS}
176 ## Prepare chrooting into the image.
179 # Check if the network stack should be build.
180 if [ "${USE_GIT_NETWORK_STACK}" == "True" ]; then
181 BUILD_NETWORK_CMDS
="cd network/ && ./autogen.sh && ./configure && make && make install"
184 ENABLE_GETTY
="/bin/systemctl enable getty@.service"
186 # Check if the arch uses grub
187 if [ "${HAVE_GRUB}" == "True" ]; then
188 GENERATE_GRUB_CONF
="grub-install --boot-directory=${IMAGE_MOUNT_DIR}/boot/ --modules="${FILESYSTEM} part_msdos" ${outlo} && \
189 grub-mkconfig -o /boot/grub/grub.cfg"
193 # Use systemd-nspawn to spawn a chroot environment and execute
194 # commands inside it.
196 # The first command enables the terminal on TTY1.
197 # The second command generates the configuration file for grub2.
200 systemd-nspawn
-D ${IMAGE_MOUNT_DIR} --bind /dev
--capability=CAP_SYS_ADMIN
,CAP_SYS_RAWIO
--bind /proc
--bind /sys
<< END
201 echo "Execute commands inside chroot"
203 ${GENERATE_GRUB_CONF}
205 ${BUILD_NETWORK_CMDS}
206 echo "All commands executed"
211 # Insert the UUID because grub-mkconfig often fails to
212 # detect that correctly
214 sed -i "${IMAGE_MOUNT_DIR}/boot/grub/grub.cfg" \
215 -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=${FS_UUID}/g"
217 cat "${IMAGE_MOUNT_DIR}/boot/grub/grub.cfg"
219 cat "${IMAGE_MOUNT_DIR}/etc/fstab"
229 # Check filesystem for damage.
230 fsck.
${FILESYSTEM} ${outlo}p1
234 publish
"${IMAGE_DIR_PUBLISH}" "${IMAGE_BASE_FILE}"