--- /dev/null
+#!/bin/bash
+
+set -e
+
+source library.sh
+
+RED="\e[31m";
+GREEN="\e[32m";
+YELLOW="\e[33m";
+ENDCOLOR="\e[0m";
+root="/run/live/medium";
+
+function help() {
+ echo "immudex-upgrade - script for searching upgrades and upgrade immudex";
+ echo "@ 2025 morketsmerke.org";
+ echo "Superuser (root) privileges are required.";
+ echo "Options:";
+ #echo " --check - check there are upgrades for immudex";
+ echo " --upgrade - upgrade immudex from given source";
+ #echo " --myversion - prints images current commit message";
+ #echo " --myversion - prints image details";
+ #echo " --compilation-date - prints date of image creation";
+ #echo " --packages-upgradable [--security] - updates apt (packages) list and";
+ #echo " prints available to upgrade packages, with --security modificator";
+ #echo " prints only pacakages from security repository branch";
+}
+
+if [ $UID -ne 0 ]; then
+ echo "Permission denied!";
+ help;
+ exit 1;
+fi
+
+if [ "$1" ]; then
+ if [ "$1" ] && [ "$1" = "--check" ]; then
+ if check_distro_commit; then
+ echo -e "${GREEN}This${ENDCOLOR} is the latest version of immudex";
+ else
+ echo -e "There is a ${RED}new${ENDCOLOR} version of immudex:";
+ echo "===================================================";
+ check_distro_commit --print;
+ fi
+ elif [ "$1" ] && [ "$1" = "--upgrade" ]; then
+ echo "Upgrading immudex...";
+ part=$(blkid | grep 'LABEL="immudex"' | awk '{printf $1}' | cut -d ":" -f 1);
+ if mount | grep -q "$part"; then
+ echo -n " Mounting iso image...";
+ mount $2 /mnt > /dev/null 2>&1;
+ if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ mountPointList=$(mount | grep "$part" | awk '{printf $3" "}');
+ for mountPoint in $mountPointList; do
+ echo -n " Unlocking $mountPoint ...";
+ mount $part $mountPoint -o remount,rw > /dev/null 2>&1;
+ if [ $? -eq 0 ]; then
+ echo -e "[ ${GREEN}OK${ENDCOLOR} ]";
+ else
+ echo -e "[ ${RED}FAIL${ENDCOLOR} ]";
+ fi
+ done
+ echo " Copying immudex files to the disk...";
+ cp -vv /mnt/live/* ${mountPoint}/live;
+ if [ $? -eq 0 ]; then
+ echo -e " Copying immudex files to the disk...[ ${GREEN}OK${ENDCOLOR} ]";
+ else
+ echo -e " Copying immudex files to the disk...[ ${RED}FAIL${ENDCOLOR} ]";
+ fi
+ else
+ echo -n " Mounting immudex partition...";
+ mount $part /mnt >> /dev/null 2>&1;
+ if [ $? -eq 0 ]; then echo -e "[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ if [ "$2" ] && $(echo "$2" | grep -q '^http'); then
+ URL="$2";
+ wget ${URL}/live/vmlinuz -O /mnt/live/vmlinuz 2>/dev/null;
+ if [ $? -eq 0 ]; then echo -e " Copying immudex kernel to the disk...[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ wget ${URL}/live/initrd -O /mnt/live/initrd 2>/dev/null;
+ if [ $? -eq 0 ]; then echo -e " Copying immudex initrd to the disk...[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ wget ${URL}/live/filesystem.squashfs -O /mnt/live/filesystem.squashfs 2>/dev/null;
+ if [ $? -eq 0 ]; then echo -e " Copying immudex filesystem.squashfs to the disk...[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ wget ${URL}/live/changelog -O /mnt/live/changelog 2>/dev/null;
+ if [ $? -eq 0 ]; then echo -e " Copying immudex changelog file to the disk...[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ else
+ echo " Copying immudex files to the disk...";
+ cp -vv /run/live/medium/live/* /mnt/live;
+ if [ $? -eq 0 ]; then
+ echo -e " Copying immudex files to the disk...[ ${GREEN}OK${ENDCOLOR} ]";
+ else
+ echo -e " Copying immudex files to the disk...[ ${RED}FAIL${ENDCOLOR} ]";
+ fi
+ fi
+ fi
+ if $(sudo efibootmgr > /dev/null 2>&1); then
+ echo " Copying grub config to the disk...";
+ if [ "$mountPoint" ]; then
+ cp -vv /mnt/boot/grub/grub.cfg ${mountPoint}/boot/grub/grub.cfg;
+ if [ $? -eq 0 ]; then
+ echo -e " Copying grub config to the disk...[ ${GREEN}OK${ENDCOLOR} ]";
+ sed -i '/set\ timeout=/ s/30/5/' ${mountPoint}/boot/grub/grub.cfg;
+ sed -i 's/bootfrom=removable //g' ${mountPoint}/boot/grub/grub.cfg;
+ else
+ echo -e " Copying grub config to the disk...[ ${RED}FAIL${ENDCOLOR} ]";
+ fi
+ else
+ if [ "$2" ] && $(echo "$2" | grep -q '^http'); then
+ wget ${URL}/live/grub.cfg -O /mnt/boot/grub/grub.cfg 2>/dev/null;
+ if [ $? -eq 0 ]; then echo -e " Downloading immudex GRUB config...[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ echo -e " Copying grub config to the disk...[ ${GREEN}OK${ENDCOLOR} ]";
+ else
+ cp -vv /run/live/medium/boot/grub/grub.cfg /mnt/boot/grub/grub.cfg;
+ if [ $? -eq 0 ]; then
+ echo -e " Copying grub config to the disk...[ ${GREEN}OK${ENDCOLOR} ]";
+ else
+ echo -e " Copying grub config to the disk...[ ${RED}FAIL${ENDCOLOR} ]";
+ fi
+ fi
+ sed -i '/set\ timeout=/ s/30/5/' /mnt/boot/grub/grub.cfg;
+ sed -i 's/bootfrom=removable //g' /mnt/boot/grub/grub.cfg;
+ fi
+ fi
+ umount -R /mnt;
+ if [ $? -eq 0 ]; then echo -e " Unmount immudex partition...[ ${GREEN}OK${ENDCOLOR} ]"; fi
+ echo -e "Upgrading immudex...[ ${GREEN}OK${ENDCOLOR} ]";
+ elif [ "$1" ] && [ "$1" = "--myversion" ]; then
+ #if [ -d /tmp/immudex ]; then
+ # (cd /tmp/immudex && git pull > /dev/null 2>&1)
+ #else
+ # git clone https://github.com/xf0r3m/immudex /tmp/immudex;
+ #fi
+ #(cd /tmp/immudex && git show $(cat /run/live/medium/live/version))
+ cat /run/live/medium/live/changelog;
+ elif [ "$1" ] && [ "$1" = "--packages-upgradable" ]; then
+ apt update;
+ if [ "$2" ] && [ "$2" = "--security" ]; then
+ apt list --upgradable | grep 'security';
+ else
+ apt list --upgradable;
+ fi
+ elif [ "$1" ] && [ "$1" = "--compilation-date" ]; then
+ eval $(grep '^COMPILATION_DATE' /run/live/medium/live/changelog);
+ echo "Image was created: $COMPILATION_DATE";
+ else
+ help;
+ exit 1;
+ fi
+else
+ help;
+ exit 1;
+fi