From b8417a7f64905cb51c1e63fa5a0b03ddc4070c0b Mon Sep 17 00:00:00 2001 From: xf0r3m Date: Mon, 14 Aug 2023 13:24:10 +0200 Subject: [PATCH] Dostosowywanie immudex-upgrade do nowego sposobu wydawania immudex-testing --- tools/immudex-upgrade | 121 +++++------------------------------------- tools/library.sh | 6 ++- 2 files changed, 17 insertions(+), 110 deletions(-) diff --git a/tools/immudex-upgrade b/tools/immudex-upgrade index fbfc50c..ce8d5f6 100755 --- a/tools/immudex-upgrade +++ b/tools/immudex-upgrade @@ -14,14 +14,8 @@ function help() { echo "immudex-upgrade - script for searching upgrades and upgrade immudex"; echo "@ 2023 morketsmerke.org"; echo "Options:"; - echo " --check --print - check there are upgrades for immudex"; - echo " --upgrade - check there are upgrades for immudex and install them."; - echo " If there is no new version, script will propose refreshing"; - echo " current immudex installation, its helpful when you tried"; - echo " remaster immudex and you get any trouble with this". - echo " --version - getting latest version of immudex"; - echo " --branch - change immudex branch"; - echo " Switch between stable or testing version and vice versa" + echo " --check - check there are upgrades for immudex"; + echo " --upgrade - upgrade immudex from given source"; } function main_upgrade() { @@ -41,110 +35,19 @@ function main_upgrade() { sudo cp /tmp/version ${1}/live; } -function check_mirror() { - mirrorList=("sourceforge.net=https://sourceforge.net/projects/immudex/files", "plikownia.zsgronowo.edu.pl=https://plikownia.zsgronowo.edu.pl/pliki/Nauczyciele/Administrator/files", "ftp.morketsmerke.org=https://ftp.morketsmerke.org"); - for i in ${mirrorList[@]}; do - name=$(echo $i | cut -d "=" -f 1); - address=$(echo $i | cut -d "=" -f 2 | sed 's/,//'); - echo -en "Checking is ${YELLOW}${name}${ENDCOLOR} available..." 1>&2; - curl ${address}/immudex/stable/upgrades/latest/64/version > /dev/null 2>&1; - if [ $? -eq 0 ]; then - echo -e "[ ${GREEN}OK${ENDCOLOR} ]" 1>&2; - mirror=$address; - mirror_name=$name; +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 "[ ${RED}FAIL${ENDCOLOR} ]" 1>&2; - fi - done - if [ "$mirror" ]; then - echo "Choosing $mirror_name" 1>&2; - echo $mirror; - else exit 1; fi -} - -if [ "$1" ] && [ "$1" = "--check" ]; then - if [ "$2" ] && [ "$2" = "--print" ]; then - newVersion=$(check_distro_version --print); - if check_distro_version; then - echo -e "${YELLOW}New version (${ENDCOLOR}${RED}$newVersion${ENDCOLOR}${YELLOW}) of immudex is available to upgrade.${ENDCOLOR}"; - else - echo -e "${YELLOW}This (${ENDCOLOR}${GREEN}$newVersion${ENDCOLOR}${YELLOW}) is the latest version of immudex.${ENDCOLOR}"; - fi - elif [ "$2" = "--mirror" ]; then - mirror=$(check_mirror); - echo $mirror; - fi -elif [ "$1" ] && [ "$1" = "--upgrade" ]; then - newVersionTxt=$(check_distro_version --print); - newVersionInt=$(echo $newVersionTxt | sed 's/\.//g'); - if check_distro_version; then - echo -en "${YELLOW}New version " - echo -en "(${ENDCOLOR}${RED}${newVersionTxt}${ENDCOLOR}${YELLOW}) " - echo -e "of immudex is available.${ENDCOLOR}"; - echo -e "${RED}Warning, reboot maybe necessary to continue work on this machine${ENDCOLOR}"; - echo -en "${YELLOW}Do you want upgrade this system? (y/n):${ENDCOLOR} "; - read commit; - if [ $commit = "y" ]; then - echo "Upgrading immudex to the newest version..."; - main_upgrade $root $newVersionTxt; - if [ $? -eq 0 ]; then echo -e "Upgrading immudex to the newest version...[ ${GREEN}OK${ENDCOLOR} ]"; fi - else - exit 1; - fi - else - echo -e "${GREEN}There is no newer version of immudex,${ENDCOLOR}"; - echo -e "${YELLOW}but you can copy fresh system files from latest iso image"; - echo -e "${RED}Warning, reboot maybe necessary to continue work on this machine${ENDCOLOR}"; - echo -en "${YELLOW}Do you want refresh this system? (y/n):${ENDCOLOR} "; - read commit; - if [ $commit = "y" ]; then - echo "Refreshing immudex to the latest iso image..."; - main_upgrade $root $newVersionTxt; - if [ $? -eq 0 ]; then echo -e "Refreshing immudex to the latest iso image...[ ${GREEN}OK${ENDCOLOR} ]"; fi - else - exit 1; - fi - exit 0; - fi -elif [ "$1" ] && [ "$1" = "--version" ]; then - MIRROR=$(check_mirror); - stable64=$(curl ${MIRROR}/immudex/stable/upgrades/latest/64/version 2>/dev/null) - stable32=$(curl ${MIRROR}/immudex/stable/upgrades/latest/32/version 2>/dev/null) - testing64=$(curl ${MIRROR}/immudex/testing/upgrades/latest/64/version 2>/dev/null) - testing32=$(curl ${MIRROR}/immudex/testing/upgrades/latest/32/version 2>/dev/null) - branch=$(get_debian_branch); - localVer=$(cat /run/live/medium/live/version); - if [ "$(uname -m)" = "x86_64" ]; then - arch="amd64"; - stable=$stable64; - testing=$testing64; - else - arch="i386"; - stable=$stable32; - testing=$testing32; - fi - echo "Arch: $arch"; - echo "Local: ${localVer} (${branch})"; - echo "Stable: $stable"; - echo "Testing: $testing"; -elif [ "$1" ] && [ "$1" = "--branch" ]; then - if [ "$2" ] && ([ "$2" = "stable" ] || [ "$2" = "testing" ]); then - BRANCH=$2; - ARCH=$(get_machine_arch); - export $BRANCH; - echo -en "${YELLOW}Do you really want change immudex branch (y/n):${ENDCOLOR} "; - read commit; - if [ $commit = "y" ]; then - echo "Changing immudex branch to ${BRANCH}..."; - newVersionTxt=$(curl https://ftp.morketsmerke.org/immudex/${BRANCH}/upgrades/latest/${ARCH}/version 2>/dev/null); - main_upgrade $root $newVersionTxt; - if [ $? -eq 0 ]; then echo -e "Changing immudex branch to ${BRANCH}...[ ${GREEN}OK${ENDCOLOR} ]"; fi - else - exit 1; + echo -e "There is a ${RED}new${ENDCOLOR} version of immudex"; + check_distro_commit --print; fi + elif [ "$1" ] && [ "$1" = "--upgrade" ]; then + else - help; exit 1; - fi + help; + exit 1; else help; exit 1; diff --git a/tools/library.sh b/tools/library.sh index 998968a..c43e68b 100755 --- a/tools/library.sh +++ b/tools/library.sh @@ -21,7 +21,11 @@ function check_distro_commit() { versionFile="/run/live/medium/live/version"; if [ -f $versionFile ]; then localVersion=$(cat $versionFile); - git clone -q --depth=1 https://git.morketsmerke.org/git/immudex-testing /tmp/immudex-testing; + if [ -d /tmp/immudex-testing ]; then + $(cd /tmp/immudex-testing && git pull -q); + else + git clone -q --depth=1 https://git.morketsmerke.org/git/immudex-testing /tmp/immudex-testing; + fi latestVersion=$(cd /tmp/immudex-testing && git log --pretty=oneline | cut -d " " -f 1); if [ "$1" ] && [ "$1" == "--print" ]; then $(cd /tmp/immudex-testing && git log $latestVersion); -- 2.39.5