#!/usr/bin/env zsh # Copyright (c) 2017 Dyne.org Foundation # live-sdk is written and maintained by Ivan J. # # This file is part of live-sdk # devuan-desktop-live.blend is maintained by fsmithred # # This source code is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this source code. If not, see . BLENDPATH="${BLENDPATH:-$(dirname $0)}" source $BLENDPATH/config blend_release_path=$BLENDPATH/$release blend_packages=${blend_release_path}/packages blend_scripts=${blend_release_path}/scripts blend_preinst() { fn blend_preinst req=(blend_name) ckreq || return 1 notice "executing $blend_name preinst - copying blend debs and scripts." if [[ -d "${blend_packages}" ]] ; then notice "copying blend-specific debs" mkdir -p "$R/extra/custom-packages" cp -fv "$blend_packages"/*.deb "$R/extra/custom-packages" else notice "no blend-specific debs found in ${blend_release_path}/packages" fi if [[ -d "${blend_scripts}" ]] ; then notice "copying blend-specific scripts" mkdir -p "$R/extra/custom-scripts" cp -fv "$blend_scripts"/*.sh "$R/extra/custom-scripts" else notice "no blend-specific scripts found in ${blend_release_path}/automate" fi enable_apt-proxy } blend_postinst() { fn blend_postinst req=(strapdir blend_name) ckreq || return 1 notice "executing $blend_name postinst" [[ $mkefi = yes ]] && { iso_make_efi iso_write_grub_cfg } install-custdebs || zerr install-custscripts || zerr blend_finalize || zerr disable_apt-proxy } iso_write_isolinux_cfg() { fn iso_write_isolinux_cfg "(override)" req=(workdir arch username) ckreq || return 1 notice "writing isolinux configuration" cat </dev/null ui vesamenu.c32 prompt 0 menu title devuan-live boot menu timeout 70 menu background /isolinux/splash.png menu color title * #C6C2C2 * menu color border * #00000000 #00000000 none menu color sel * #ffffffff #5F1A1A * menu color hotsel 1;7;37;40 #ffffffff #401111 * menu color tabmsg * #D4D0D0 #00000000 * menu color cmdline 0 #D4D0D0 #00000000 menu vshift 12 menu rows 12 # The help line must be at least one line from the bottom. menu helpmsgrow 14 # The command line must be at least one line from the help line. menu cmdlinerow 16 menu timeoutrow 16 menu tabmsgrow 18 menu tabmsg Press ENTER to boot or TAB to edit a menu entry label live menu label ${os}-live (${arch}) menu default linux /live/vmlinuz append initrd=/live/initrd.img boot=live username=${username} label lang_gb menu label en_GB locale (TAB to edit) linux /live/vmlinuz append initrd=/live/initrd.img boot=live username=${username} locales=en_GB.UTF-8 keyboard-layouts=gb label lang_it menu label it_IT locale (TAB to edit) linux /live/vmlinuz append initrd=/live/initrd.img boot=live username=${username} locales=en_IT.UTF-8 keyboard-layouts=it label toram menu label ${os}-live (${arch}) (load to RAM) linux /live/vmlinuz append initrd=/live/initrd.img boot=live username=${username} toram label failsafe menu label ${os}-live (${arch}) (failsafe) kernel /live/vmlinuz noapic noapm nodma nomce nolapic nosmp nomodeset vga=normal append initrd=/live/initrd.img boot=live label memtest menu label Memory test kernel /live/memtest label help menu label ^Help text help Display help screens; type 'menu' at boot prompt to return to this menu endtext config prompt.cfg endtext EOF notice "copying isolinux overlay" sudo mkdir -p "$workdir"/binary/{live,isolinux} sudo cp -rav "$blend_release_path"/isolinux-overlay/* "$workdir"/binary/isolinux/ notice "copying live overlay" sudo cp -av "$blend_release_path"/live-overlay/* "$workdir"/binary/live/ # [[ -n "$hookscripts" ]] && { # sudo cp -av "$blend_release_path"/hooks "$workdir"/binary/live/ # } } # create /boot and /efi for uefi. # uefi code borrowed and adapted from David Hare, who borrowed and adapted it # from similar scripts by Colin Watson and Patrick J. Volkerding. iso_make_efi() { fn iso_make_efi req=(workdir efi_work) ckreq || return 1 notice "creating efi boot files" tempdir="$(mktemp -d /tmp/work_temp.XXXX)" # for initial grub.cfg mkdir -p "$tempdir"/boot/grub if [ "$arch" = amd64 ] ; then grubarch="x86_64-efi" elif [ "$arch" = i386 ] ; then grubarch="i386-efi" fi cat >"$tempdir"/boot/grub/grub.cfg <> boot/grub/${grubarch}/grub.cfg done # Additional modules so we don't boot in blind mode. # I don't know which ones are really needed. efimods=( efi_gop efi_uga ieee1275_fb vbe vga video_bochs video_cirrus jpeg png gfxterm ) for i in $efimods; do print "insmod $i" >> boot/grub/${grubarch}/grub.cfg done print "source /boot/grub/grub.cfg" >> boot/grub/${grubarch}/grub.cfg pushd "$tempdir" # make a tarred "memdisk" to embed in the grub image tar -cvf memdisk boot # make the grub images grub-mkimage -O "x86_64-efi" -m "memdisk" -o "bootx64.efi" \ -p '(memdisk)/boot/grub' \ search iso9660 configfile normal memdisk tar cat \ part_msdos part_gpt fat ext2 ntfs ntfscomp hfsplus \ chain boot linux grub-mkimage -O "i386-efi" -m "memdisk" -o "bootia32.efi" \ -p '(memdisk)/boot/grub' \ search iso9660 configfile normal memdisk tar cat \ part_msdos part_gpt fat ext2 ntfs ntfscomp hfsplus \ chain boot linux popd # copy the grub image to efi/boot (to go later in the device's root) cp "$tempdir"/bootx64.efi efi/boot cp "$tempdir"/bootia32.efi efi/boot # Do the boot image "boot/grub/efiboot.img" dd if=/dev/zero of=boot/grub/efiboot.img bs=1K count=1440 mkfs.vfat -F 12 boot/grub/efiboot.img sudo mkdir img-mnt sudo mount -o loop boot/grub/efiboot.img img-mnt sudo mkdir -p img-mnt/efi/boot sudo cp "$tempdir"/bootx64.efi img-mnt/efi/boot/ sudo cp "$tempdir"/bootia32.efi img-mnt/efi/boot/ # copy modules and font cp ${strapdir}/usr/lib/grub/${grubarch}/* boot/grub/${grubarch}/ # if this doesn't work try another font from the same place (grub's default, unicode.pf2, is much larger) # Either of these will work, and they look the same to me. Unicode seems to work with qemu. -fsr # cp /usr/share/grub/ascii.pf2 boot/grub/font.pf2 cp ${strapdir}/usr/share/grub/unicode.pf2 boot/grub/font.pf2 # copy splash sudo cp -rav "$blend_release_path"/isolinux-overlay/splash.png boot/grub/splash.png # Cleanup efi temps sudo umount img-mnt sudo rmdir img-mnt rm -rf "$tempdir" popd # Copy efi files to iso pushd ${workdir} sudo rsync -avx "${efi_work}"/boot binary/ sudo rsync -avx "${efi_work}"/efi binary/ popd } iso_write_grub_cfg() { fn iso_write_grub_cfg "(override)" req=(workdir arch username) ckreq || return 1 notice "writing grub configuration" # Do the main grub.cfg (which gets loaded last): cat </dev/null #!/bin/sh set -x for i in cdrom floppy audio dip video plugdev netdev lpadmin scanner; do gpasswd -a ${username} \$i done chsh -s "${default_shell}" ${username} update-alternatives --set editor ${default_editor} chown -R 1000:1000 /home/${username} ## This can go away when desktop-base is fixed to do the grub theme. (SEEMS TO BE FIXED-no it's not.) #grep -q GRUB_THEME /etc/default/grub || { # printf "\nGRUB_THEME=/usr/share/desktop-base/grub-themes/desktop-grub-theme/theme.txt\n" >> /etc/default/grub #} # ## This needs to stay #cp /splash.png /usr/lib/refractasnapshot/iso/isolinux/ #rm -f /splash.png # This has been fixed (in devuan-baseconf) in suites/ascii #rm -rf /data rm -f /etc/fstab rm -f /etc/popularity-contest.conf rm -f /vmlinuz.old rm -f /initrd.img.old # For ascii if no display manager is used. Maybe this should have a # contitional that's turned on/off in the config? # echo "needs_root_rights=yes" >> /etc/X11/Xwrapper.config # Disable contrib and non-free after installing firmware. # sed -i 's/contrib//g' /etc/apt/sources.list # sed -i 's/non-free//g' /etc/apt/sources.list # for amd64 only at this time if ls /boot | grep amd64 ; then apt-get download grub-pc apt-get download grub-efi-ia32 fi ##### this should be temporary if dpkg -l lightdm ; then apt-get -y --purge remove lightdm lightdm-gtk-greeter liblightdm-gobject-1-0 echo "Removed lightdm" > /home/devuan/which_dm fi if dpkg -l grub-efi-amd64-signed ; then apt-get -y remove grub-efi-amd64-signed fi ## package list dpkg -l | awk '/^ii/ { print \$2 " " \$3 }' > /home/${username}/package_list # Enable encryption (e.g. for live-usb with persistence) #sed -i 's/#CRYPTSETUP=/CRYPTSETUP=y/' /etc/cryptsetup-initramfs/conf-hook CRYPTSETUP=y update-initramfs -u -k all # Change sources.list to use deb.devuan.org #sed -i 's/pkgmaster/deb/g' /etc/apt/sources.list # Run zgen update as root and the user to bring in the extensions. zgen update su - default zgen update apt-get update apt-get clean updatedb EOF chroot-script -d finalize || zerr } ## Override the helper function: # takes the 'apt-get -f' out of the loop so that dependency provided by other debs can be resolved. # inside the loop it just uninstalls the deb because of unfullfilled deps. install-custdebs() { fn install-custdebs req=(R strapdir custom_deb_packages) ckreq || return 1 sudo mkdir -p ${strapdir}/debs sudo cp $R/extra/custom-packages/*.deb ${strapdir}/debs/ cat </dev/null #!/bin/sh cd /debs for deb in ${custom_deb_packages}; do dpkg -i \$deb done apt-get --yes --force-yes -f install cd / apt-get --yes --force-yes autoremove #rm -rf /debs EOF chroot-script -d install-debs } ## Added function: # In the style of install-custdebs above but for a collection of arbitrary scripts placed in a # directory alongside the blend custom debs called automate. # The scripts are copied from the automate directory to extra/custom-scripts in blend_preinst() above. # Called after install-customdebs because some need checkinstall which disappears from archives. install-custscripts() { fn install-custscripts req=(R strapdir custom_scripts) ckreq || return 1 sudo mkdir -p ${strapdir}/var/tmp/automate sudo cp $R/extra/custom-scripts/*.sh ${strapdir}/var/tmp/automate/ cat </dev/null #!/bin/sh cd /var/tmp/automate for script in ${custom_scripts}; do touch \${script}.log bash \$script done apt-get --yes --force-yes -f install cd / apt-get --yes --force-yes autoremove #rm -rf /var/tmp/automate EOF chroot-script -d install-scripts } ## Override the helper function: # Allow an alternative skel directory add-user() { fn add-user $* local user="$1" local pass="$2" local skel="$3" req=(strapdir user pass skel) ckreq || return 1 notice "adding user $user:$pass using $skel" touch ${strapdir}/adduser.log cat < /etc/apt/apt.conf.d/02proxy << 'FOE' Acquire::http { Proxy "${apt_proxy}"; }; FOE EOF chroot-script addproxy || zerr } disable_apt-proxy() { fn enable_apt-proxy req=(apt_proxy) ckreq || return 1 cat << EOF | sudo tee ${strapdir}/delproxy #!/bin/sh #sed '/^${apt_proxy}/d' /etc/apt/apt.conf.d/02proxy if [ -f /etc/apt/apt.conf.d/02proxy ]; then rm /etc/apt/apt.conf.d/02proxy fi EOF chroot-script delproxy || zerr } ## Override to insert an apt-proxy before the main fetch of packages begins #bootstrap_config_thirdstage() { # fn bootstrap_config_thirdstage # req=(core_packages base_packages apt_proxy) # ckreq || return 1 # # if [ -v ${apt_proxy} ]; then # enable_apt-proxy # fi # # cat << EOF ##!/bin/sh #apt-get update #debconf-set-selections /debconf.set # #echo "${rootcredentials}" | chpasswd #sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' \ # /lib/udev/rules.d/75-persistent-net-generator.rules #rm -f /etc/udev/rules.d/70-persistent-net.rules #export DEBIAN_FRONTEND=noninteractive # #apt-get --yes --force-yes install ${core_packages_option} ${core_packages} #apt-get --yes --force-yes install ${base_packages_option} ${base_packages} #apt-get --yes --force-yes purge ${purge_packages_option} ${purge_packages} #apt-get --yes --force-yes autoremove # #apt-get clean # #sed -e 's/# en_US.UTF-8/en_US.UTF-8/' -i /etc/locale.gen #locale-gen # #rm -f /debconf.set #rm -f /etc/ssh/ssh_host_* #rm -f /root/.bash_history #echo "1" > .keep #EOF #}