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