linuxmuster / linuxmuster-linbo7

Next generation linbo
GNU General Public License v3.0
9 stars 8 forks source link

refactor linbo_cmd #72

Closed HappyBasher closed 2 months ago

HappyBasher commented 2 years ago

Refactor linbo_cmd to increase maintainability splitting the big shell script into smaller ones, each one for one purpose.

HappyBasher commented 2 years ago

In the course often used system variables will be provided as environment variables through /.env so they must not be queried multiple times.

~ # cat /.env 
# linbo client environment
export PS1='\h: \w # '
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
export LINBOFULLVER="$(cat /etc/linbo-version)"
export LINBOVER="$(echo "$LINBOFULLVER" | awk '{print $2}' | sed 's|:||')"
export CACHE="$(grep -iw ^cache /start.conf | tail -1 | awk -F\= '{print $2}' | awk '{print $1}' | awk -F\# '{print $1}' | awk '{print $1}')"
export HOSTGROUP="$(grep -i ^group /start.conf | tail -1 | awk -F= '{ print $2 }' | awk '{ print $1 }')"
export SYSTEMTYPE="$(grep -iw ^SystemType /start.conf | tail -1 | awk -F= '{ print $2 }' | awk '{ print $1 }')"
export BOOT_IMAGE=/linbo64
export QUIET='yes'
export DEBUG='yes'
export NOGUI='yes'
export FORCEGRUB='yes'
export NETBOOT='yes'
export BOOT_IMAGE='/linbo64'
export BOOT_FILE='boot/grub/x86_64-efi/core.efi'
export BROADCAST='10.0.255.255'
export DNS='10.0.0.1'
export DOMAIN='linuxmuster.lan'
export HOSTNAME='multi-01'
export INTERFACE='eth0'
export IP='10.0.100.1'
export LEASE='172800'
export MASK='16'
export NTPSRV='10.0.0.1'
export OPT53='05'
export ROUTER='10.0.0.254'
export SERVERID='10.0.0.1'
export SIADDR='10.0.0.1'
export SNAME='server.linuxmuster.lan'
export SUBNET='255.255.0.0'
export FQDN='multi-01.linuxmuster.lan'
export MACADDR='96:9b:31:46:54:f3'
export LINBOSERVER='10.0.0.1'
HappyBasher commented 2 years ago

Additionally /start.conf will be splitted into easy shell parseable chunks for convenient processing, For instance:

~ # ls -1 /conf/*
/conf/linbo
/conf/os.1
/conf/os.2
/conf/part.1.sda1
/conf/part.2.sda2
/conf/part.3.sda3
/conf/part.4.sda4
/conf/part.5.sda5
HappyBasher commented 2 years ago
~ # cat /conf/linbo 

server="10.0.0.1"
group="multi"
cache="/dev/sda5"
roottimeout="600"
autopartition="no"
autoformat="no"
autoinitcache="no"
downloadtype="torrent"
guidisabled="no"
useminimallayout="no"
locale="de-de"
systemtype="efi64"
kerneloptions="quiet debug nogui forcegrub"
HappyBasher commented 2 years ago
~ # cat /conf/part.*

dev="/dev/sda1"
label="efi"
size="200M"
id="ef"
fstype="vfat"
bootable="yes"

dev="/dev/sda2"
label="msr"
size="128M"
id="0c01"
fstype=""
bootable="no"

dev="/dev/sda3"
label="windows"
size="30G"
id="7"
fstype="ntfs"
bootable="no"

dev="/dev/sda4"
label="ubuntu"
size="25G"
id="83"
fstype="ext4"
bootable="no"

dev="/dev/sda5"
label="cache"
size=""
id="83"
fstype="ext4"
bootable="no"
HappyBasher commented 2 years ago
~ # cat /conf/os.*

name="Windows 10"
version=""
description="Windows 10 1903"
iconname="win10.svg"
image=""
baseimage="win10-efi.qcow2"
boot="/dev/sda3"
root="/dev/sda3"
kernel="auto"
initrd=""
append=""
startenabled="yes"
syncenabled="yes"
newenabled="yes"
autostart="no"
autostarttimeout="15"
defaultaction="new"
hidden="yes"

name="Ubuntu"
version=""
description="Ubuntu 18.04"
iconname="ubuntu.svg"
image=""
baseimage="ubuntu1804.qcow2"
boot="/dev/sda4"
root="/dev/sda4"
kernel="vmlinuz"
initrd="initrd.img"
append="ro splash"
startenabled="yes"
syncenabled="yes"
newenabled="yes"
autostart="no"
autostarttimeout="5"
defaultaction="sync"
hidden="yes"
HappyBasher commented 2 years ago

linbo_cmd is splitted into these files in /usr/bin:

The commonly used shell functions are located in /usr/share/linbo/shell_functions, which will be sourced by the scripts.

linbo_cmd will behave as before and will now invoke these scripts to provide its functionality. So linbo_gui can use linbo_cmd as usual.

Note: Each script provides a help option.

HappyBasher commented 10 months ago

1fd8e9e78251fdb098f8b734489d6c5b295bf654 073f3471f6b7dfe8ec98ee0920b286e6561c91cc

HappyBasher commented 10 months ago
HappyBasher commented 2 months ago

Refactoring is completed.