bootstrap: Switch back to the GPLv3+ license
[dragora.git] / stages / 2 / 04-iso
blobc6e90811625db290ef04f5aebf53283a5a648e8a
1 # Build script to compose the Live CD image.
3 # Copyright (c) 2017 MMPG.
4 # Copyright (c) 2017-2021 Matias Fonzo <selk@dragora.org>.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 #    http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # ISO file name
19 ISONAME="${ISONAME:-dragora-3.0_$(date +%Y%m%d)-${package_arch}}"
21 # Default mkisofs(8) invocation name
22 MKISOFS=mkisofs
24 # Perform sanity checks (requirements)
26 if ! test -e "${rootdir}/squashfs-tools_lzip/mksquashfs"
27 then
28     echo "Local \`${rootdir}/squashfs-tools_lzip/mksquashfs' does not exist." 1>&2
29     exit 2;
31 if ! type mkisofs > /dev/null
32 then
33     printf '%s\n' \
34      "" \
35      "    \`mkisofs' was not found in your PATH ..." \
36      "" 1>&2
37     if type genisoimage > /dev/null
38     then
39         MKISOFS=genisoimage
40     else
41         printf '%s\n' \
42         "    \`genisoimage' was not found in your PATH." \
43         "" \
44         "Please install one of these programs to make the ISO image." \
45         "" 1>&2
46         exit 2;
47     fi
49 echo "The \`${MKISOFS}' command will be used to generate the ISO image."
50 echo ""
52 # This depends on the existence of the stage 1
54 if test ! -d "${output}/stage1/usr/pkg"
55 then
56     echo "The stage number 1 does not exist or is incomplete." 1>&2
57     echo "Build (completely) the stage 1 before processing '$stage'." 1>&2
58     exit 1;
60 if test ! -f "${rootdir}/initrd/initrd.img"
61 then
62     echo "${rootdir}/initrd/initrd.img: No such initramfs file" 1>&2
63     exit 1;
66 STAGE1="${output}/stage1"
67 CDROM="${rootdir}/cdrom"
70 # Re-create CD tree
73 echo "Re-creating CD tree (${CDROM}) ..."
74 echo ""
75 rm -rf -- "$CDROM"
76 mkdir -p -- "${CDROM}/isolinux"
79 # Copy kernel installation to isolinux/
82 cd -- "${STAGE1}/boot"
84 for file in System.map-* config-* vmlinuz-*
86     cp -p "${STAGE1}/boot/$file" "${CDROM}/isolinux/${file%%-*}"
87 done
88 unset file
91 # Copy local isolinux files and initramfs for ISOLINUX
94 cp -p "${worktree}"/archive/isolinux/* "${CDROM}/isolinux/"
95 cp -p "${rootdir}/initrd/initrd.img" "${CDROM}/isolinux/"
97 # Clean up (we don't want this on the final ISO)
98 rm -f "${CDROM}/isolinux/isohybrid.pl" \
99       "${CDROM}/isolinux/generate-keymap"
102 # Adjust things on the live side
105 # Set auto login
106 sed \
107  -e 's|c1:123:respawn:/sbin/agetty --noclear tty1 38400 linux|c1:123:respawn:/sbin/agetty --noclear --autologin root --noissue tty1 38400 linux|' \
108  -e 's|c2:123:respawn:/sbin/agetty tty2 38400 linux|c2:123:respawn:/sbin/agetty --autologin root --login-pause --noissue tty2 38400 linux|' \
109  -e 's|c3:12345:respawn:/sbin/agetty tty3 38400 linux|c3:12345:respawn:/sbin/agetty --autologin root --login-pause --noissue tty3 38400 linux|' \
110  -i "${STAGE1}/etc/inittab"
112 # Add instructions for running the installer from boot menu option
113 cat << 'EOF' > "${STAGE1}/root/.profile"
115 # .profile - Personal shell-initialization file.
117 # The instructions here could serve to complement
118 # /etc/profile or to override default (previous)
119 # values.
122 # Add personal bin directory to the end of path
123 # and make it known to child process
125 PATH=${PATH}:${HOME}/bin
126 export PATH
128 # Run Dragora setup if the "parameter" in the boot was set
130 # Execute setup only on tty1/serial console
132 case "$(fgconsole)" in
133 1* | serial* )
134     if grep -q -m 1 DRAGORA_SETUP /proc/cmdline
135     then
136         /sbin/dragora-keymap
137         /sbin/dragora-mouse
138         /sbin/dragora-installer
139     fi
140     ;;
141 esac
146 # Produce compressed image using mksquashfs(1)
149 cd -- "$STAGE1"
150 rm -f ./dragora.sfs
152 "${rootdir}"/squashfs-tools_lzip/mksquashfs ./* "${CDROM}/dragora.sfs" \
153  -comp lzip -b 128K -Xcompression-level 1 -Xdict-size 100% \
154  -noappend -e ./tools ./var/cache/qi/packages ./root/.ash_history \
155   ./*-log* ./usr/pkg/kernel-buildtree-* ./usr/src/linux-* ./usr/src/qi \
156   ./usr/bin/build-for-release
159 # Produce hybrid ISO-9660 image
162 cd -- "$CDROM"
164 rm -f ./${ISONAME}*
165 $MKISOFS -v -o ${ISONAME}.iso                                     \
166          -J -R -iso-level 3                                       \
167          -no-emul-boot -boot-load-size 4 -boot-info-table         \
168          -b "isolinux/isolinux.bin"                               \
169          -c "isolinux/boot.cat"                                   \
170          -V "Dragora-${package_arch}"                             \
171          .
172 unset MKISOFS
174 echo "Applying \"hybrid booting\" to the ISO image ..."
175 "${worktree}"/archive/isolinux/isohybrid.pl ${ISONAME}.iso
177 echo "Creating .sha256 sum ..."
178 echo "sha256sum ${ISONAME}.iso > ${ISONAME}.iso.sha256"
179 sha256sum ${ISONAME}.iso > ${ISONAME}.iso.sha256
181 echo "Finishing ..."
182 echo ""
183 echo "***"
184 echo "The ISO image has been produced at"
185 echo "    ${CDROM}/${ISONAME}.iso"
186 echo "***"
187 echo ""
188 exit 0