restructered code, working now with template files instead this huge monolithic script

This commit is contained in:
Marcus 2023-05-01 20:26:40 +02:00
parent b72c4bdd8a
commit 8263e9eed0
19 changed files with 270 additions and 218 deletions

View file

@ -81,167 +81,37 @@ sudo debootstrap bullseye build/chroot/ $MIRROR || sudo debootstrap bullseye bui
message "copy xdgmenumaker deb file into chroot" message "copy xdgmenumaker deb file into chroot"
sudo cp deb/xdgmenumaker* build/chroot/tmp || error sudo cp deb/xdgmenumaker* build/chroot/tmp || error
message "deploying install_base"
cat <<\EOF > build/chroot/tmp/install_base.sh
#!/bin/bash
RED="\e[31m" message "copy template/install_base.sh to build/chroot/tmp/install_base.sh"
GREEN="\e[32m" cp templates/install_base.tpl.sh build/chroot/tmp/install_base.sh || error
YELLOW="\e[33m"
ENDCOLOR="\e[0m"
function message() { message "run install_base.sh"
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"
}
error ()
{
message error "ERROR!!"
exit 1
}
### hostname setting
echo nanodesk > /etc/hostname
### noninteractive
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
message "activate contrib and non-free repositories"
sed -i 's/main$/main contrib non-free/g' /etc/apt/sources.list || error
message "activate backports repository"
sed 's/bullseye/bullseye-backports/g' /etc/apt/sources.list > /etc/apt/sources.list.d/bullseye-backports.list || error
message "apt update"
apt update || error
### packages
message "install nanodesk base packages"
apt install -y \
live-boot \
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 \
/tmp/xdgmenumaker*.deb || error
message "install linux-kernel from backports"
apt install -t bullseye-backports -y linux-image-amd64
message "set hostname in hosts"
sed -i 's/localhost/localhost nanodesk/g' /etc/hosts
### set root password
message "set root password to 'debian'"
echo -e "debian\ndebian" | (passwd root)
### add debian user
message "create user debian"
useradd -m -U -s /bin/bash debian
### set password
message "set password for user debian to 'debian'"
echo -e "debian\ndebian" | (passwd debian)
### Configure timezone and locale
#dpkg-reconfigure locales
#dpkg-reconfigure console-data
#dpkg-reconfigure keyboard-configuration
###https://serverfault.com/a/689947
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 && \
update-locale LANG=en_US.UTF-8
### clean cache
message "apt clean"
apt clean
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$')"
test -n "$KERNEL_VER" || error
message "KERNEL_VER=$KERNEL_VER"
### but fetch packages for grub and kernel, so we do not need to download them
### 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 \
os-prober || error
EOF
message "run install_base"
$CHROOTCMD /bin/bash /tmp/install_base.sh || error $CHROOTCMD /bin/bash /tmp/install_base.sh || error
message "clear /tmp" message "clear /tmp"
$CHROOTCMD /usr/bin/rm -Rf /tmp/* || error $CHROOTCMD /usr/bin/rm -Rf /tmp/* || error
### process markdown files in src/ to html message "writing nanodesk-installer.sh into /root"
message "convert .md from src to .html in build/chroot" #first get the installed kernel version
for md in $(find src/ -name "*.md") KERNEL_VER="$($CHROOTCMD /usr/bin/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 "using Kernel $KERNEL_VER"
sed "s/%KERNEL_VER%/${KERNEL_VER}/g" templates/nanodesk-installer.tpl.sh > build/chroot/root/nanodesk-installer.sh
sudo chmod +x build/chroot/root/nanodesk-installer.sh
message "convert rootdir/usr/share/nanodesk/firstlogin/*.md to .html"
for md in $(find rootdir/ -name "*.md")
do markdown $md > $(echo $md|sed 's/\.md/\.html/') do markdown $md > $(echo $md|sed 's/\.md/\.html/')
done done
echo $VERSION > src/usr/share/nanodesk/version message "write nanodesk version $VERSION into rootdir/usr/share/nanodesk/version"
echo $VERSION > rootdir/usr/share/nanodesk/version
### copy nanodesk configs to chroot ### copy nanodesk configs to chroot
message "copy nanodesk config files into chroot" message "copy nanodesk config files into chroot"
sudo cp -r src/* build/chroot/ sudo cp -r rootdir/* build/chroot/
message "correct file permissions" message "correct file permissions"
$CHROOTCMD /usr/bin/chmod 440 /etc/sudoers $CHROOTCMD /usr/bin/chmod 440 /etc/sudoers
@ -266,76 +136,15 @@ message "copy kernel and init images"
cp build/chroot/boot/vmlinuz-* build/staging/live/vmlinuz || error cp build/chroot/boot/vmlinuz-* build/staging/live/vmlinuz || error
cp build/chroot/boot/initrd.img-* build/staging/live/initrd || error cp build/chroot/boot/initrd.img-* build/staging/live/initrd || error
message "isolinux.cfg" message "generate isolinux.cfg"
cat <<EOF >build/staging/isolinux/isolinux.cfg sed "s/%VERSION%/${VERSION}/g" templates/isolinux.tpl.cfg > build/staging/isolinux/isolinux.cfg
UI vesamenu.c32
MENU TITLE Boot Menu message "generate grub.cfg"
DEFAULT linux sed "s/%VERSION%/${VERSION}/g" templates/grub.tpl.cfg > build/staging/boot/grub/grub.cfg
TIMEOUT 600 sed "s/%VERSION%/${VERSION}/g" templates/grub.tpl.cfg > build/staging/EFI/BOOT/grub.cfg
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 message "copy grub-embed.cfg"
MENU LABEL nanodesk $VERSION Live [BIOS/ISOLINUX] cp templates/grub-embed.tpl.cfg build/tmp/grub-embed.cfg
MENU DEFAULT
KERNEL /live/vmlinuz
APPEND initrd=/live/initrd boot=live
LABEL linux
MENU LABEL nanodesk $VERSION Live [BIOS/ISOLINUX] (nomodeset)
MENU DEFAULT
KERNEL /live/vmlinuz
APPEND initrd=/live/initrd boot=live nomodeset
EOF
cat <<EOF > build/staging/boot/grub/grub.cfg
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.
menuentry "nanodesk $VERSION Live [EFI/GRUB]" {
search --no-floppy --set=root --label NANODESK
linux (\$root)/live/vmlinuz boot=live
initrd (\$root)/live/initrd
}
menuentry "nanodesk $VERSION Live [EFI/GRUB] (nomodeset)" {
search --no-floppy --set=root --label NANODESK
linux (\$root)/live/vmlinuz boot=live nomodeset
initrd (\$root)/live/initrd
}
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
message "copy isolinux" message "copy isolinux"
cp /usr/lib/ISOLINUX/isolinux.bin "build/staging/isolinux/" || error cp /usr/lib/ISOLINUX/isolinux.bin "build/staging/isolinux/" || error

View file

@ -0,0 +1,38 @@
<h1>Welcome to nanodesk</h1>
<p>nanodesk is a debian base linux "distribution". I put distribution in ""
becuase it is just a minimal debian debootstrap installation, which you
can boot from a DVD or usb-stick and install it to disk, with well picked
packages I like and a customized jwm config. Taddaa - a new distribution. </p>
<p>Everything done with having the goal to consume as less ram as possible.</p>
<h2>install to disk</h2>
<p>You can install nanodesk to your harddrive. Before doing so,
you have to get your drive partitioned and formated. </p>
<p>Partiotioning on an empty drive is simple, you need two partitions</p>
<ul>
<li>partition1: ext4 , mainfilesystem. </li>
<li>partition2 (optional, but recommended): swap</li>
</ul>
<p>You can use <code>gparted</code> or <code>fdisk</code> for this. Please read their manuals.</p>
<p>This done, just run <code>sudo /root/install_nanodesk.sh /dev/sdXY</code> from the terminal
and the installation will start. (change /dev/sdXY to your drive)</p>
<h2>installing software</h2>
<p>There is no GUI tool for installing software. You have to use <code>apt</code> from the
terminal.</p>
<h2>getting root</h2>
<p>In the LiveCD mode you can just do <code>sudo su -</code> without being asked for a password.
Depending on your choice by the installation, you will have to enter a password,
when you created your own using by the installer.</p>
<p>So or so good old <code>su -</code> works fine as well, just type in the root password.</p>

View file

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

View file

@ -0,0 +1 @@
v0.1.3-11-g2b670a8

View file

@ -0,0 +1,8 @@
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"

24
templates/grub.tpl.cfg Normal file
View file

@ -0,0 +1,24 @@
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.
menuentry "nanodesk %VERSION% Live [EFI/GRUB]" {
search --no-floppy --set=root --label NANODESK
linux (\$root)/live/vmlinuz boot=live
initrd (\$root)/live/initrd
}
menuentry "nanodesk %VERSION% Live [EFI/GRUB] (nomodeset)" {
search --no-floppy --set=root --label NANODESK
linux (\$root)/live/vmlinuz boot=live nomodeset
initrd (\$root)/live/initrd
}

View file

@ -0,0 +1,145 @@
#!/bin/bash
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"
}
error ()
{
message error "ERROR!!"
exit 1
}
### hostname setting
echo nanodesk > /etc/hostname
### noninteractive
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
message "activate contrib and non-free repositories"
sed -i 's/main$/main contrib non-free/g' /etc/apt/sources.list || error
message "activate backports repository"
sed 's/bullseye/bullseye-backports/g' /etc/apt/sources.list > /etc/apt/sources.list.d/bullseye-backports.list || error
message "apt update"
apt update || error
### packages
message "install nanodesk base packages"
apt install -y \
live-boot \
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 \
/tmp/xdgmenumaker*.deb || error
message "install linux-kernel from backports"
apt install -t bullseye-backports -y linux-image-amd64
message "set hostname in hosts"
sed -i 's/localhost/localhost nanodesk/g' /etc/hosts
### set root password
message "set root password to 'debian'"
echo -e "debian\ndebian" | (passwd root)
### add debian user
message "create user debian"
useradd -m -U -s /bin/bash debian
### set password
message "set password for user debian to 'debian'"
echo -e "debian\ndebian" | (passwd debian)
### Configure timezone and locale
#dpkg-reconfigure locales
#dpkg-reconfigure console-data
#dpkg-reconfigure keyboard-configuration
###https://serverfault.com/a/689947
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 && \
update-locale LANG=en_US.UTF-8
### clean cache
message "apt clean"
apt clean
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$')"
test -n "$KERNEL_VER" || error
message "KERNEL_VER=$KERNEL_VER"
### but fetch packages for grub and kernel, so we do not need to download them
### 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 \
os-prober || error

View file

@ -0,0 +1,27 @@
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
MENU LABEL nanodesk %VERSION% Live [BIOS/ISOLINUX]
MENU DEFAULT
KERNEL /live/vmlinuz
APPEND initrd=/live/initrd boot=live
LABEL linux
MENU LABEL nanodesk %VERSION% Live [BIOS/ISOLINUX] (nomodeset)
MENU DEFAULT
KERNEL /live/vmlinuz
APPEND initrd=/live/initrd boot=live nomodeset

View file

@ -124,8 +124,8 @@ DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND export DEBIAN_FRONTEND
#/usr/bin/apt --yes purge 'linux-image-*' 'grub-*' #/usr/bin/apt --yes purge 'linux-image-*' 'grub-*'
/usr/bin/apt --yes --reinstall install \ /usr/bin/apt --yes --reinstall install \
linux-image-amd64 \ linux-image-amd64 \
linux-image-5.10.0-22-amd64 \ %KERNEL_VER% \
grub-pc grub-pc-bin \ grub-pc grub-pc-bin \
grub-common \ grub-common \
grub2-common \ grub2-common \