]>
Commit | Line | Data |
---|---|---|
5bbf7721 JS |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # IPFire.org - An Open Source Firewall Solution # | |
4 | # Copyright (C) - IPFire Development Team <info@ipfire.org> # | |
5 | ############################################################################### | |
6 | ||
9c529a3a JS |
7 | #Path of the script |
8 | ||
9 | SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" | |
10 | ||
5bbf7721 | 11 | |
acd922d7 JS |
12 | #Dependencies of this script |
13 | ||
14 | ||
15 | BINARIES="pakfire pakfire-server dd losetup parted mkfs.${FILESYSTEM} " | |
16 | ||
17 | ||
358ea1df | 18 | # INCLUDE SETTINGS |
e6838c5c | 19 | # shellcheck source=settings.sh |
358ea1df | 20 | . "${SCRIPT_PATH}/settings.sh" |
424aa4ee | 21 | |
358ea1df | 22 | # INCLUDE FUNCTIONS |
e6838c5c | 23 | # shellcheck source=functions.sh |
358ea1df | 24 | . "${SCRIPT_PATH}/functions.sh" |
5bbf7721 | 25 | # |
358ea1df | 26 | # Scripts starts here |
5bbf7721 JS |
27 | # |
28 | ||
e04a0de0 | 29 | log DEBUG "Working dir is ${WORKING_DIR}" |
5bbf7721 | 30 | |
0ca7b8a5 | 31 | |
424aa4ee JS |
32 | #Parse cmdline |
33 | parse_cmdline $@ | |
34 | ||
acd922d7 JS |
35 | for binary in ${BINARIES}; do |
36 | if ! check_for_binary "${binary}"; then | |
37 | exit ${EXIT_ERROR} | |
38 | fi | |
39 | done | |
40 | ||
5bbf7721 JS |
41 | # Check that pakfire is working |
42 | check_for_pakfire | |
43 | ||
c38c098c JS |
44 | if ! check_for_free_space 10000 "${WORKING_DIR}"; then |
45 | exit ${EXIT_ERROR} | |
46 | fi | |
5bbf7721 JS |
47 | |
48 | # Check that the image does not exist yet | |
e04a0de0 | 49 | if [ -f ${IMAGE_BASE_FILE} ]; then |
5bbf7721 JS |
50 | log ERROR "Image file does already exists" |
51 | exit 1 | |
52 | fi | |
53 | ||
54 | # Check that the local repo file does not exists yet. | |
55 | # We do not want to override custom user configurations. | |
56 | if [ -f "${LOCAL_REPO_FILE}" ]; then | |
57 | log ERROR "Config file ${LOCAL_REPO_FILE} for the local repo does already exists" | |
58 | exit 1 | |
59 | fi | |
60 | ||
e04a0de0 JS |
61 | # cd into working directory |
62 | cd ${WORKING_DIR} || exit ${EXIT_ERROR} | |
63 | ||
5bbf7721 JS |
64 | # |
65 | ## Create the disk image. | |
66 | # | |
7d368c65 | 67 | dd if=/dev/zero of=${IMAGE_BASE_FILE} seek=${IMAGE_SIZE}M count=1k bs=1 |
5bbf7721 JS |
68 | |
69 | # Setup the loopback device. | |
e04a0de0 | 70 | outlo=`losetup -f --show ${IMAGE_BASE_FILE}` |
5bbf7721 | 71 | |
16178a1b | 72 | log INFO "Loop device is ${outlo}" |
5bbf7721 JS |
73 | log INFO "Create partions and filesystem" |
74 | ||
75 | # Create and msdos compatible table on the image. | |
76 | parted ${outlo} mklabel msdos | |
77 | ||
78 | # Add a new partition to the image. | |
79 | parted ${outlo} mkpart primary ${FILESYSTEM} 2048k 100% -a minimal | |
80 | ||
81 | # Make the primary partition bootable. | |
82 | parted ${outlo} set 1 boot on | |
83 | ||
84 | # Notify the kernel about the new partition. | |
85 | partx -a ${outlo} | |
86 | ||
87 | # | |
88 | ## Create the filesystem. | |
89 | # | |
90 | mkfs.${FILESYSTEM} ${outlo}p1 | |
91 | ||
92 | # | |
93 | ## Mount the filesystem. | |
94 | # | |
95 | ||
96 | log INFO "Mount partion in ${IMAGE_MOUNT_DIR}" | |
97 | ||
5bbf7721 JS |
98 | # Afterwards mount the image. |
99 | mount -t ${FILESYSTEM} ${outlo}p1 ${IMAGE_MOUNT_DIR} | |
100 | ||
101 | # | |
102 | ## Install IPFire 3.x. | |
103 | # | |
104 | ||
105 | # Add grub on x86_64 to the package list. | |
106 | if [ "${ARCH}" == "x86_64" ] || [ "${ARCH}" == "i686" ]; then | |
107 | PACKAGES="${PACKAGES} grub" | |
108 | ||
109 | # Store, that grub is present. | |
110 | HAVE_GRUB="True" | |
111 | fi | |
112 | ||
113 | # Check if the git network stack should be installed. | |
114 | if [ "${USE_GIT_NETWORK_STACK}" == "True" ]; then | |
115 | GIT_REPOS="${GIT_REPOS} git://git.ipfire.org/network.git" | |
116 | ||
117 | # Add build dependencies of network package. | |
118 | PACKAGES="${PACKAGES} ${NETWORK_BUILD_DEPS}" | |
119 | fi | |
120 | ||
121 | # Add develoment packes to the package list, if required. | |
122 | if [ "${INSTALL_DEV_PACKAGES}" == "True" ] || [ ! -z "${GIT_REPOS}" ]; then | |
123 | PACKAGES="${PACKAGES} ${DEVELOPMENT_PACKAGES}" | |
124 | fi | |
125 | ||
126 | log INFO "Create local respository" | |
127 | ||
128 | ||
129 | # Check if the local repo should be used. | |
130 | if [ "${USE_LOCAL_REPO}" == "True" ]; then | |
131 | # Create local repository. | |
132 | mkdir -pv "${LOCAL_REPO_DIR}" | |
133 | ||
134 | # Master repository. | |
135 | if ! pakfire-server repo create ${LOCAL_REPO_DIR} ${LOCAL_REPO_SOURCE_PATH}; then | |
136 | log ERROR "Failed to create a local respository" | |
91a03596 | 137 | cleanup |
5bbf7721 JS |
138 | exit 1 |
139 | fi | |
140 | ||
141 | # Create temporary pakfire repo file. | |
142 | echo "[repo:local]" >> "${LOCAL_REPO_FILE}" | |
143 | echo "description = Local repository." >> "${LOCAL_REPO_FILE}" | |
144 | echo "enabled = 0" >> "${LOCAL_REPO_FILE}" | |
145 | echo "baseurl = ${LOCAL_REPO_DIR}" >> "${LOCAL_REPO_FILE}" | |
146 | ||
147 | ENABLE_LOCAL="--enable-repo=local" | |
148 | fi | |
149 | ||
150 | # Install IPFire 3.x in the created image. | |
151 | yes | pakfire --root=${IMAGE_MOUNT_DIR} ${ENABLE_LOCAL} install @Base ${PACKAGES} | |
152 | ||
153 | # | |
154 | # Enable serial console | |
155 | # | |
156 | ||
157 | ||
158 | #echo "GRUB_TERMINAL=\"serial console\"" >> "${IMAGE_MOUNT_DIR}/etc/default/grub" | |
159 | #echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> "${IMAGE_MOUNT_DIR}/etc/default/grub" | |
160 | ||
161 | #Hack to install a /etc/default/grub file | |
162 | ||
9c529a3a | 163 | cmd cp -f "${SCRIPT_PATH}/grub" "${IMAGE_MOUNT_DIR}/etc/default" |
5bbf7721 | 164 | |
5bbf7721 JS |
165 | # |
166 | ## Generate fstab | |
167 | # | |
168 | ||
169 | # Gather the uuid of the partition. | |
170 | FS_UUID=$(blkid -o value -s UUID ${outlo}p1) | |
171 | ||
172 | # Write fstab. | |
879862d2 JS |
173 | echo "UUID=${FS_UUID} / ${FILESYSTEM} defaults 0 0" > "${IMAGE_MOUNT_DIR}/etc/fstab" |
174 | ||
175 | cat "${IMAGE_MOUNT_DIR}/etc/fstab" | |
5bbf7721 JS |
176 | |
177 | # | |
178 | ## Remove the password for user root. | |
179 | # | |
180 | ||
181 | reset_root_password "${IMAGE_MOUNT_DIR}" | |
182 | ||
183 | # | |
184 | ## Setup git repositories. | |
185 | # | |
186 | ||
187 | clone_git_repos "${IMAGE_MOUNT_DIR}/build" ${GIT_REPOS} | |
188 | ||
6dd651ff | 189 | |
5bbf7721 JS |
190 | # |
191 | ## Prepare chrooting into the image. | |
192 | # | |
193 | ||
6dd651ff | 194 | chroot_script_init |
5bbf7721 | 195 | |
5bbf7721 | 196 | if [ "${HAVE_GRUB}" == "True" ]; then |
6dd651ff | 197 | chroot_script_add_cmd "grub-install --boot-directory=/boot/ ${outlo}" "grub-mkconfig -o /boot/grub/grub.cfg" |
5bbf7721 JS |
198 | fi |
199 | ||
840a293b | 200 | |
6dd651ff JS |
201 | |
202 | # ENABLE Serial Console | |
203 | chroot_script_add_cmd "/bin/systemctl enable getty@.service" | |
5bbf7721 JS |
204 | |
205 | ||
6dd651ff JS |
206 | # Check if the network stack should be build. |
207 | if [ "${USE_GIT_NETWORK_STACK}" == "True" ]; then | |
208 | chroot_script_add_cmd "cd /build/network" "./autogen.sh" "./configure" "make" "make install" | |
209 | fi | |
5bbf7721 | 210 | |
6dd651ff | 211 | chroot_script_exec |
5bbf7721 JS |
212 | |
213 | ||
214 | # Insert the UUID because grub-mkconfig often fails to | |
215 | # detect that correctly | |
216 | ||
840a293b | 217 | sed -i "${IMAGE_MOUNT_DIR}/boot/grub/grub.cfg" \ |
5bbf7721 JS |
218 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=${FS_UUID}/g" |
219 | ||
840a293b | 220 | cat "${IMAGE_MOUNT_DIR}/boot/grub/grub.cfg" |
879862d2 JS |
221 | |
222 | cat "${IMAGE_MOUNT_DIR}/etc/fstab" | |
223 | ||
224 | ||
5bbf7721 JS |
225 | # |
226 | ## Tidy up. | |
227 | # | |
228 | ||
229 | # Wait a second. | |
230 | sleep 5 | |
231 | ||
232 | # Check filesystem for damage. | |
233 | fsck.${FILESYSTEM} ${outlo}p1 | |
234 | ||
879862d2 JS |
235 | cleanup_stage_1 |
236 | ||
bdeefd44 | 237 | publish "${IMAGE_DIR_PUBLISH}" "${IMAGE_BASE_FILE}" |
5bbf7721 | 238 | |
c5c9ff39 | 239 | # Cleanup |
879862d2 | 240 | cleanup_stage_2 |