#/bin/sh -e                                                                                                                

# Script for upgrade ALT SP Server (release 9) to ALT SP Server (release 10)
# Copyright (c) 2024 Andrey Cherepanov <cas@basealt.ru>

# This program is free software; you can redistribute it and/or modify it
# under the terms of GNU General Public License (GPL) version 3 or later.

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

apt-get update

TO_INSTALL=""
if [ -n "$(rpm -q postgresql11-devel-11.22 2>/dev/null)" ]; then 
	apt-get -y remove postgresql11-devel
	#TO_INSTALL="postgresql11 postgresql11-devel postgresql11-pgcopydb postgresql11-server"
fi

apt-get -y dist-upgrade
apt-get -y dist-upgrade

if [ -n "$TO_INSTALL" ]; then
	apt-get -y install $TO_INSTALL
fi

apt-repo rm all
apt-repo add 'rpm [cert8] http://update.altsp.su/pub/distributions/ALTLinux c10f2/branch/x86_64 classic gostcrypto'
apt-repo add 'rpm [cert8] http://update.altsp.su/pub/distributions/ALTLinux c10f2/branch/x86_64-i586 classic'
apt-repo add 'rpm [cert8] http://update.altsp.su/pub/distributions/ALTLinux c10f2/branch/noarch classic'
subst 's/c10f1/c10f2/' /usr/lib/rpm/macros
apt-get update
apt-get -y dist-upgrade

update-kernel -t 6.12 -y

apt-get -y remove nagios-plugins-common

apt-get -y install alt-chksum alt-rpmkeys alt-rpmkeys-utils apt-conf-branch-gostcrypto attr branding-alt-spserver-indexhtml btrfs-progs chrony color-prompt-and-man cryptsetup dialog exfatprogs firmware-aic94xx-seq firmware-ast_dp501 firmware-ql6312 fping gostsum hddtemp icinga2 icinga2-common ima-inspect indexhtml-common integalert inxi kernel-modules-drm-6.12 kernel-modules-drm-nouveau-6.12 kernel-modules-tripso-6.12 kernel-modules-xtables-addons-6.12 libboost_context1.76.0 libboost_coroutine1.76.0 libboost_filesystem1.76.0 libboost_program_options1.76.0 libdialog libdouble-conversion3 libestr libfastjson libprotobuf27 libqb100 libqt5-core libqt5-dbus libumockdev libusbguard1 make-initrd-luks man-pages-ru-extra mkbootflash nagios-nrpe nagios-plugins nagios-plugins-common nagios-plugins-local nagios-plugins-network nagwad-icinga-agent nagwad-service nano-icinga2 os-prober osec-cert-cronjob osec-cert-mailreport perl-Digest-SHA1 perl-RPM2 policycoreutils python3-module-audit python3-module-networkx-core python3-module-policycoreutils python3-module-selinux python3-module-semanage python3-module-setools python3-module-slip python3-module-slip-dbus python3-module-tqdm python3-modules-tkinter qt5-base-common rfkill rsyslog syslinux systemd-settings-enable-log-to-tty12 systemd-settings-enable-showstatus tmux usbguard usbguard-common usbguard-dbus usbguard-notifier usbguard-utils verify-checksums vim-icinga2 xtables-addons

rpm -e --nodeps liblmdb
apt-get -fy install

apt-get clean

systemctl disable integalert systemd-update-done.service system-update-cleanup.service

echo
echo "Upgrade is complete."
echo
