nanodesk/makeanything.sh

379 lines
9.5 KiB
Bash
Raw Permalink Normal View History

2023-05-01 03:54:15 +02:00
#!/bin/bash
### this script makes everything to build a ready to boot .iso file of nanodesk
###
### By: DeltaLima
### 2023
2023-05-01 03:58:47 +02:00
2023-05-01 05:32:10 +02:00
CHROOTCMD="sudo chroot build/chroot/"
2023-05-01 10:46:32 +02:00
VERSION="$(git describe --tags)-$(git rev-parse --short HEAD)"
2023-05-01 07:49:56 +02:00
2023-05-01 10:46:32 +02:00
MIRROR=$1
2023-05-01 07:49:56 +02:00
if [ -z "$MIRROR" ]
then
MIRROR="http://ftp.gwdg.de/debian/"
fi
2023-05-01 05:32:10 +02:00
2023-05-01 11:58:19 +02:00
# colors for colored output 8)
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
function message() {
case $1 in
warn)
MESSAGE_TYPE="${YELLOW}WARN${ENDCOLOR}"
;;
error)
MESSAGE_TYPE="${RED}ERROR${ENDCOLOR}"
;;
info|*)
MESSAGE_TYPE="${GREEN}INFO${ENDCOLOR}"
;;
esac
if [ "$1" == "info" ] || [ "$1" == "error" ]
then
MESSAGE=$2
else
MESSAGE=$1
fi
echo -e "[${MESSAGE_TYPE}] $MESSAGE"
2023-05-01 03:58:47 +02:00
}
error ()
{
2023-05-01 11:58:19 +02:00
message error "ERROR!!"
2023-05-01 03:58:47 +02:00
exit 1
}
2023-05-01 06:14:58 +02:00
message "installing requirements"
# ~fakeroot fakechroot~
# debootstrap chroot
### https://www.willhaley.com/blog/custom-debian-live-environment/
sudo apt install \
debootstrap \
squashfs-tools \
xorriso \
isolinux \
syslinux-efi \
grub-pc-bin \
grub-efi-amd64-bin \
grub-efi-ia32-bin \
mtools \
2023-05-01 06:16:53 +02:00
dosfstools \
2023-05-01 09:24:15 +02:00
coreutils \
2023-05-01 11:58:19 +02:00
markdown || error
2023-05-01 03:58:47 +02:00
### stuff begins here
2023-05-01 06:04:01 +02:00
message "Checking build directory"
2023-05-01 03:58:47 +02:00
test -f build/chroot || mkdir -p build/chroot
2023-05-01 05:32:10 +02:00
### i have the problem, that fakechroot will not work atm. in ubuntu 22.04 i get libc6 version mismatch errors. so we run it direct as root. not my favorite, but works for now.
2023-05-01 07:50:25 +02:00
message "running debootstrap with mirror $MIRROR"
2023-05-01 07:52:56 +02:00
sudo debootstrap bullseye build/chroot/ $MIRROR || sudo debootstrap bullseye build/chroot/ $MIRROR
2023-05-01 07:39:57 +02:00
2023-05-01 06:20:39 +02:00
message "copy xdgmenumaker deb file into chroot"
2023-05-01 11:58:19 +02:00
sudo cp deb/xdgmenumaker* build/chroot/tmp || error
2023-05-01 06:04:01 +02:00
message "deploying install_base"
cat <<\EOF > build/chroot/tmp/install_base.sh
2023-05-01 05:32:10 +02:00
#!/bin/bash
2023-05-01 06:44:45 +02:00
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
function message() {
case $1 in
error)
MESSAGE_TYPE="${RED}ERROR${ENDCOLOR}"
;;
info|*)
MESSAGE_TYPE="${GREEN}INFO${ENDCOLOR}"
;;
esac
if [ "$1" == "info" ] || [ "$1" == "error" ]
then
MESSAGE=$2
else
MESSAGE=$1
fi
echo -e "[${MESSAGE_TYPE}] ${YELLOW}install_base${ENDCOLOR}: $MESSAGE"
2023-05-01 07:48:03 +02:00
}
2023-05-01 07:48:03 +02:00
error ()
{
message error "ERROR!!"
2023-05-01 07:48:03 +02:00
exit 1
}
2023-05-01 06:44:45 +02:00
### hostname setting
2023-05-01 05:32:10 +02:00
echo nanodesk > /etc/hostname
2023-05-01 06:44:45 +02:00
### noninteractive
2023-05-01 05:32:10 +02:00
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
2023-05-01 06:44:45 +02:00
### packages
2023-05-01 07:48:03 +02:00
message "install nanodesk base packages"
apt install -y \
live-boot \
linux-image-amd64 \
grub-pc \
ifupdown \
net-tools \
wireless-tools \
wpagui \
isc-dhcp-client \
man \
console-data \
locales \
sudo \
xserver-xorg \
jwm \
xdm \
xterm \
xfe \
pcmanfm \
audacious \
htop \
host \
mc \
wget \
curl \
less \
rsync \
vim \
links2 \
firefox-esr \
transmission-gtk \
lxterminal \
arandr \
zenity \
ncdu \
gparted \
git \
2023-05-01 07:48:03 +02:00
/tmp/xdgmenumaker*.deb || error
2023-05-01 08:01:56 +02:00
message "set hostname in hosts"
sed -i 's/localhost/localhost nanodesk/g' /etc/hosts
2023-05-01 06:44:45 +02:00
### set root password
2023-05-01 07:48:03 +02:00
message "set root password to debian"
2023-05-01 05:32:10 +02:00
echo -e "debian\ndebian" | (passwd root)
2023-05-01 08:01:56 +02:00
2023-05-01 06:44:45 +02:00
### add debian user
2023-05-01 07:48:03 +02:00
message "create user debian"
2023-05-01 07:39:57 +02:00
useradd -m -U -s /bin/bash debian
2023-05-01 08:01:56 +02:00
2023-05-01 06:44:45 +02:00
### set password
2023-05-01 07:48:03 +02:00
message "set password debian for user debian"
2023-05-01 05:32:10 +02:00
echo -e "debian\ndebian" | (passwd debian)
2023-05-01 08:01:56 +02:00
2023-05-01 05:47:12 +02:00
### Configure timezone and locale
#dpkg-reconfigure locales
#dpkg-reconfigure console-data
#dpkg-reconfigure keyboard-configuration
###https://serverfault.com/a/689947
2023-05-01 07:48:03 +02:00
message "set locales and tzdata"
echo "Europe/Berlin" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \
dpkg-reconfigure --frontend=noninteractive locales && \
locale-gen en_US.UTF-8 && \
2023-05-01 05:32:10 +02:00
update-locale LANG=en_US.UTF-8
2023-05-01 08:01:56 +02:00
2023-05-01 07:27:07 +02:00
### clean cache
2023-05-01 07:48:03 +02:00
message "apt clean"
2023-05-01 07:20:44 +02:00
apt clean
2023-05-01 08:01:56 +02:00
KERNEL_VER="$(dpkg -l "linux-image-*" | grep "^ii"| awk '{print $2}' | grep -E 'linux-image-[0-9]\.([0-9]|[0-9][0-9])\.([0-9]|[0-9][0-9])-([0-9]|[0-9][0-9])-amd64$')"
message "KERNEL_VER=$KERNEL_VER"
2023-05-01 07:27:07 +02:00
### but fetch packages for grub and kernel, so we do not need to download them
2023-05-01 07:48:03 +02:00
### in case nanodesk get installed to diska
message "apt --download linux-image and grub packages to have them in cache for installation by user"
apt -d --reinstall install \
linux-image-amd64 \
$(echo $KERNEL_VER) \
grub-pc grub-pc-bin \
grub-common \
grub2-common \
2023-05-01 08:12:39 +02:00
os-prober || error
2023-05-01 05:32:10 +02:00
EOF
2023-05-01 06:04:01 +02:00
message "run install_base"
2023-05-01 05:32:10 +02:00
$CHROOTCMD /bin/bash /tmp/install_base.sh || error
2023-05-01 05:47:12 +02:00
2023-05-01 07:39:57 +02:00
message "clear /tmp"
$CHROOTCMD /usr/bin/rm -Rf /tmp/* || error
2023-05-01 09:42:16 +02:00
### process markdown files in src/ to html
message "convert .md from src to .html in build/chroot"
for md in $(find src/ -name "*.md")
do markdown $md > $(echo $md|sed 's/\.md/\.html/')
done
2023-05-01 10:46:32 +02:00
echo $VERSION > src/usr/share/nanodesk/version
2023-05-01 06:07:51 +02:00
### copy nanodesk configs to chroot
message "copy nanodesk config files into chroot"
2023-05-01 06:12:57 +02:00
sudo cp -r src/* build/chroot/
2023-05-01 06:07:51 +02:00
2023-05-01 06:40:03 +02:00
message "correct file permissions"
$CHROOTCMD /usr/bin/chmod 440 /etc/sudoers
2023-05-01 06:04:01 +02:00
### liveboot part, https://www.willhaley.com/blog/custom-debian-live-environment/
message "checking liveboot directories"
for dir in $(echo build/{staging/{EFI/BOOT,boot/grub/x86_64-efi,isolinux,live},tmp})
do
message "check $dir"
test -d $dir || mkdir -p $dir
done
#mkdir -p build/{staging/{EFI/BOOT,boot/grub/x86_64-efi,isolinux,live},tmp}
2023-05-01 06:44:45 +02:00
message "make squashfs"
2023-05-01 06:04:01 +02:00
test -f build/staging/live/filesystem.squashfs && sudo rm build/staging/live/filesystem.squashfs
2023-05-01 05:47:12 +02:00
sudo mksquashfs \
build/chroot \
build/staging/live/filesystem.squashfs \
-e boot || error
2023-05-01 06:44:45 +02:00
message "copy kernel and init images"
2023-05-01 05:47:12 +02:00
cp build/chroot/boot/vmlinuz-* build/staging/live/vmlinuz || error
cp build/chroot/boot/initrd.img-* build/staging/live/initrd || error
2023-05-01 06:44:45 +02:00
message "isolinux.cfg"
2023-05-01 13:43:30 +02:00
cat <<EOF >build/staging/isolinux/isolinux.cfg
2023-05-01 05:47:12 +02:00
UI vesamenu.c32
MENU TITLE Boot Menu
DEFAULT linux
TIMEOUT 600
MENU RESOLUTION 640 480
MENU COLOR border 30;44 #40ffffff #a0000000 std
MENU COLOR title 1;36;44 #9033ccff #a0000000 std
MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel 37;44 #50ffffff #a0000000 std
MENU COLOR help 37;40 #c0ffffff #a0000000 std
MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07 37;40 #90ffffff #a0000000 std
MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
LABEL linux
2023-05-01 13:43:30 +02:00
MENU LABEL nanodesk $VERSION Live [BIOS/ISOLINUX]
2023-05-01 05:47:12 +02:00
MENU DEFAULT
KERNEL /live/vmlinuz
APPEND initrd=/live/initrd boot=live
LABEL linux
2023-05-01 13:43:30 +02:00
MENU LABEL nanodesk $VERSION Live [BIOS/ISOLINUX] (nomodeset)
2023-05-01 05:47:12 +02:00
MENU DEFAULT
KERNEL /live/vmlinuz
APPEND initrd=/live/initrd boot=live nomodeset
EOF
2023-05-01 13:43:30 +02:00
cat <<EOF > build/staging/boot/grub/grub.cfg
2023-05-01 05:47:12 +02:00
insmod part_gpt
insmod part_msdos
insmod fat
insmod iso9660
insmod all_video
insmod font
set default="0"
set timeout=30
# If X has issues finding screens, experiment with/without nomodeset.
2023-05-01 13:43:30 +02:00
menuentry "nanodesk $VERSION Live [EFI/GRUB]" {
2023-05-01 05:47:12 +02:00
search --no-floppy --set=root --label NANODESK
2023-05-01 13:43:30 +02:00
linux (\$root)/live/vmlinuz boot=live
initrd (\$root)/live/initrd
2023-05-01 05:47:12 +02:00
}
2023-05-01 13:43:30 +02:00
menuentry "nanodesk $VERSION Live [EFI/GRUB] (nomodeset)" {
2023-05-01 05:47:12 +02:00
search --no-floppy --set=root --label NANODESK
2023-05-01 13:43:30 +02:00
linux (\$root)/live/vmlinuz boot=live nomodeset
initrd (\$root)/live/initrd
2023-05-01 05:47:12 +02:00
}
EOF
cp build/staging/boot/grub/grub.cfg build/staging/EFI/BOOT/ || error
cat <<'EOF' >build/tmp/grub-embed.cfg
if ! [ -d "$cmdpath" ]; then
# On some firmware, GRUB has a wrong cmdpath when booted from an optical disc.
# https://gitlab.archlinux.org/archlinux/archiso/-/issues/183
if regexp --set=1:isodevice '^(\([^)]+\))\/?[Ee][Ff][Ii]\/[Bb][Oo][Oo][Tt]\/?$' "$cmdpath"; then
cmdpath="${isodevice}/EFI/BOOT"
fi
fi
configfile "${cmdpath}/grub.cfg"
EOF
2023-05-01 06:44:45 +02:00
message "copy isolinux"
2023-05-01 05:47:12 +02:00
cp /usr/lib/ISOLINUX/isolinux.bin "build/staging/isolinux/" || error
cp /usr/lib/syslinux/modules/bios/* "build/staging/isolinux/" || error
2023-05-01 06:44:45 +02:00
message "copy grub-efi"
2023-05-01 05:47:12 +02:00
cp -r /usr/lib/grub/x86_64-efi/* "build/staging/boot/grub/x86_64-efi/"
2023-05-01 06:44:45 +02:00
message "make efi images"
2023-05-01 05:47:12 +02:00
grub-mkstandalone -O i386-efi \
--modules="part_gpt part_msdos fat iso9660" \
--locales="" \
--themes="" \
--fonts="" \
--output="build/staging/EFI/BOOT/BOOTIA32.EFI" \
"boot/grub/grub.cfg=build/tmp/grub-embed.cfg"
grub-mkstandalone -O x86_64-efi \
--modules="part_gpt part_msdos fat iso9660" \
--locales="" \
--themes="" \
--fonts="" \
--output="build/staging/EFI/BOOT/BOOTx64.EFI" \
"boot/grub/grub.cfg=build/tmp/grub-embed.cfg"
(cd build/staging && \
dd if=/dev/zero of=efiboot.img bs=1M count=20 && \
mkfs.vfat efiboot.img && \
mmd -i efiboot.img ::/EFI ::/EFI/BOOT && \
mcopy -vi efiboot.img \
build/staging/EFI/BOOT/BOOTIA32.EFI \
build/staging/EFI/BOOT/BOOTx64.EFI \
build/staging/boot/grub/grub.cfg \
::/EFI/BOOT/
)
2023-05-01 06:44:45 +02:00
message "generate .iso"
2023-05-01 05:47:12 +02:00
xorriso \
-as mkisofs \
-iso-level 3 \
2023-05-01 10:46:32 +02:00
-o "build/nanodesk_$VERSION.iso" \
2023-05-01 05:47:12 +02:00
-full-iso9660-filenames \
-volid "NANODESK" \
--mbr-force-bootable -partition_offset 16 \
-joliet -joliet-long -rational-rock \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-eltorito-boot \
isolinux/isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
--eltorito-catalog isolinux/isolinux.cat \
-eltorito-alt-boot \
-e --interval:appended_partition_2:all:: \
-no-emul-boot \
-isohybrid-gpt-basdat \
-append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B build/staging/efiboot.img \
"build/staging"