From 67109343ef0bbbe0dd663445c976d15588c47f21 Mon Sep 17 00:00:00 2001 From: kake26 Date: Sat, 10 May 2025 21:29:00 -0500 Subject: [PATCH] feat: add distro compatibility check for system restore process --- restore.deb.bash | 9 ++++++++- restore.lib.bash | 25 +++++++++++++++++++++++++ syssetup.bash | 4 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/restore.deb.bash b/restore.deb.bash index dbcfd3a..b46fa59 100755 --- a/restore.deb.bash +++ b/restore.deb.bash @@ -76,6 +76,11 @@ function restore_config() { cprint 2 "Done!" } +echo "Distro check..." + +check_distro + + # Check for root only important on pure Debian as there is no sudo by default if [ "$(id -u)" != "0" ]; then # check is the system is debian @@ -84,8 +89,10 @@ if [ "$(id -u)" != "0" ]; then fi fi + + until [ "$selection" = "0" ]; do -clear +#clear echo "" cprint 3 " Main Menu" mprint 1 "Restore" diff --git a/restore.lib.bash b/restore.lib.bash index 5728fb6..a39a5f1 100755 --- a/restore.lib.bash +++ b/restore.lib.bash @@ -38,4 +38,29 @@ if [ -f $pkgsum ] && [ -f $hostsum ]; then else echo "Checksum files not found" fi +} + +function check_distro() { + + if [ -f ./distro_info ]; then + . ./distro_info + source_distro="$DISTRO_ID" + source_version="$DISTRO_VERSION" + else + cprint 1 "Warning: No distro info found in archive. Cannot verify compatibility." + return + fi + + . /etc/os-release + target_distro="$ID" + target_version="$VERSION_ID" + + if [ "$source_distro" != "$target_distro" ] || [ "$source_version" != "$target_version" ]; then + cprint 3 "Warning: This restore was created on $source_distro $source_version, but the target system is $target_distro $target_version." + cprint 3 "Restoration may fail if packages or configurations are incompatible." + cprint 3 "Press Enter to continue, or Ctrl+C to abort." + read + else + cprint 2 "Distro match: $source_distro $source_version. Proceeding with restoration." + fi } \ No newline at end of file diff --git a/syssetup.bash b/syssetup.bash index 38b2268..7136e4c 100755 --- a/syssetup.bash +++ b/syssetup.bash @@ -69,6 +69,10 @@ function copy_config() { if [ -f ./exclusions ]; then cp ./exclusions $tmpdir fi + # Save distro info + . /etc/os-release + echo "DISTRO_ID=$ID" > $tmpdir/distro_info + echo "DISTRO_VERSION=$VERSION_ID" >> $tmpdir/distro_info if [ "$osp" = "Debian" ]; then dpkg --get-selections > $tmpdir/installed_packages cp ./restore.deb.bash $tmpdir/restore.bash