devuan-minimal-live.blend (9185B)
1 #!/usr/bin/env zsh 2 # Copyright (c) 2017 Dyne.org Foundation 3 # live-sdk is written and maintained by Ivan J. <parazyd@dyne.org> 4 # 5 # This file is part of live-sdk 6 # devuan-minimal-live.blend is maintained by KatolaZ <katolaz@freaknet.org> 7 # 8 # This source code is free software: you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation, either version 3 of the License, or 11 # (at your option) any later version. 12 # 13 # This software is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this source code. If not, see <http://www.gnu.org/licenses/>. 20 21 BLENDPATH="${BLENDPATH:-$(dirname $0)}" 22 23 source $BLENDPATH/config 24 25 blend_release_path=$BLENDPATH/$release/ 26 blend_scripts=${blend_release_path}/scripts 27 28 ###source $BLENDPATH/$release/devuan-minimal-live.release 29 30 blend_preinst() { 31 fn blend_preinst 32 req=(blend_name username userpass) 33 ckreq || return 1 34 35 notice "executing $blend_name preinst" 36 37 add-user $username $userpass 38 39 notice "copying blend-specific debs into $R/extra/custom-packages" 40 ## No more custom-packages 41 ##cp -fv "$blend_release_path"/custom_debs/*.deb "$R/extra/custom-packages" 42 } 43 44 blend_postinst() { 45 fn blend_postinst 46 req=(strapdir blend_name) 47 ckreq || return 1 48 49 notice "executing $blend_name postinst" 50 51 [[ "$mkefi" = "yes" ]] && { 52 iso_make_efi 53 iso_write_grub_cfg 54 } 55 56 ## TODO: ENABLE THIS 57 install-custdebs || zerr 58 pushd "$strapdir" 59 sudo rsync -avx --no-o --no-g "$blend_release_path"/rootfs_overlay/* . || zerr 60 sudo chmod 755 etc/init.d/boot_beep 61 popd 62 63 blend_finalize || zerr 64 } 65 66 iso_write_isolinux_cfg() { 67 fn iso_write_isolinux_cfg "(override)" 68 req=(workdir arch username) 69 ckreq || return 1 70 71 notice "copying isolinux overlay" 72 sudo mkdir -p "$workdir"/binary/{live,isolinux} 73 sudo cp -rav "$blend_release_path"/isolinux_overlay/* "$workdir"/binary/isolinux/ 74 #[[ -n "$hookscripts" ]] && { 75 # sudo cp -av "$BLENDPATH"/hooks "$workdir"/binary/live/ 76 #} 77 } 78 79 # create /boot and /efi for uefi. 80 # uefi code borrowed and adapted from David Hare, who borrowed and adapted it 81 # from similar scripts by Colin Watson and Patrick J. Volkerding. 82 iso_make_efi() { 83 fn iso_make_efi 84 req=(workdir efi_work) 85 ckreq || return 1 86 87 notice "creating efi boot files" 88 89 tempdir="$(mktemp -d /tmp/work_temp.XXXX)" 90 # for initial grub.cfg 91 mkdir -p "$tempdir"/boot/grub 92 93 94 cat >"$tempdir"/boot/grub/grub.cfg <<EOF 95 search --file --set=root /isolinux/isolinux.cfg 96 set prefix=(\$root)/boot/grub 97 source \$prefix/x86_64-efi/grub.cfg 98 EOF 99 100 mkdir -p "$efi_work" 101 pushd "$efi_work" 102 103 # start with empty directories. 104 rm -rf boot; mkdir -p boot/grub/x86_64-efi 105 rm -rf efi ; mkdir -p efi/boot 106 107 # second grub.cfg file 108 for i in $(find $strapdir/usr/lib/grub/x86_64-efi -name 'part_*.mod'); do 109 print "insmod $(basename $i)" >> boot/grub/x86_64-efi/grub.cfg 110 done 111 112 # Additional modules so we don't boot in blind mode. 113 # I don't know which ones are really needed. 114 efimods=( 115 efi_gop 116 efi_uga 117 ieee1275_fb 118 vbe 119 vga 120 video_bochs 121 video_cirrus 122 jpeg 123 png 124 gfxterm 125 ) 126 for i in $efimods; do 127 print "insmod $i" >> boot/grub/x86_64-efi/grub.cfg 128 done 129 130 print "source /boot/grub/grub.cfg" >> boot/grub/x86_64-efi/grub.cfg 131 132 pushd "$tempdir" 133 # make a tarred "memdisk" to embed in the grub image 134 tar -cvf memdisk boot 135 136 # make the grub image 137 grub-mkimage -O "x86_64-efi" -m "memdisk" -o "bootx64.efi" \ 138 -p '(memdisk)/boot/grub' \ 139 search iso9660 configfile normal memdisk tar cat \ 140 part_msdos part_gpt fat ext2 ntfs ntfscomp hfsplus \ 141 chain boot linux 142 popd 143 144 # copy the grub image to efi/boot (to go later in the device's root) 145 cp "$tempdir"/bootx64.efi efi/boot 146 147 # Do the boot image "boot/grub/efiboot.img" 148 dd if=/dev/zero of=boot/grub/efiboot.img bs=1K count=1440 149 mkfs.vfat -F 12 boot/grub/efiboot.img 150 151 sudo mkdir img-mnt 152 sudo mount -o loop boot/grub/efiboot.img img-mnt 153 sudo mkdir -p img-mnt/efi/boot 154 sudo cp "$tempdir"/bootx64.efi img-mnt/efi/boot/ 155 156 # copy modules and font 157 cp $strapdir/usr/lib/grub/x86_64-efi/* boot/grub/x86_64-efi/ 158 159 # if this doesn't work try another font from the same place (grub's default, unicode.pf2, is much larger) 160 # Either of these will work, and they look the same to me. Unicode seems to work with qemu. -fsr 161 # cp /usr/share/grub/ascii.pf2 boot/grub/font.pf2 162 cp $strapdir/usr/share/grub/unicode.pf2 boot/grub/font.pf2 163 164 # copy splash 165 sudo cp -rav "$blend_release_path"/isolinux_overlay/splash.png boot/grub/splash.png 166 167 # Cleanup efi temps 168 sudo umount img-mnt 169 sudo rmdir img-mnt 170 rm -rf "$tempdir" 171 172 popd 173 174 175 # Copy efi files to iso 176 pushd $workdir 177 sudo rsync -avx "$efi_work"/boot binary/ 178 sudo rsync -avx "$efi_work"/efi binary/ 179 popd 180 181 } 182 183 184 ## UNUSED 185 iso_write_grub_cfg() { 186 fn iso_write_grub_cfg "(override)" 187 req=(workdir arch username) 188 ckreq || return 1 189 190 notice "writing grub configuration" 191 192 # Do the main grub.cfg (which gets loaded last): 193 cat <<EOF | sudo tee ${workdir}/binary/boot/grub/grub.cfg 194 if loadfont $prefix/font.pf2 ; then 195 set gfxmode=640x480 196 insmod efi_gop 197 insmod efi_uga 198 insmod video_bochs 199 insmod video_cirrus 200 insmod gfxterm 201 insmod jpeg 202 insmod png 203 terminal_output gfxterm 204 fi 205 206 background_image /boot/grub/splash.png 207 set menu_color_normal=white/black 208 set menu_color_highlight=dark-gray/white 209 set timeout=6 210 211 menuentry "${os}-live (${arch})" { 212 set gfxpayload=keep 213 linux /live/vmlinuz boot=live username=$username 214 initrd /live/initrd.img 215 } 216 217 menuentry "Other language" { 218 set gfxpayload=keep 219 linux /live/vmlinuz boot=live username=$username hooks=file:///lib/live/mount/medium/live/hooks/fix-lang.sh locales=it_IT.UTF-8 220 initrd /live/initrd.img 221 } 222 223 menuentry "${os}-live (load to RAM)" { 224 set gfxpayload=keep 225 linux /live/vmlinuz boot=live username=$username toram 226 initrd /live/initrd.img 227 } 228 229 menuentry "${os}-live (failsafe)" { 230 set gfxpayload=keep 231 linux /live/vmlinuz boot=live username=$username noapic noapm nodma nomce nolapic nosmp vga=normal 232 initrd /live/initrd.img 233 } 234 235 menuentry "Memory test" { 236 linux /live/memtest 237 } 238 239 EOF 240 } 241 242 ## put the "create_initrd.sh" script 243 244 ##func 245 put_create_initrd(){ 246 247 sudo cp ${blend_scripts}/create_initrd.sh ${strapdir}/ >/dev/null 248 249 ## Now we make it executable 250 sudo chmod 755 ${strapdir}/create_initrd.sh 251 } 252 253 ## put the "finalize" script, that does the final work 254 255 ## func 256 put_finalize(){ 257 258 cat <<EOF | sudo tee ${strapdir}/finalize >/dev/null 259 #!/bin/sh 260 261 ## permissions 262 for i in cdrom floppy audio dip video plugdev netdev lpadmin scanner; do 263 gpasswd -a ${username} \$i 264 done 265 266 chsh -s "${default_shell}" ${username} 267 chown -R 1000:1000 /home/${username} 268 269 # Not sure if this has been fixed (in devuan-baseconf?) 270 mv /data/etc/apt/apt.conf.d/05disable-suggests /etc/apt/apt.conf.d/ 271 rm -rf /data 272 273 rm -f /etc/fstab 274 rm -f /etc/popularity-contest.conf 275 276 # For ascii if no display manager is used. Maybe this should have a 277 # contitional that's turned on/off in the config? 278 # echo "needs_root_rights=yes" >> /etc/X11/Xwrapper.config 279 280 # Disable contrib and non-free after installing firmware. 281 sed -i 's/ contrib//g' /etc/apt/sources.list 282 sed -i 's/ non-free//g' /etc/apt/sources.list 283 284 ## Disable updates 285 sed -i '/-updates/s/^/## /g' /etc/apt/sources.list 286 287 ## insert service boot_beep 288 insserv boot_beep 289 290 ## Configure framebuffer 291 setcap 'cap_sys_tty_config+ep' /usr/bin/fbterm 292 chmod u+s /usr/bin/fbterm 293 294 ## Make initramfs 295 296 SLIM_INITRD=initrd_devuan.img 297 MICRO_INITRD=/boot/initrd.img 298 INITRD_COMPR="xz --check=crc32 --x86 -6 -" 299 300 301 /create_initrd.sh /initrd.img /boot/\${SLIM_INITRD} \ 302 "\${INITRD_COMPR}" \${MICRO_INITRD} 303 304 rm -f $(realpath /initrd.img) 305 rm -f $(realpath /initrd.img.old) 306 307 echo "====> Content of /boot before rm:" 308 309 ls /boot 310 311 rm -f /initrd.img 312 rm -f /initrd.img.old 313 314 KERN_ORIG=\$(ls /boot/initrd.img-* | head -1 | cut -d "-" -f 2-) 315 316 rm -f /boot/initrd.img-* 317 318 319 echo "====> Content of /boot AFTER rm:" 320 321 ls /boot 322 323 ln -s \${MICRO_INITRD} /initrd.img 324 325 326 327 ## rm create_initrd.sh 328 rm /create_initrd.sh 329 330 ## install additional packages 331 332 cd /custom-packages 333 dpkg -i \$(find ./ -type f -name '*.deb') 334 335 336 ## package list 337 #dpkg -l | awk '/^ii/ { print $2 " " $3 }' > /home/${username}/package_list 338 339 ##apt-get update 340 apt-get clean 341 rm /var/cache/apt/*.bin 342 updatedb 343 344 rm -f /initrd.img 345 rm -f /initrd.img.old 346 rm -f /boot/initrd.img-* 347 ln -s \${MICRO_INITRD} /initrd.img 348 349 ln -s \${MICRO_INITRD} /boot/initrd.img-\${KERN_ORIG} 350 351 352 EOF 353 354 ## cp ${strapdir}/finalize ${strapdir}/finalize.bak 355 356 } 357 358 ## func 359 # put_packages(){ 360 361 # sudo cp -a "$R/extra/custom-packages/" ${strapdir} 362 # } 363 364 365 blend_finalize() { 366 fn blend_finalize 367 req=(strapdir username default_shell) 368 ckreq || return 1 369 370 put_create_initrd 371 #put_packages 372 373 put_finalize 374 375 #chroot-script -d finalize || zerr 376 chroot-script finalize || zerr 377 378 printf "copying ${strapdir}/boot/initrd.img to ${workdir}/binary/live/..." 379 sudo cp -L ${strapdir}/boot/initrd.img ${workdir}/binary/live/ 380 echo "done" 381 }