@ -400,12 +400,21 @@ function chroot_umount_fs() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
set +e
set +e
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
umount $BUILD_DIR/proc
umount $BUILD_DIR/sys
umount $BUILD_DIR/dev/pts
umount $BUILD_DIR/tmp
umount $BUILD_DIR/dev
umount $BUILD_DIR/run
else
umount $BUILD_DIR/proc >>$OUTPUT 2>&1
umount $BUILD_DIR/proc >>$OUTPUT 2>&1
umount $BUILD_DIR/sys >>$OUTPUT 2>&1
umount $BUILD_DIR/sys >>$OUTPUT 2>&1
umount $BUILD_DIR/dev/pts >>$OUTPUT 2>&1
umount $BUILD_DIR/dev/pts >>$OUTPUT 2>&1
umount $BUILD_DIR/tmp >>$OUTPUT 2>&1
umount $BUILD_DIR/tmp >>$OUTPUT 2>&1
umount $BUILD_DIR/dev >>$OUTPUT 2>&1
umount $BUILD_DIR/dev >>$OUTPUT 2>&1
umount $BUILD_DIR/run >>$OUTPUT 2>&1
umount $BUILD_DIR/run >>$OUTPUT 2>&1
fi
set -e
set -e
check_mounted
check_mounted
@ -531,6 +540,10 @@ function build_bootstrap() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function copy_build_scripts() {
function copy_build_scripts() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
if [ ! -d $BUILD_DIR/linux-live ]; then
if [ ! -d $BUILD_DIR/linux-live ]; then
@ -538,11 +551,19 @@ function copy_build_scripts() {
(cd $SCRIPT_DIR/linux-live && cp --parents -afr * $BUILD_DIR/linux-live)
(cd $SCRIPT_DIR/linux-live && cp --parents -afr * $BUILD_DIR/linux-live)
else
else
find $SCRIPT_DIR/linux-live -type f -print0 | sed "s,$SCRIPT_DIR/linux-live/,,g" | while IFS= read -r -d '' file; do
find $SCRIPT_DIR/linux-live -type f -print0 | sed "s,$SCRIPT_DIR/linux-live/,,g" | while IFS= read -r -d '' file; do
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
if ! cmp $SCRIPT_DIR/linux-live/"$file" $BUILD_DIR/linux-live/"$file"; then
echo -e "$file has been modified since last build run."
echo -e "Copying $SCRIPT_DIR/linux-live/$file to $BUILD_DIR/linux-live/$file..."
cp -f $SCRIPT_DIR/linux-live/"$file" $BUILD_DIR/linux-live/"$file"
fi
else
if ! cmp $SCRIPT_DIR/linux-live/"$file" $BUILD_DIR/linux-live/"$file" >>$OUTPUT 2>&1; then
if ! cmp $SCRIPT_DIR/linux-live/"$file" $BUILD_DIR/linux-live/"$file" >>$OUTPUT 2>&1; then
echo -e "$file has been modified since last build run." >>$OUTPUT 2>&1
echo -e "$file has been modified since last build run." >>$OUTPUT 2>&1
echo -e "Copying $SCRIPT_DIR/linux-live/$file to $BUILD_DIR/linux-live/$file..." >>$OUTPUT 2>&1
echo -e "Copying $SCRIPT_DIR/linux-live/$file to $BUILD_DIR/linux-live/$file..." >>$OUTPUT 2>&1
cp -f $SCRIPT_DIR/linux-live/"$file" $BUILD_DIR/linux-live/"$file" >>$OUTPUT 2>&1
cp -f $SCRIPT_DIR/linux-live/"$file" $BUILD_DIR/linux-live/"$file" >>$OUTPUT 2>&1
fi
fi
fi
done
done
fi
fi
@ -565,6 +586,10 @@ function copy_build_scripts() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function build_chroot() {
function build_chroot() {
current_process
current_process
@ -618,6 +643,10 @@ function build_chroot() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function build_live() {
function build_live() {
current_process
current_process
@ -668,6 +697,10 @@ function build_live() {
}
}
# =================================================================
#
#
# =================================================================
function build_iso() {
function build_iso() {
current_process
current_process
@ -738,29 +771,16 @@ function build_iso() {
exit 0
exit 0
}
}
function batch_run() {
current_process
chroot $1 /usr/bin/env \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
BUILD_TEST_ISO=$BUILD_TEST_ISO \
CREATE_BACKUP=$CREATE_BACKUP \
DEBIAN_FRONTEND_TYPE=$DEBIAN_FRONTEND_TYPE \
APT_CMD=$APT_CMD \
APT_OPTIONS=$APT_OPTIONS \
APT_OPTIONS2=$APT_OPTIONS2 \
LIVE_TYPE=$LIVE_TYPE \
sudo DEBIAN_FRONTEND=$DEBIAN_FRONTEND_TYPE \
$2
}
# =================================================================
# =================================================================
# =================================================================
# =================================================================
# ====================== INSTALL FUNCTIONS ========================
# ====================== INSTALL FUNCTIONS ========================
# =================================================================
# =================================================================
# =================================================================
# =================================================================
# =================================================================
#
#
# =================================================================
function setup_host() {
function setup_host() {
current_process
current_process
@ -769,6 +789,10 @@ function setup_host() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function chroot_setup_host() {
function chroot_setup_host() {
current_process
current_process
@ -787,77 +811,81 @@ function chroot_setup_host() {
current_process
current_process
}
}
function build_cleanup() {
# =================================================================
#
#
# =================================================================
function chroot_build_cleanup() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
set +e
set +e
rm -f $MODULE_UPPER_DIR /preinstall >>$OUTPUT 2>&1
rm -f /preinstall >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR /install >>$OUTPUT 2>&1
rm -f /install >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR /install2 >>$OUTPUT 2>&1
rm -f /install2 >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR /cleanup >>$OUTPUT 2>&1
rm -f /cleanup >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR /package.list >>$OUTPUT 2>&1
rm -f /package.list >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR /postinstall >>$OUTPUT 2>&1
rm -f /postinstall >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR /rootcopy >>$OUTPUT 2>&1
rm -rf /rootcopy >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR /patches >>$OUTPUT 2>&1
rm -rf /patches >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/fstab >>$OUTPUT 2>&1
rm -f /etc/fstab >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/mtab >>$OUTPUT 2>&1
rm -f /etc/mtab >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/apt/sources.list~ >>$OUTPUT 2>&1
rm -f /etc/apt/sources.list~ >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/etc/systemd/system/timers.target.wants >>$OUTPUT 2>&1
rm -Rf /etc/systemd/system/timers.target.wants >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/systemd/system/multi-user.target.wants/ssh.service >>$OUTPUT 2>&1
rm -f /etc/systemd/system/multi-user.target.wants/ssh.service >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/systemd/system/multi-user.target.wants/dnsmasq.service >>$OUTPUT 2>&1
rm -f /etc/systemd/system/multi-user.target.wants/dnsmasq.service >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/ssh/ssh_host* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/backups/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/ldconfig/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/debconf/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/fontconfig/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/apt/extended_states >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/systemd/random-seed >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/deb.* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/root/.local/share/mc >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/root/.cache >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.wget-hsts >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/dpkg/*-old >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/log/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/log/*/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/log/*/*/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/apt/archives/*.deb >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/apt/*.bin >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/debconf/*-old >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/dhcp/dhclient.leases >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.bash_history >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.wget-hsts >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/doc/* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/info/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/usr/share/images/fluxbox/debian-squared.jpg >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/fluxbox/nls/??* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/gnome/help >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/?? >>$OUTPUT 2>&1
rm -f /etc/ssh/ssh_host* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??_* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??@* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??? >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/i18n/locales/*_* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/man/?? >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/man/*_* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/icons/elementaryXubuntu-dark >>$OUTPUT 2>&1
rm -f /var/backups/* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/icons/gnome/256x256 >>$OUTPUT 2>&1
rm -f /var/cache/ldconfig/* >>$OUTPUT 2>&1
rm -f /var/cache/debconf/* >>$OUTPUT 2>&1
rm -f /var/cache/fontconfig/* >>$OUTPUT 2>&1
rm -f /var/lib/apt/extended_states >>$OUTPUT 2>&1
rm -f /var/lib/systemd/random-seed >>$OUTPUT 2>&1
rm -f /var/lib/apt/lists/deb.* >>$OUTPUT 2>&1
rm -Rf /root/.local/share/mc >>$OUTPUT 2>&1
rm -Rf /root/.cache >>$OUTPUT 2>&1
rm -f /root/.wget-hsts >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/compton.desktop >>$OUTPUT 2>&1
rm -f /var/lib/dpkg/*-old >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/debian-uxterm.desktop >>$OUTPUT 2>&1
rm -f /var/log/* >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/debian-xterm.desktop >>$OUTPUT 2>&1
rm -f /var/log/*/* >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/htop.desktop >>$OUTPUT 2>&1
rm -f /var/log/*/*/* >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/mc.desktop >>$OUTPUT 2>&1
rm -f /var/cache/apt/archives/*.deb >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/mcedit.desktop >>$OUTPUT 2>&1
rm -f /var/cache/apt/*.bin >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/pcmanfm-desktop-pref.desktop >>$OUTPUT 2>&1
rm -f /var/cache/debconf/*-old >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/python2.7.desktop >>$OUTPUT 2>&1
rm -f /var/lib/dhcp/dhclient.leases >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/python3.7.desktop >>$OUTPUT 2>&1
rm -f /root/.bash_history >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/vim.desktop >>$OUTPUT 2>&1
rm -f /root/.wget-hsts >>$OUTPUT 2>&1
rm -Rf /usr/share/doc/* >>$OUTPUT 2>&1
rm -Rf /usr/share/info/* >>$OUTPUT 2>&1
rm -f /usr/share/images/fluxbox/debian-squared.jpg >>$OUTPUT 2>&1
rm -Rf /usr/share/fluxbox/nls/??* >>$OUTPUT 2>&1
rm -Rf /usr/share/gnome/help >>$OUTPUT 2>&1
rm -Rf /usr/share/locale/?? >>$OUTPUT 2>&1
rm -Rf /usr/share/locale/??_* >>$OUTPUT 2>&1
rm -Rf /usr/share/locale/??@* >>$OUTPUT 2>&1
rm -Rf /usr/share/locale/??? >>$OUTPUT 2>&1
rm -Rf /usr/share/i18n/locales/*_* >>$OUTPUT 2>&1
rm -Rf /usr/share/man/?? >>$OUTPUT 2>&1
rm -Rf /usr/share/man/*_* >>$OUTPUT 2>&1
rm -Rf /usr/share/icons/elementaryXubuntu-dark >>$OUTPUT 2>&1
rm -Rf /usr/share/icons/gnome/256x256 >>$OUTPUT 2>&1
rm /usr/share/applications/compton.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/debian-uxterm.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/debian-xterm.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/htop.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/mc.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/mcedit.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/pcmanfm-desktop-pref.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/python2.7.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/python3.7.desktop >>$OUTPUT 2>&1
rm /usr/share/applications/vim.desktop >>$OUTPUT 2>&1
# Unzip gzipped files (man pages), so LZMA can compress 2times better.
# Unzip gzipped files (man pages), so LZMA can compress 2times better.
# First we fix symlinks, then uncompress files
# First we fix symlinks, then uncompress files
@ -874,8 +902,8 @@ function build_cleanup() {
find "$1" -type f -name "*.gz" | xargs -r gunzip >>$OUTPUT 2>&1
find "$1" -type f -name "*.gz" | xargs -r gunzip >>$OUTPUT 2>&1
}
}
uncompress_files $MODULE_UPPER_DIR /etc/alternatives >>$OUTPUT 2>&1
uncompress_files /etc/alternatives >>$OUTPUT 2>&1
uncompress_files $MODULE_UPPER_DIR /usr/share/man >>$OUTPUT 2>&1
uncompress_files /usr/share/man >>$OUTPUT 2>&1
# remove broken links
# remove broken links
# $1 = search directory
# $1 = search directory
@ -883,13 +911,17 @@ function build_cleanup() {
find "$1" -type l -exec test ! -e {} \; -print | xargs rm -vf >>$OUTPUT 2>&1
find "$1" -type l -exec test ! -e {} \; -print | xargs rm -vf >>$OUTPUT 2>&1
}
}
remove_broken_links $MODULE_UPPER_DIR /etc/alternatives >>$OUTPUT 2>&1
remove_broken_links /etc/alternatives >>$OUTPUT 2>&1
remove_broken_links $MODULE_UPPER_DIR /usr/share/man >>$OUTPUT 2>&1
remove_broken_links /usr/share/man >>$OUTPUT 2>&1
set -e
set -e
}
}
# =================================================================
#
#
# =================================================================
function hostreq_pkg_list() {
function hostreq_pkg_list() {
echo -e "${YELLOW}=====> installing required software for host system ...${ENDCOLOUR}"
echo -e "${YELLOW}=====> installing required software for host system ...${ENDCOLOUR}"
$APT_CMD update >>$OUTPUT 2>&1
$APT_CMD update >>$OUTPUT 2>&1
@ -902,6 +934,10 @@ function hostreq_pkg_list() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function prereq_pkg_list() {
function prereq_pkg_list() {
echo -e "${YELLOW}=====> installing prerequested software for chroot system ...${ENDCOLOUR}"
echo -e "${YELLOW}=====> installing prerequested software for chroot system ...${ENDCOLOUR}"
@ -915,6 +951,10 @@ function prereq_pkg_list() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function main_pkg_list() {
function main_pkg_list() {
echo -e "${YELLOW}=====> installing main packages for chroot system ...${ENDCOLOUR}"
echo -e "${YELLOW}=====> installing main packages for chroot system ...${ENDCOLOUR}"
@ -929,9 +969,9 @@ function main_pkg_list() {
LIVE_TYPE=$LIVE_TYPE \
LIVE_TYPE=$LIVE_TYPE \
/linux-live/basesystem/01-core/preinstall
/linux-live/basesystem/01-core/preinstall
fi
fi
if [ "$(ls -A /linux-live/basesystem/01-core/rootcopy)" != "" ]; then
: ' if [ "$(ls -A /linux-live/basesystem/01-core/rootcopy)" != "" ]; then
(cd /linux-live/basesystem/01-core/rootcopy && cp --parents -afr * /)
(cd /linux-live/basesystem/01-core/rootcopy && cp --parents -afr * /)
fi
fi'
if [ -f /linux-live/basesystem/01-core/install ]; then
if [ -f /linux-live/basesystem/01-core/install ]; then
chmod +x /linux-live/basesystem/01-core/install
chmod +x /linux-live/basesystem/01-core/install
/usr/bin/env \
/usr/bin/env \
@ -955,9 +995,13 @@ function main_pkg_list() {
/linux-live/basesystem/01-core/postinstall
/linux-live/basesystem/01-core/postinstall
fi
fi
build_cleanup
chroot_ build_cleanup
}
}
# =================================================================
#
#
# =================================================================
function chroot_pkg_install() {
function chroot_pkg_install() {
current_process
current_process
@ -970,11 +1014,13 @@ function chroot_pkg_install() {
$APT_CMD clean $APT_OPTIONS >>$OUTPUT 2>&1
$APT_CMD clean $APT_OPTIONS >>$OUTPUT 2>&1
}
}
# =================================================================
#
#
# =================================================================
function chroot_configure() {
function chroot_configure() {
current_process
current_process
(cd /linux-live/basesystem/01-core/rootcopy && cp --parents -afr * /)
echo "Set up password for user 'root'" >>$OUTPUT 2>&1
echo "Set up password for user 'root'" >>$OUTPUT 2>&1
echo root:toor | chpasswd >>$OUTPUT 2>&1
echo root:toor | chpasswd >>$OUTPUT 2>&1
@ -985,34 +1031,18 @@ function chroot_configure() {
addgroup live adm >>$OUTPUT 2>&1
addgroup live adm >>$OUTPUT 2>&1
addgroup live sudo >>$OUTPUT 2>&1
addgroup live sudo >>$OUTPUT 2>&1
(cd /linux-live/basesystem/01-core/rootcopy && cp --parents -afr * /)
chown live:live /home/live
chown -R live:live /home/live
cat <<EOF >/etc/sudoers.d/90-minios
cat <<EOF >/etc/sudoers.d/90-minios
# live user is default user in minios.
# live user is default user in minios.
# It needs passwordless sudo functionality.
# It needs passwordless sudo functionality.
live ALL=(ALL) NOPASSWD:ALL
live ALL=(ALL) NOPASSWD:ALL
EOF
EOF
if [ ! -d /etc/NetworkManager ]; then
echo "Enable dhclient.service autostart." >>$OUTPUT 2>&1
cat <<EOF >/lib/systemd/system/dhclient.service
[Unit]
Description=DHCP Client
Documentation=man:dhclient(8)
Wants=network.target
After=network-pre.target systemd-sysctl.service systemd-modules-load.service
Before=network.target shutdown.target network-online.target
ConditionPathExists=!/run/initramfs/net.up.flag
[Service]
Type=forking
ExecStart=-/bin/sh -c 'udevadm settle && dhclient -nw'
PIDFile=/run/dhclient.pid
[Install]
WantedBy=multi-user.target
WantedBy=network-online.target
EOF
systemctl enable dhclient >>$OUTPUT 2>&1
systemctl enable dhclient >>$OUTPUT 2>&1
fi
if [ -f /etc/systemd/system/multi-user.target.wants/grub-initrd-fallback.service ]; then
if [ -f /etc/systemd/system/multi-user.target.wants/grub-initrd-fallback.service ]; then
echo "Disable grub-initrd-fallback.service autostart."
echo "Disable grub-initrd-fallback.service autostart."
@ -1021,7 +1051,7 @@ EOF
if grep openssh-server $SCRIPT_DIR/basesystem/01-core/package.list >>$OUTPUT 2>&1; then
if grep openssh-server $SCRIPT_DIR/basesystem/01-core/package.list >>$OUTPUT 2>&1; then
echo "Enable ssh.service autostart." >>$OUTPUT 2>&1
echo "Enable ssh.service autostart." >>$OUTPUT 2>&1
cat <<EOF >/lib/systemd/system/ssh-keygen.service
cat <<EOF >/usr/ lib/systemd/system/ssh-keygen.service
[Unit]
[Unit]
Description=Generate sshd keys
Description=Generate sshd keys
Before=ssh.service
Before=ssh.service
@ -1072,45 +1102,14 @@ EOF
EOF
else
cat <<EOF >/etc/issue
\l
Thank you for using MiniOS.
Based on Ubuntu.
:::: :::: ::::::::::: :::: ::: ::::::::::: :::::::: ::::::::
+:+:+: :+:+:+ :+: :+:+: :+: :+: :+: :+: :+: :+:
+:+ +:+:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+
+#+ +:+ +#+ +#+ +#+ +:+ +#+ +#+ +#+ +:+ +#++:++#++
+#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+#+# #+# #+# #+# #+# #+#
### ### ########### ### #### ########### ######## ########
: :
: Root login name: [1;33mroot[0;29m :
: Password: [1;33mtoor[0;29m :
: User login name: [1;33mlive[0;29m :
: Password: [1;33mevil[0;29m :
EOF
EOF
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function chroot_finish_up() {
function chroot_finish_up() {
current_process
current_process
@ -1154,6 +1153,10 @@ function chroot_finish_up() {
# =================================================================
# =================================================================
# =================================================================
# =================================================================
# =================================================================
#
#
# =================================================================
function module_check_mounted() {
function module_check_mounted() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
if grep -qs "$MODULE_MERGED_DIR" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/dev" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/run" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/proc" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/sys" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/dev/pts" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/tmp" /proc/mounts; then
if grep -qs "$MODULE_MERGED_DIR" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/dev" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/run" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/proc" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/sys" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/dev/pts" /proc/mounts || grep -qs "$MODULE_MERGED_DIR/tmp" /proc/mounts; then
@ -1172,6 +1175,10 @@ function module_check_mounted() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function module_check_build_dir() {
function module_check_build_dir() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
if [ "$UNATTENDED" = "1" ]; then
if [ "$UNATTENDED" = "1" ]; then
@ -1195,6 +1202,10 @@ function module_check_build_dir() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function module_chroot_mount_fs() {
function module_chroot_mount_fs() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
@ -1262,12 +1273,31 @@ function module_chroot_mount_fs() {
mount none -t tmpfs $MODULE_MERGED_DIR/tmp
mount none -t tmpfs $MODULE_MERGED_DIR/tmp
}
}
# =================================================================
#
#
# =================================================================
function module_chroot_umount_fs() {
function module_chroot_umount_fs() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
local MODULES MODULE_LOWER_DIR
local MODULES MODULE_LOWER_DIR
set +e
set +e
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
umount $MODULE_MERGED_DIR/proc
umount $MODULE_MERGED_DIR/sys
umount $MODULE_MERGED_DIR/dev/pts
umount $MODULE_MERGED_DIR/tmp
umount $MODULE_MERGED_DIR/dev
if [ -f /.dockerenv ] || [ "$container" = "podman" ]; then
umount $MODULE_MERGED_DIR/run/resolvconf/resolv.conf
rm -f $MODULE_MERGED_DIR/run/resolvconf/resolv.conf
rmdir $MODULE_MERGED_DIR/run/resolvconf
else
umount $MODULE_MERGED_DIR/run
fi
umount $MODULE_MERGED_DIR
else
umount $MODULE_MERGED_DIR/proc >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR/proc >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR/sys >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR/sys >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR/dev/pts >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR/dev/pts >>$OUTPUT 2>&1
@ -1281,18 +1311,23 @@ function module_chroot_umount_fs() {
umount $MODULE_MERGED_DIR/run >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR/run >>$OUTPUT 2>&1
fi
fi
umount $MODULE_MERGED_DIR >>$OUTPUT 2>&1
umount $MODULE_MERGED_DIR >>$OUTPUT 2>&1
#set -e
fi
MODULES=($PARENT_DIR/image/$LIVEKITNAME/*.$BEXT)
MODULES=($PARENT_DIR/image/$LIVEKITNAME/*.$BEXT)
for ((i = ${#MODULES[@]} - 1; i >= 0; i--)); do
for ((i = ${#MODULES[@]} - 1; i >= 0; i--)); do
MODULE_LOWER_DIR=$(basename ${MODULES[$i]} .$BEXT)
MODULE_LOWER_DIR=$(basename ${MODULES[$i]} .$BEXT)
umount $MODULES_DIR/lower/$MODULE_LOWER_DIR-lower
umount $MODULES_DIR/lower/$MODULE_LOWER_DIR-lower
done
done
set -e
set -e
module_check_mounted
module_check_mounted
}
}
# =================================================================
#
#
# =================================================================
function module_cleanup() {
function module_cleanup() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
if [ "$UNATTENDED" = "1" ]; then
if [ "$UNATTENDED" = "1" ]; then
@ -1317,6 +1352,10 @@ function module_cleanup() {
fi
fi
}
}
# =================================================================
#
#
# =================================================================
function module_chroot_finish_up() {
function module_chroot_finish_up() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
@ -1326,15 +1365,53 @@ truncate -s 0 /etc/machine-id
EOF
EOF
# remove diversion (why??)
# remove diversion (why??)
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
chroot $MODULE_MERGED_DIR /bin/bash -x <<EOF
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl
EOF
else
chroot $MODULE_MERGED_DIR /bin/bash -x <<EOF
chroot $MODULE_MERGED_DIR /bin/bash -x <<EOF
rm /sbin/initctl >>$OUTPUT 2>&1
rm /sbin/initctl >>$OUTPUT 2>&1
dpkg-divert --rename --remove /sbin/initctl >>$OUTPUT 2>&1
dpkg-divert --rename --remove /sbin/initctl >>$OUTPUT 2>&1
EOF
EOF
fi
}
}
# =================================================================
#
#
# =================================================================
function module_chroot_cleanup() {
function module_chroot_cleanup() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
# clean up useless stuff
# clean up useless stuff
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
rm -rf $MODULE_UPPER_DIR/boot $MODULE_UPPER_DIR/dev $MODULE_UPPER_DIR/proc $MODULE_UPPER_DIR/sys $MODULE_UPPER_DIR/rmp $MODULE_UPPER_DIR/run
rm -f $MODULE_UPPER_DIR/root/.bash_history
rm -rf $MODULE_UPPER_DIR/.cache
find $MODULE_UPPER_DIR/var/log/ -type f | xargs rm -f
rm -f $MODULE_UPPER_DIR/etc/ssh/ssh_host*
rm -f $MODULE_UPPER_DIR/var/backups/*
rm -f $MODULE_UPPER_DIR/var/cache/ldconfig/*
#rm -f $MODULE_UPPER_DIR/var/cache/debconf/*
rm -f $MODULE_UPPER_DIR/var/cache/fontconfig/*
rm -f $MODULE_UPPER_DIR/var/cache/apt/archives/*.deb
rm -f $MODULE_UPPER_DIR/var/cache/apt/*.bin
rm -f $MODULE_UPPER_DIR/var/cache/debconf/*-old
rm -f $MODULE_UPPER_DIR/var/lib/apt/extended_states
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/*Packages
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/*Translation*
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/*InRelease
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/deb.*
rm -f $MODULE_UPPER_DIR/var/lib/dpkg/*-old
rm -f $MODULE_UPPER_DIR/preinstall
rm -f $MODULE_UPPER_DIR/install
rm -f $MODULE_UPPER_DIR/install2
rm -f $MODULE_UPPER_DIR/cleanup
rm -f $MODULE_UPPER_DIR/package.list
rm -f $MODULE_UPPER_DIR/postinstall
rm -rf $MODULE_UPPER_DIR/rootcopy
else
rm -rf $MODULE_UPPER_DIR/boot $MODULE_UPPER_DIR/dev $MODULE_UPPER_DIR/proc $MODULE_UPPER_DIR/sys $MODULE_UPPER_DIR/rmp $MODULE_UPPER_DIR/run
rm -rf $MODULE_UPPER_DIR/boot $MODULE_UPPER_DIR/dev $MODULE_UPPER_DIR/proc $MODULE_UPPER_DIR/sys $MODULE_UPPER_DIR/rmp $MODULE_UPPER_DIR/run
rm -f $MODULE_UPPER_DIR/root/.bash_history >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.bash_history >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR/.cache
rm -rf $MODULE_UPPER_DIR/.cache
@ -1360,8 +1437,216 @@ function module_chroot_cleanup() {
rm -f $MODULE_UPPER_DIR/package.list >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/package.list >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/postinstall >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/postinstall >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR/rootcopy >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR/rootcopy >>$OUTPUT 2>&1
fi
}
# =================================================================
#
#
# =================================================================
function module_build_cleanup() {
echo -e "=====> the ${CYAN}${FUNCNAME[0]}${ENDCOLOUR} function is executing ..."
set +e
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
rm -f $MODULE_UPPER_DIR/preinstall
rm -f $MODULE_UPPER_DIR/install
rm -f $MODULE_UPPER_DIR/install2
rm -f $MODULE_UPPER_DIR/cleanup
rm -f $MODULE_UPPER_DIR/package.list
rm -f $MODULE_UPPER_DIR/postinstall
rm -rf $MODULE_UPPER_DIR/rootcopy
rm -rf $MODULE_UPPER_DIR/patches
rm -f $MODULE_UPPER_DIR/etc/fstab
rm -f $MODULE_UPPER_DIR/etc/mtab
rm -f $MODULE_UPPER_DIR/etc/apt/sources.list~
rm -Rf $MODULE_UPPER_DIR/etc/systemd/system/timers.target.wants
rm -f $MODULE_UPPER_DIR/etc/systemd/system/multi-user.target.wants/ssh.service
rm -f $MODULE_UPPER_DIR/etc/systemd/system/multi-user.target.wants/dnsmasq.service
rm -f $MODULE_UPPER_DIR/etc/ssh/ssh_host*
rm -f $MODULE_UPPER_DIR/var/backups/*
rm -f $MODULE_UPPER_DIR/var/cache/ldconfig/*
rm -f $MODULE_UPPER_DIR/var/cache/debconf/*
rm -f $MODULE_UPPER_DIR/var/cache/fontconfig/*
rm -f $MODULE_UPPER_DIR/var/lib/apt/extended_states
rm -f $MODULE_UPPER_DIR/var/lib/systemd/random-seed
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/deb.*
rm -Rf $MODULE_UPPER_DIR/root/.local/share/mc
rm -Rf $MODULE_UPPER_DIR/root/.cache
rm -f $MODULE_UPPER_DIR/root/.wget-hsts
rm -f $MODULE_UPPER_DIR/var/lib/dpkg/*-old
rm -f $MODULE_UPPER_DIR/var/log/*
rm -f $MODULE_UPPER_DIR/var/log/*/*
rm -f $MODULE_UPPER_DIR/var/log/*/*/*
rm -f $MODULE_UPPER_DIR/var/cache/apt/archives/*.deb
rm -f $MODULE_UPPER_DIR/var/cache/apt/*.bin
rm -f $MODULE_UPPER_DIR/var/cache/debconf/*-old
rm -f $MODULE_UPPER_DIR/var/lib/dhcp/dhclient.leases
rm -f $MODULE_UPPER_DIR/root/.bash_history
rm -f $MODULE_UPPER_DIR/root/.wget-hsts
rm -Rf $MODULE_UPPER_DIR/usr/share/doc/*
rm -Rf $MODULE_UPPER_DIR/usr/share/info/*
rm -f $MODULE_UPPER_DIR/usr/share/images/fluxbox/debian-squared.jpg
rm -Rf $MODULE_UPPER_DIR/usr/share/fluxbox/nls/??*
rm -Rf $MODULE_UPPER_DIR/usr/share/gnome/help
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??_*
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??@*
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/???
rm -Rf $MODULE_UPPER_DIR/usr/share/i18n/locales/*_*
rm -Rf $MODULE_UPPER_DIR/usr/share/man/??
rm -Rf $MODULE_UPPER_DIR/usr/share/man/*_*
rm -Rf $MODULE_UPPER_DIR/usr/share/icons/elementaryXubuntu-dark
rm -Rf $MODULE_UPPER_DIR/usr/share/icons/gnome/256x256
rm $MODULE_UPPER_DIR/usr/share/applications/compton.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/debian-uxterm.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/debian-xterm.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/htop.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/mc.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/mcedit.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/pcmanfm-desktop-pref.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/python2.7.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/python3.7.desktop
rm $MODULE_UPPER_DIR/usr/share/applications/vim.desktop
# Unzip gzipped files (man pages), so LZMA can compress 2times better.
# First we fix symlinks, then uncompress files
# $1 = search directory
uncompress_files() {
local LINK LINE
find "$1" -type l -name "*.gz" | while read LINE; do
LINK="$(readlink "$LINE" | sed -r 's/.gz$//')"
FILE="$(echo "$LINE" | sed -r 's/.gz$//')"
ln -sfn "$LINK" "$FILE"
rm -f "$LINE"
done
find "$1" -type f -name "*.gz" | xargs -r gunzip
}
uncompress_files $MODULE_UPPER_DIR/etc/alternatives
uncompress_files $MODULE_UPPER_DIR/usr/share/man
# remove broken links
# $1 = search directory
remove_broken_links() {
find "$1" -type l -exec test ! -e {} \; -print | xargs rm -vf
}
remove_broken_links $MODULE_UPPER_DIR/etc/alternatives
remove_broken_links $MODULE_UPPER_DIR/usr/share/man
else
rm -f $MODULE_UPPER_DIR/preinstall >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/install >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/install2 >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/cleanup >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/package.list >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/postinstall >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR/rootcopy >>$OUTPUT 2>&1
rm -rf $MODULE_UPPER_DIR/patches >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/fstab >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/mtab >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/apt/sources.list~ >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/etc/systemd/system/timers.target.wants >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/systemd/system/multi-user.target.wants/ssh.service >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/systemd/system/multi-user.target.wants/dnsmasq.service >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/etc/ssh/ssh_host* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/backups/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/ldconfig/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/debconf/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/fontconfig/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/apt/extended_states >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/systemd/random-seed >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/apt/lists/deb.* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/root/.local/share/mc >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/root/.cache >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.wget-hsts >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/dpkg/*-old >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/log/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/log/*/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/log/*/*/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/apt/archives/*.deb >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/apt/*.bin >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/cache/debconf/*-old >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/var/lib/dhcp/dhclient.leases >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.bash_history >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/root/.wget-hsts >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/doc/* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/info/* >>$OUTPUT 2>&1
rm -f $MODULE_UPPER_DIR/usr/share/images/fluxbox/debian-squared.jpg >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/fluxbox/nls/??* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/gnome/help >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/?? >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??_* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??@* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/locale/??? >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/i18n/locales/*_* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/man/?? >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/man/*_* >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/icons/elementaryXubuntu-dark >>$OUTPUT 2>&1
rm -Rf $MODULE_UPPER_DIR/usr/share/icons/gnome/256x256 >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/compton.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/debian-uxterm.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/debian-xterm.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/htop.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/mc.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/mcedit.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/pcmanfm-desktop-pref.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/python2.7.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/python3.7.desktop >>$OUTPUT 2>&1
rm $MODULE_UPPER_DIR/usr/share/applications/vim.desktop >>$OUTPUT 2>&1
# Unzip gzipped files (man pages), so LZMA can compress 2times better.
# First we fix symlinks, then uncompress files
# $1 = search directory
uncompress_files() {
local LINK LINE
find "$1" -type l -name "*.gz" | while read LINE; do
LINK="$(readlink "$LINE" | sed -r 's/.gz$//')"
FILE="$(echo "$LINE" | sed -r 's/.gz$//')"
ln -sfn "$LINK" "$FILE"
rm -f "$LINE"
done
find "$1" -type f -name "*.gz" | xargs -r gunzip >>$OUTPUT 2>&1
}
}
uncompress_files $MODULE_UPPER_DIR/etc/alternatives >>$OUTPUT 2>&1
uncompress_files $MODULE_UPPER_DIR/usr/share/man >>$OUTPUT 2>&1
# remove broken links
# $1 = search directory
remove_broken_links() {
find "$1" -type l -exec test ! -e {} \; -print | xargs rm -vf >>$OUTPUT 2>&1
}
remove_broken_links $MODULE_UPPER_DIR/etc/alternatives >>$OUTPUT 2>&1
remove_broken_links $MODULE_UPPER_DIR/usr/share/man >>$OUTPUT 2>&1
fi
set -e
}
# =================================================================
#
#
# =================================================================
function build_modules_chroot() {
function build_modules_chroot() {
current_process
current_process
@ -1408,15 +1693,28 @@ function build_modules_chroot() {
# copy files
# copy files
if [ ! -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
if [ ! -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
if [ "$(ls -A $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy)" != "" ]; then
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy && cp --parents -afr * $MODULE_MERGED_DIR/)
fi
else
if [ "$(ls -A $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy)" != "" ] >>$OUTPUT 2>&1; then
if [ "$(ls -A $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy)" != "" ] >>$OUTPUT 2>&1; then
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy && cp --parents -afr * $MODULE_MERGED_DIR/)
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy && cp --parents -afr * $MODULE_MERGED_DIR/)
fi
fi
fi
else
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
if [ "$(ls -A $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy)" != "" ]; then
mkdir $MODULE_MERGED_DIR/rootcopy
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy && cp --parents -afr * $MODULE_MERGED_DIR/rootcopy/)
fi
else
else
if [ "$(ls -A $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy)" != "" ] >>$OUTPUT 2>&1; then
if [ "$(ls -A $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy)" != "" ] >>$OUTPUT 2>&1; then
mkdir $MODULE_MERGED_DIR/rootcopy
mkdir $MODULE_MERGED_DIR/rootcopy
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy && cp --parents -afr * $MODULE_MERGED_DIR/rootcopy/)
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/rootcopy && cp --parents -afr * $MODULE_MERGED_DIR/rootcopy/)
fi
fi
fi
fi
fi
# run install script
# run install script
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/install ]; then
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/install ]; then
@ -1428,6 +1726,19 @@ function build_modules_chroot() {
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/package.list ]; then
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/package.list ]; then
cp $SCRIPT_DIR/linux-live/modules/$MODULE/package.list $MODULE_MERGED_DIR/package.list
cp $SCRIPT_DIR/linux-live/modules/$MODULE/package.list $MODULE_MERGED_DIR/package.list
fi
fi
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
chroot $MODULE_MERGED_DIR /usr/bin/env \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
BUILD_TEST_ISO=$BUILD_TEST_ISO \
CREATE_BACKUP=$CREATE_BACKUP \
DEBIAN_FRONTEND_TYPE=$DEBIAN_FRONTEND_TYPE \
APT_CMD=$APT_CMD \
APT_OPTIONS=$APT_OPTIONS \
APT_OPTIONS2=$APT_OPTIONS2 \
LIVE_TYPE=$LIVE_TYPE \
/install
else
chroot $MODULE_MERGED_DIR /usr/bin/env \
chroot $MODULE_MERGED_DIR /usr/bin/env \
OUTPUT=$OUTPUT \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
LOGPATH=$LOGPATH \
@ -1440,11 +1751,12 @@ function build_modules_chroot() {
LIVE_TYPE=$LIVE_TYPE \
LIVE_TYPE=$LIVE_TYPE \
/install >>$OUTPUT 2>&1
/install >>$OUTPUT 2>&1
fi
fi
fi
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
module_chroot_umount_fs
module_chroot_umount_fs
build_cleanup
module_ build_cleanup
# run external actions
# run external actions
@ -1455,7 +1767,7 @@ function build_modules_chroot() {
cd $MODULE_UPPER_DIR >>$OUTPUT 2>&1
cd $MODULE_UPPER_DIR >>$OUTPUT 2>&1
unsquashfs $MODULE-stock.$BEXT >>$OUTPUT 2>&1
unsquashfs $MODULE-stock.$BEXT >>$OUTPUT 2>&1
else
else
echo -e "${MAGENTA}$BUILD _DIR${ENDCOLOUR} is empty. Nothing to do."
echo -e "${MAGENTA}$MODULE_UPPER _DIR${ENDCOLOUR} is empty. Nothing to do."
fi
fi
#module_check_build_dir
#module_check_build_dir
@ -1471,6 +1783,19 @@ function build_modules_chroot() {
mkdir $MODULE_MERGED_DIR/patches
mkdir $MODULE_MERGED_DIR/patches
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/patches && cp --parents -afr * $MODULE_MERGED_DIR/patches/)
(cd $SCRIPT_DIR/linux-live/modules/$MODULE/patches && cp --parents -afr * $MODULE_MERGED_DIR/patches/)
fi
fi
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
chroot $MODULE_MERGED_DIR /usr/bin/env \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
BUILD_TEST_ISO=$BUILD_TEST_ISO \
CREATE_BACKUP=$CREATE_BACKUP \
DEBIAN_FRONTEND_TYPE=$DEBIAN_FRONTEND_TYPE \
APT_CMD=$APT_CMD \
APT_OPTIONS=$APT_OPTIONS \
APT_OPTIONS2=$APT_OPTIONS2 \
LIVE_TYPE=$LIVE_TYPE \
/install2
else
chroot $MODULE_MERGED_DIR /usr/bin/env \
chroot $MODULE_MERGED_DIR /usr/bin/env \
OUTPUT=$OUTPUT \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
LOGPATH=$LOGPATH \
@ -1483,11 +1808,25 @@ function build_modules_chroot() {
LIVE_TYPE=$LIVE_TYPE \
LIVE_TYPE=$LIVE_TYPE \
/install2 >>$OUTPUT 2>&1
/install2 >>$OUTPUT 2>&1
fi
fi
fi
# run post-install script
# run post-install script
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/postinstall ]; then
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/postinstall ]; then
cp $SCRIPT_DIR/linux-live/modules/$MODULE/postinstall $MODULE_MERGED_DIR/postinstall
cp $SCRIPT_DIR/linux-live/modules/$MODULE/postinstall $MODULE_MERGED_DIR/postinstall
chmod +x $MODULE_MERGED_DIR/postinstall
chmod +x $MODULE_MERGED_DIR/postinstall
if [ $OUTPUT = "/dev/stdout" ] && [ ! -f /dev/stdout ]; then
chroot $MODULE_MERGED_DIR /usr/bin/env \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
BUILD_TEST_ISO=$BUILD_TEST_ISO \
CREATE_BACKUP=$CREATE_BACKUP \
DEBIAN_FRONTEND_TYPE=$DEBIAN_FRONTEND_TYPE \
APT_CMD=$APT_CMD \
APT_OPTIONS=$APT_OPTIONS \
APT_OPTIONS2=$APT_OPTIONS2 \
LIVE_TYPE=$LIVE_TYPE \
/postinstall
else
chroot $MODULE_MERGED_DIR /usr/bin/env \
chroot $MODULE_MERGED_DIR /usr/bin/env \
OUTPUT=$OUTPUT \
OUTPUT=$OUTPUT \
LOGPATH=$LOGPATH \
LOGPATH=$LOGPATH \
@ -1500,6 +1839,7 @@ function build_modules_chroot() {
LIVE_TYPE=$LIVE_TYPE \
LIVE_TYPE=$LIVE_TYPE \
/postinstall >>$OUTPUT 2>&1
/postinstall >>$OUTPUT 2>&1
fi
fi
fi
# run external actions
# run external actions
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
if [ -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
@ -1511,15 +1851,26 @@ function build_modules_chroot() {
module_chroot_umount_fs
module_chroot_umount_fs
if [ ! -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
if [ ! -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
build_cleanup
module_ build_cleanup
fi
fi
module_chroot_cleanup
module_chroot_cleanup
if [ ! -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
if [ ! -f $SCRIPT_DIR/linux-live/modules/$MODULE/is_internal_build ]; then
ls -la $SCRIPT_DIR/linux-live/modules/$MODULE/
if [ ! -f $PARENT_DIR/image/$LIVEKITNAME/$MODULE-$COMP_TYPE.$BEXT ]; then
if [ ! -f $PARENT_DIR/image/$LIVEKITNAME/$MODULE.$BEXT ]; then
if [ "$(ls -A $MODULE_UPPER_DIR)" != "" ]; then
build_modules_live
if [ $COMP_TYPE = "zstd" ]; then
mksquashfs $MODULE_UPPER_DIR $PARENT_DIR/image/$LIVEKITNAME/$MODULE-$COMP_TYPE.$BEXT -comp $COMP_TYPE -Xcompression-level 22 -b 1024K -always-use-fragments -noappend || exit
else
mksquashfs $MODULE_UPPER_DIR $PARENT_DIR/image/$LIVEKITNAME/$MODULE-$COMP_TYPE.$BEXT -comp $COMP_TYPE -b 1024K -always-use-fragments -noappend || exit
fi
else
echo -e "${MAGENTA}$MODULE_UPPER_DIR${ENDCOLOUR} is empty. Nothing to do."
fi
else
echo -e "${RED}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${ENDCOLOUR}"
echo -e "Please remove ${MAGENTA}$PARENT_DIR/image/$LIVEKITNAME/$MODULE-$COMP_TYPE.$BEXT${ENDCOLOUR} if you want to build ${MAGENTA}$MODULE${ENDCOLOUR}."
echo -e "${RED}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!${ENDCOLOUR}"
fi
fi
fi
fi
@ -1527,6 +1878,10 @@ function build_modules_chroot() {
done
done
}
}
# =================================================================
#
#
# =================================================================
function build_modules_live() {
function build_modules_live() {
current_process
current_process
echo "here 2"
echo "here 2"
@ -1559,7 +1914,7 @@ function build_modules_live() {
mksquashfs $MODULE_UPPER_DIR $PARENT_DIR/image/$LIVEKITNAME/$MODULE-$COMP_TYPE.$BEXT -comp $COMP_TYPE -b 1024K -always-use-fragments -noappend || exit
mksquashfs $MODULE_UPPER_DIR $PARENT_DIR/image/$LIVEKITNAME/$MODULE-$COMP_TYPE.$BEXT -comp $COMP_TYPE -b 1024K -always-use-fragments -noappend || exit
fi
fi
else
else
echo -e "${MAGENTA}$BUILD _DIR${ENDCOLOUR} is empty. Nothing to do."
echo -e "${MAGENTA}$MODULE_UPPER _DIR${ENDCOLOUR} is empty. Nothing to do."
fi
fi
fi
fi
done
done