BASH 46
Php-updater Guest on 30th June 2024 01:18:32 PM
  1. #!/bin/bash
  2. # /usr/local/bin/php-updater
  3. # version 2024-06-27 20:20 CEST 1719512402
  4. #
  5. # Copyright (c) 2023-2024 [ernolf] Raphael Gradenwitz
  6. # Email        raphael.gradenwitz<at>googlemail.com
  7. # OpenPGP_Key  3EE43A84D2BA635A94E1033B0B145139A170715C
  8. #              (only for codesigning)
  9. #
  10. # This script may be freely used, modified, and distributed, provided
  11. # that the original author, [ernolf] Raphael Gradenwitz, is credited.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  17. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  18. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  19. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. #
  21.  
  22. declare scriptname='php-updater'
  23. declare sin=${scriptname%-test}
  24. declare -a dependencies modules
  25.  
  26. dependencies=(
  27.     "less#less#A terminal pager similar to more"
  28.     "apt-file#apt-file#Search for files within Debian packages"
  29. #    "apt-rdepends#apt-rdepends#Recursively lists package dependencies"
  30.     "lsb_release#lsb-release#Tool to detect the Linux standard base version"
  31.     "update-the-ca-certificates#ca-certificates#Common CA certificates"
  32.     "curl#curl#Command line file transfer tool with URL syntax"
  33.     "gpg#gnupg#GNU Privacy Guard"
  34.     "jq#jq#Command-line JSON processor"
  35.     "ccdiff#ccdiff#Colored Character Diff"
  36. )
  37. modules=(
  38.     today interval basics sed tempfile prompt ansi button fstring exit spinner
  39.     anykey line array ask sudo dependency httpd php/versions php/fpm php/apache2
  40.     vdir integrity dpkg sort dist/os_release php/sury php/extensions
  41.     php.net/ini_directives $sin/merge $sin/tasks $sin/linstalled $sin/help
  42.     $sin/chfiles
  43. )
  44.  
  45. declare debug=false
  46. $debug&&trap 'read -rp "$(R)[DEBUG:]$(N) press Enter to poceed..."' DEBUG
  47.  
  48. # when
  49. declare -i rte;printf -v rte "%(%s)T" -2
  50.  
  51. # whoami, whereami
  52. # b=basename m=me a=absolute p=path ca=canonical
  53. declare bm apm me ca_me ca_dir
  54. bm="$(basename "$0")";apm="$(cd "$(dirname "$0")"&&pwd)/$bm"
  55. [ "$(which "$bm")" = "$apm" ]&&me="$bm"||me="$apm"
  56. ca_me="$(readlink -e "$apm")";ca_dir="$(dirname "$ca_me")"
  57.  
  58. # don't change this by hand, its done safe and interactively by the script:
  59. declare vdirname="" # <-- don't change this!
  60. [ -z "$TMPDIR" ]&&declare TMPDIR="/tmp"
  61.  
  62. ### module handling (minified)
  63. declare my_home=https://global-social.net/apps/raw/s
  64. # read minified codeblocks here: https://github.com/ernolf/ebtb/tree/main/blocks
  65. ## general
  66. log(){ (flock -x 200;echo "$(ts) - $bm-$epoch - $(fp)$@">>"$lf") 200>"$lf.lock";};ts(){ printf "%(%s-)T";printf "%((%F_%R_%Z))T";};ver_(){ awk '/^# v/{print$3,$4}' "$1";};epch_(){ awk '/^# v/{print$NF}' "$1";};fp(){ cat $lincld/fp 2>/dev/null;};hc(){ local a=$1;shift;log "$1"&curl -$a /dev/null -w %{http_code} -A "$(fp)$@";};nohome(){ echo -e "\n - Failed to load required module \"$1\".\n   try again later or run\n   - sudo wget -O $ca_me $my_url\n   and start the script again.";rm -f "$lincld/$1";exit 1;};sourced(){ local am;local -u m="${1#*/}_BASHLIB";eval am="\$$m";${am:-false}&&return 0||return 1;};json_etag(){ which jq>/dev/null||return 1;jq -r '.etag' "$1" 2>/dev/null;return $?;};c4u(){ local -u m="${1#*/}_BASHLIB";[ -f "$lincld/$1" ]||return 0;local -i le=$(module_etag "$1" "$lmj") re=$(module_etag "$1" "$lmjn");((le<re))&&{ rm "$lincld/$1";declare -g $m=false;};};req(){ sourced $1&&return 0||{ log req $1;curl -A "$(fp)req $1" $cargs/$rincld/$1&&return 0||nohome $l;};};require(){ req $@;};module_etag(){ jq -r '.modules[]|select(.name=="'$1'")|.etag' $2;};declare lf version my_url cargs opt opts astr="$(id -un): " A="$(uname -a)";declare -i epoch my_epoch my_size lce mje mjne w4uc;declare -a args tntd;lf="$TMPDIR/ebtb-logfiles/$bm.log";[ -d "${lf%/*}" ]||mkdir -p "${lf%/*}";version="$(ver_ "$apm")" epoch="$(epch_ "$apm")";my_url="$my_home/$scriptname" cargs="-se $bm-$epoch $my_home";opts="rt run2 irun2 do_update do_restore_backup do_integrity_check";for opt in $opts;do declare $opt=false;done;(($(id -u)))||rt=:;for arg in "$@";do if [ "${arg%=*}" = 'json' ];then declare run2=: my_$arg astr="run2 $astr";elif [ "$arg" = 'irun2' ];then declare irun2=: astr="irun2 $astr";elif [ "$arg" = 'my_update' ];then declare do_update=: astr="update $astr";elif [ "$arg" = 'restore_backup' ];then declare do_restore_backup=: astr="backup $astr";elif [ "$arg" = 'integrity_check' ];then declare do_integrity_check=: astr="integrity $astr";else args+=("$arg");fi;done;set -- "${args[@]}"&&unset -v args;declare my_args="$*" r my_json my_scriptname my_hash;$run2&&r=$(hc Io "$astr$my_args" $cargs/${scriptname}_json)||{ r=$(hc D "$astr$my_args" $cargs/${scriptname}_json);((${r##*$'\n'}==200))&&my_json="${r%$'\n'*}";};unset -v r
  67. ## include bashmodules (minified) ->
  68. declare channel='prod' lincld rincld REQ mod lmo check=false lmj lmjn rmj lcf fp;w4uc=3600;[[ $scriptname =~ test ]]&&{ channel='test' w4uc=36;};lincld="${ca_dir%/*}/include/ernolf/$channel" rincld="includes/$channel";mkdir -p $lincld/$sin;REQ=". $lincld" lmj="$lincld/modules.json" rmj="$rincld/modules.json" lcf="$lincld/$sin/.checked";lmjn="$lmj~new" lce=$(cat "$lcf" 2>/dev/null) fp=$(cat "$lincld/fp" 2>/dev/null);$rt&&((rte-lce>w4uc))&&{ curl -o "$lmjn" -A "$(fp)$A" $cargs/$rmj;if mje=$(json_etag "$lmj")&&mjne=$(json_etag "$lmjn");then ((mje<mjne))&&check=:;fi;};for mod in ${modules[@]};do lmo="$lincld/$mod";$rt&&mkdir -p "${lmo%/*}";$check&&{ ${pager:-false}||printf "\r\e[K.. checking modules - $mod";c4u "$mod";}||{ ${pager:-false}||printf "\r\e[K.. loading modules - $mod";};sourced "$mod"&&continue;if [ -f "$lmo" ];then $REQ/$mod;elif ! $rt;then . <(req $mod);elif (($(curl -o "$lmo" -w %{http_code} -A "$(fp)REQ $mod" $cargs/$rincld/$mod)==200));then log REQ $mod;$REQ/$mod;else nohome $mod;fi;[ "$mod" = 'dependency' ]&&dependency_check;done;$check&&echo $rte>"$lcf";[ -f "$lmjn" ]&&mv "$lmjn" "$lmj";$rt&&! ((lce))&&echo $rte>"$lcf";${pager:-false}||te1;eval "$(echo "$(unquote $my_json)"|jq -r 'keys[] as $key|"my_\($key)=\(.[$key]|@sh)"')";declare upinf='(no update info available)';. <(req update);"$do_update"&&my_update;[ "$1" = "my_update_check" ]&&my_update_check;"$do_restore_backup"&&restore_backup
  69. # check module integrity if root is running script and remove tainted modules (minified)
  70. $rt&&{ [ -f "$lmj" ]||curl -o "$lmj" -A "$(fp)$A" $cargs/$rmj;jq -r '.modules[] | "\(.hash) \(.name)"' $lmj>$lincld/modules.sha256 2>/dev/null;tntd=($(cd $lincld;sha256sum -c --ignore-missing --quiet modules.sha256 2>/dev/null|sed 's/:.*//'));((${#tntd[@]}))&&{ for i in ${!tntd[@]};do rm "$lincld/${tntd[i]}";done;"$me" "json=$my_json" $my_args;exit 0;};};unset -v rt lcf tntd
  71. ## <- include bashmodules end #
  72.  
  73. declare help=false force=false forceflag='' needforce=false supported=false unsupported=false nolts=false distrib_to_old=false distrib_to_new=false distrib_unknown=false pager=:;declare -a args=()
  74. for arg in "$@";do
  75.    if [ "$arg" = "-h" ]||[ "$arg" = "--help" ];then help=true
  76.    elif [ "$arg" = "--force" ];then force=true forceflag=' --force'
  77.    elif [ "$arg" = "--nopager" ]||[ "$arg" = "--no_pager" ]||[ "$arg" = "--no-pager" ];then pager=false
  78.    else args+=("$arg");fi
  79. done;set -- "${args[@]}"&&unset -v args
  80. $help&&explain
  81.  
  82. cursor_ hide
  83.  
  84. ## it starts here:
  85. ###############################################################################
  86. # you MUST be root:
  87. su_root "to run this script."
  88. my_update_check
  89. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " distrib_checked " ]]||. <(require $sin/distrib)
  90. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " supported " ]]&&supported=true
  91. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " to_old " ]]&&{ distrib_to_old=true needforce=true; $force&&supported=true;}
  92. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " to_new " ]]&&{ distrib_to_new=true needforce=true; $force&&supported=true;}
  93. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " nolts " ]]&&{ nolts=true needforce=true; $force&&supported=true;}
  94. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " unknown " ]]&&{ distrib_unknown=true needforce=true; $force&&supported=true;}
  95. [[ " $(tail -n3 "$ca_me"|head -n1) " =~ " unsupported " ]]&&unsupported=true
  96.  
  97.  
  98. # returns a list with vals unique to $1 - # x1=minimum packages to be installed, x2= packages required by cli and thus installed
  99. packages_diff(){ local pkg pvo pvn;local -a eia x1 x2;local -i i;pvo="$1" pvn="$2"
  100.    (( ${#EXTS_ADMIN[@]} ))&&{
  101.        for i in $(eval echo \${!C4EIBY4_${pvo//./}[@]});do
  102.            pkgmod="$(eval echo \"\${C4EIBY4_${pvo//./}[i]}\")";pkg=${pkgmod%:*}
  103.            [[ " $pkg" =~ " php$pvo-" ]]&&eia+=("${pkg#*-}")
  104.        done;}
  105.    x1=(apcu bcmath bz2 curl gd gmp igbinary intl mbstring redis xml zip) x2=(cli common json opcache readline)
  106.    inst(){ local v x;v="$1";shift;(dpkg -l|awk '/^[hiu]i.*php'$v'/{print $2}'|sed "s/$v//";for x in $@;do echo php-$x;done)|sort -u;}
  107.    for pkg in $(comm -23 <(inst $1 ${x1[@]} ${eia[@]}) <(inst $2 ${x2[@]})|sed "s/php/php$2/");do
  108.        if echo "$pkg"|grep -Eqsvw "^$phpvregex$";then apt_exist "$pkg" &>/dev/null && echo $pkg;fi
  109.    done
  110. }
  111.  
  112. install_new_php(){ local old="$1" new="$2" package;local -a packages;local -i i
  113.    apt_need_update
  114.    if apt-cache show php$NEW >/dev/null 2>&1;then
  115.        separator
  116.        # update first?
  117.        f;echo " -$(format_string "An update is not recommended at this point but possible. However, if you answer $(box yes) here, all PHP related packages will be marked 'hold' to remain the initial php-situation unchanged." 3)"
  118.        if ask "$(qpf)Do you want to update the system first " "$NO";then
  119.            apt-mark hold $(dpkg -l|awk '/^[hiu]i.*php*/{print $2}') >/dev/null 2>&1 # hold php as it is for this step.
  120.            apt-get dist-upgrade
  121.            pf;echo "$(lG)system updated$(N)"
  122.            anykey
  123.        fi
  124.        apt-mark unhold *php* &>/dev/null
  125.        which needrestart >/dev/null&&export NEEDRESTART_SUSPEND=1
  126.        detect_and_assign_extensions
  127.        search_candidates_4_extensions_installed_by_admin $OLD
  128.        spinner C " . performing thorough review (dry run) of package sources and candidate availability ." &
  129.        mapfile -t packages< <(packages_diff $OLD $NEW)
  130.        kill_spinner
  131.        if ((${#packages[@]})); then
  132.            apt_install_prechecked --yes php$NEW-cli
  133.            apt_install_prechecked --yes ${packages[@]}
  134.        fi
  135.        which needrestart >/dev/null&&needrestart -r a
  136.    else f
  137.        no_candidate "$NEW"
  138.        exit1
  139.    fi
  140.    populate_versions_array
  141.    separator
  142.    f;echo " -$(format_string "$(P)If everything looks good so far, the migration of the settings from $(C)php-$OLD$(P) to $(C)php-$NEW$(P) can be started. If you answer $(box no) here or abort the migration process on some point $(GRAY)(with Ctrl-C)$(P), you can always call and start this step again with" 3)"
  143.    f;G;echo "$(prompt;lB) $me$forceflag$(C) $OLD $NEW";N
  144.    f;os;P;echo "to finalize or redo the migration.";N
  145.    f;echo " -$(format_string "$(P)Please be aware that a malicious configuration under $(C)php-$OLD$(P) will also be migrated. This script does not yet check for all thinkable wrong configurations. This will change step by step in future." 3;N)"
  146.    ask "$(qpf)Proceed with next step" "$YES"&&{ separator;"$me$forceflag" "json=$my_json" $OLD $NEW;exit;}||exit0
  147. }
  148.  
  149. # messages
  150. call_help(){ o2;GRAY;echo "You can call the help with:$(o 35;B)$me --help";line '-' dP 2/78;}
  151. call_me(){ o2;GRAY;echo "You can call this list with:$(o 35;B)$me --list-$1";line '-' dP 2/78 a${2:-1};}
  152. version_mismatch(){ f;o;Pbg;pf;echo "A version mismatch has been detected which cannot be resolved by this script$(pf;N)";exit1;}
  153. wrong_first_argument(){ local -i a=$2
  154.    f;o;Pbg;pf;printf "First argument must be the version of an installed php but "
  155.    if ((a));then
  156.        echo "php$1 is not installed$(pf;N)";f;list_candidates;call_me candidates;call_help;f
  157.    else
  158.        echo "\"$1\" is not an existing php version$(pf;N)"
  159.        list_existing;call_me existing;call_help;f
  160.    fi
  161.    exit1
  162. }
  163. does_not_exist(){ f;o;Pbg;pf;echo "\"$1\" is not an existing php version$(pf;N)";list_existing;call_me existing;call_help;f;exit1;}
  164. no_candidate(){ f;os;Pbg;pf;echo "Version \"$1\" cannot be installed with your Apt sources$(pf;N;f)";list_candidates;call_me candidates;need_sury_repo;call_help;f;}
  165. no_higher_candidate(){ f;pf;echo "The installed PHP version ($PHP_VERSION) is the highest available from your configured apt sources.";list_candidates;call_me candidates;need_sury_repo;downgrade_possible;anykey;}
  166. need_ppa(){ need_sury_repo;}
  167. downgrade_possible(){ pf;echo "However, it is possible to downgrade to a lower version using this script, although I don't recommend it";}
  168. end_message(){
  169.    f;separator xGRAY;f
  170.    echo "  $(format_string "This script is continually being enhanced and expanded. This means it will be able to perform even more tasks for you safely in the future." 3)"
  171.    GRAY;echo "  $(format_string "Feel free to donate 1 € by $(C)Paypal$(GRAY) to $(lG)ernolf$(C)<at>$(lG)global-social.net$(GRAY) or at least leave a $(R)❤️$(GRAY) at $(button 1;GRAY) and spread the word, if you like my work." 3;N)"
  172.    f;o3;button 1;W;pf;echo "https://help.nextcloud.com/t/php-updater-a-script-to-upgrade-php-in-a-safe-way/180215"
  173.    f;separator xGRAY;f
  174. }
  175.  
  176. # TODO 1 -->
  177. list_tasks(){
  178.    echo "explain Show help page"
  179.    echo "check_distrib Check runing distribution (done automaticaly on first run)"
  180.    echo "list_ubuntu/debian List ubuntu/debian distributions"
  181.    echo "list_existing List existing PHP-Versions"
  182.    echo "list_apt_sources List APT sources"
  183.    echo "list_apt_sources_files List APT sources files"
  184.    echo "add_apt_sources Add APT sources"
  185.    echo "remove_apt_sources Remove APT sources"
  186.    echo "list_candidates List instalable PHP-Versions offered by APT sources"
  187.    echo "list_installed List installed PHP-related packages and modules"
  188.    echo "list_ht_servers List enabled web server resources"
  189.    echo "switch_php_version Set the default PHP version"
  190. }
  191.  
  192. tasks(){
  193.    local -i n=1 i c2=9 c3=29
  194.    local -a task_list
  195.    local -l num key
  196.  
  197.    mapfile -t task_list< <(list_tasks)
  198.    (( ${#task_list[@]} )) || {
  199.        o2;echo "no tasks available."
  200.        anykey
  201.        return
  202.    }
  203.    line '=' P 2/78 b1
  204.    o3;B;echo "These tasks are available for selection:";N
  205.    o4;Y;echo "Num$(o $c2)Task$(o $c3)Description"
  206.    line '-' dP 2/78
  207.    for i in "${!task_list[@]}"; do
  208.        task="${task_list[i]}"
  209.        description=""
  210.        o3;echo "- $((n+i))$(o $c2)\"$task\"$(o $c3)\"$description\""
  211.    done
  212.    line '-' dP 2/78 a2
  213.    o3;echo "Enter the number of the task you want to execute $(q2q)"
  214.    while :; do
  215.        read -rsn 1 num
  216.        [ "$num" = "q" ] && exit1
  217.        [[ "$num" =~ ^[1-9]$ ]] || {
  218.            o3;echo "$invi Please enter a valid number or $(q2q)"
  219.            continue
  220.        }
  221.        (( num<n || num>=(n+${#task_list[@]}) )) && {
  222.            o3;echo "Invalid task number. Please choose a number from the list or $(q2q)"
  223.            continue
  224.        }
  225.        i="$((num-n))"
  226.        task="${task_list[i]}"
  227.        description=""
  228.        o3;echo "Your choice: task \"$task\""
  229.        o3;echo "do you want to execute this task?"
  230.        o3;echo "Press $(box y) to proceed - $(box c) to cancel - $(q2q): "
  231.        while :; do
  232.            read -rsn 1 key
  233.            case "$key" in
  234.                y)  break 2
  235.                    ;;
  236.                c)  return
  237.                    ;;
  238.                q)  exit1
  239.            esac
  240.        done
  241.    done
  242. }
  243. # TODO <-- 1
  244. ## void ##
  245. declare lang=$(echo "$LANG"|cut -d'_' -f1)
  246. declare OLD NEW SUGGESTION PKG PKGOLD PKGNEW DEFAULT_ANSWER FILE dpkg_package php_version php_version_old extension_dir fullpath module sort
  247.  
  248. $supported&&apt_need_update
  249.  
  250. declare verbose prefix
  251. verbose=false
  252. $verbose&&prefix="$(pf)"||prefix="$(o2;G)Examining the system:$(pf;W)"
  253. $verbose&&echo "Examining the system:"
  254. echo "${prefix}populating arrays with inventory results.."
  255.  
  256. # PACKAGES_INSTALLED_BY_DPKG
  257. $verbose&&echo "$(pf)Packages installed by dpkg.."
  258. populate_pkgs_by_dpkg_array
  259. if $supported; then
  260.    ext_state cleanup
  261.    ext_state fix
  262. fi
  263.  
  264. $verbose||te0
  265. # clear
  266.  
  267. # $1=old;$2=new
  268. case $1 in
  269.    --list-installed)
  270.        list_installed 'quiet=:'
  271.        exit 0
  272.        ;;
  273.    --list-candidates)
  274.        list_candidates
  275.        need_sury_repo
  276.        exit 0
  277.        ;;
  278.    --list-existing)
  279.        list_existing
  280.        exit 0
  281.        ;;
  282.    --switch-version)
  283.        $supported && switch_default_version
  284.        exit 0
  285.        ;;
  286.    --list-debian)
  287.        . <(require dist/debian)
  288.        list_supported_debian
  289.        exit 0
  290.        ;;
  291.    --list-ubuntu)
  292.        . <(require dist/ubuntu)
  293.        list_supported_ubuntu
  294.        exit 0
  295.        ;;
  296.    *)  :
  297. esac
  298.  
  299. if $supported && [ $# -eq 2 ];then
  300.    does_exist_ "${1//php/}" 1 && does_exist_ "${2//php/}" 0 && OLD="${1//php/}" NEW="${2//php/}" || explain
  301. fi
  302.  
  303. if $supported; then
  304.    if [ ${#VERSIONS[@]} -eq 1 ];then
  305.        [ "${VERSIONS[0]}" = "$PHP_VERSION" ]||version_mismatch
  306.        OLD=${VERSIONS[0]}
  307.        separator
  308.        f
  309.        echo " -$(W;format_string "Only one php version ($(C)$OLD$(W)) found, which is the thinkable best possible starting situation for this script. Simply follow the instructions and recommendations to install a new PHP version if possible, which then will adopt the settings of this PHP version by the means of this script." 3;N)"
  310.        f
  311.        anykey
  312.        separator
  313.        list_installed
  314.        anykey
  315.        list_candidates
  316.        call_me candidates
  317.        need_sury_repo
  318.        anykey
  319.        separator
  320.        if ask "$(qpf)Do you want to install a new php-version now" "$YES";then
  321.            SUGGESTION="$(i_ver "$OLD")"||{ no_higher_candidate;SUGGESTION="$(d_ver "$OLD")";}
  322.            rs1="$(os)please enter a new, not yet installed php-version…"
  323.            while :;do
  324.                cursor_ show
  325.                read -rp "E: Please enter the version string you want to install (e.g. '$SUGGESTION'): " NEW
  326.                cursor_ hide
  327.                os;echo "You entered: $NEW"
  328.                if [ -z "$NEW" ];then echo "$rs1";anykey
  329.                elif [ "$NEW" = "$OLD" ];then
  330.                    pf;echo "From the point of view of this script, php$NEW is already installed"
  331.                    echo "$rs1";anykey
  332.                elif does_exist_ "$NEW" 0;then
  333.                    if [[ " ${CAN[@]} " =~ " $NEW " ]];then
  334.                        ask "$(qpf)Are you ready to install php$NEW" "$YES"&&break||exit1
  335.                    else no_candidate "$NEW";fi
  336.                else does_not_exist;fi
  337.            done
  338.            install_new_php "$OLD" "$NEW"
  339.        else
  340.            exit0
  341.        fi
  342.    elif [ -n "$NEW" ];then
  343.        if [[ " ${CAN[@]} " =~ " $NEW " ]]; then
  344.            declare -a missing_new_packages
  345.            spinner C " . searching for php$NEW packages yet to be installed ." &
  346.            mapfile -t missing_new_packages< <(packages_diff $OLD $NEW)
  347.            kill_spinner
  348.            if [[ " ${VERSIONS[@]} " =~ " $NEW " ]]; then
  349.                if ((${#missing_new_packages[@]}));then
  350.                    array_populated missing_new_packages &
  351.                    if ((${#missing_new_packages[@]}==1)); then
  352.                        plu='is:' plu2='one:is' mnp_string="$(B)${missing_new_packages[0]}$(N)"
  353.                    else
  354.                        plu='ese:s' plu2='some:are' mnp_string="$(listify B ${missing_new_packages[@]})"
  355.                    fi
  356.                    separator
  357.                    echo " -$(format_string "You entered \"$(Y)$OLD$(N)\" as old and \"$(Y)$NEW$(N)\" as new version. Although php$NEW is installed, ${plu2%:*} $(Y)php$NEW$(N) package${plu#*:} ${plu2#*:} still missing compared to $(Y)php$OLD$(N) and the minimum packages that are needed to run a server like Nextcloud. Th${plu%:*} ${plu2#*:} the missing one${plu#*:}:" 3)"
  358.                    o3;echo "$(format_string "$mnp_string" 3)"
  359.                    os;echo "If you answer $(box no) here, the script will continue without installing th${plu%:*} package${plu#*:}."
  360.                    ask "$(qpf)Do you want to install th${plu%:*} package${plu#*:}" "$YES"&&install_new_php "$OLD" "$NEW"
  361.                fi
  362.            else
  363.                echo " -$(format_string "You entered \"$(Y)$OLD$(N)\" as old and \"$(Y)$NEW$(N)\" as new version. Since php$NEW is not yet installed at all, it will be installed from scratch." 3)"
  364.                ask "$(qpf)Are you ready to install php$NEW" "$YES"&&install_new_php "$OLD" "$NEW"||exit1
  365.            fi
  366.        else
  367.            no_candidate "$NEW"
  368.            pf;exit1
  369.        fi
  370.  
  371.        check_config $OLD
  372.  
  373.        declare -a c_f_a # changed files array
  374.        spinner C " . searching changed ini- and conf-files for php$OLD to be adapted into php$NEW ." &
  375.        mapfile -t c_f_a< <(p_nosort $(changed_files_ ini) $(changed_files_ conf))
  376.        kill_spinner
  377.        if (( ${#c_f_a[@]} )); then
  378.            for FILE in ${c_f_a[@]}; do
  379.                separator O
  380.                PKG=${FILE%:*} FILE=${FILE#*:}
  381.                [ -f "$FILE" ]||continue
  382.                f
  383.                if [ "$PKG" = "libapache2-mod-php$OLD" ]; then
  384.                    PKGOLD="$PKG" PKGNEW="${PKG//$OLD/$NEW}"
  385.                else
  386.                    PKGOLD="php$OLD-$PKG" PKGNEW="php$NEW-$PKG"
  387.                fi
  388.                preq="Q:$(P;format_string "Do you want to migrate the values from the$(C) $(basename $FILE)$(P) for $(Y)$PKGOLD$(P) into the corresponding$(C) $(basename $FILE)$(P) for$(Y) $PKGNEW" 3;N)"
  389.                if ask "$preq" $YES;then
  390.                    merge_settings
  391.                fi
  392.            done
  393.        fi
  394.        check_fpm_pool_files
  395.        declare -a o_c_f_a # other changed files array
  396.        spinner C " . searching other changed files for php$OLD to be adapted into php$NEW ." &
  397.        mapfile -t o_c_f_a< <(p_nosort $(changed_files_ other))
  398.        kill_spinner
  399.        if (( ${#o_c_f_a[@]} )); then
  400.            for FILE in ${o_c_f_a[@]}; do
  401.                separator O
  402.                PKG=${FILE%:*} FILE=${FILE#*:}
  403.                f;treat_other_files
  404.            done
  405.        fi
  406.        separator
  407.        echo " -$(format_string "The migration of the settings from php-$OLD to php-$NEW is now completed, unless you have deliberately left out files or settings. These can be made up at any time with:" 3)"
  408.        f;G;echo "$(prompt;lB) $me$forceflag$(C) $OLD $NEW";N
  409.        f;O;echo " -$(format_string "You now can switch the php version from $(C)php-$OLD$(O) to $(C)php-$NEW$(O) for the commandline and your webserver. Therefore call:" 3;N)"
  410.        f;G;echo "$(prompt;P) $me$forceflag --switch-version";N
  411.        end_message
  412.        exit0
  413.    else # if [ $# -ne 2 ]; then
  414.        first_brief_help "Brief help:"
  415.        f
  416.        anykey
  417.        separator
  418.        list_installed
  419.        anykey
  420.        separator
  421.        list_candidates
  422.        call_me candidates
  423.        need_sury_repo
  424.        anykey
  425.        separator
  426.        f
  427.        brief_help "this would be possible calls:"
  428.        N;f;exit0
  429.    fi
  430. else
  431.    f;lB;echo " -$(format_string "Your distribution is marked as not fully supported. The script is running in $(lG)safe mode$(lB) and will only provide informations about your system but will make no changes to your system$($needforce&&echo -n " unless you call it with $(GRAYbg)[ --force ]";N)" 3)"
  432.    f
  433.    anykey
  434.    separator
  435.    list_installed
  436.    anykey
  437.    separator
  438.    list_candidates
  439.    call_me candidates
  440.    separator
  441.    need_sury_repo
  442.    anykey
  443.    separator
  444.    ask "$(qpf)Do you want to read the help" "$YES" && explain
  445.    N;f;exit0
  446. fi
  447.  
  448. -----BEGIN PGP SIGNATURE-----
  449.  
  450. iQIzBAABCgAdFiEEPuQ6hNK6Y1qU4QM7CxRROaFwcVwFAmZ9rVsACgkQCxRROaFw
  451. cVyhgA//b8Z39skY78E4pAjUigqmBbDmG9/imYLq2sVy0mXR3ElMJK8wAvvfHO3g
  452. 3StZxnKAA0nkrJZf5CRseWBR1a92zCRaDEmlabtTmKJByV8krmGze6xb/7fOpRuV
  453. A4b6OpB7EIipKPHeDBX7NsYXMK9NNDnhVefU8VejLKqAwMikOCgXkiVNgqE2aYKS
  454. EFUwDyNu9F7NwXp8NckiKm+sizj9M/GvxYb59yrd81KTSSO6y/K88gEzemI9sKPL
  455. 5dcbI3e72k9GFJp2v5nc2vFL7fjqO4PL/RKIZtFbxbJDTlO/lI+S1SYtLS/J+YwN
  456. irV7jAcPZHhglfp+tPofiMg2kZh/cF4+LqPoG9/a+wVcWdbdJ7nrDhSs6nptp90I
  457. 06ViSJ0mVW0x4K7Le8frLda6cqlLAC6IEZrAX+D3doCRw98LMXNix1yiZlfawt2w
  458. tyQjTtWmBfUvK0gQxfBqDZWrqiruyHx8y5+NCrr9bG7eri5t9GKKca0zY3zzgJkK
  459. jjuq9uOcVvgyzCRmtnMsk9xGBmbtHm8SWcJm1ho4UkHzoqzslLziQGkP6QLWIGok
  460. xLnZSGAqE45uq8GAJzeqkyI9F6GD7UGimUh7LBaek6mg3J8MQQMwm2Nocs7NABFd
  461. qm4Hj+47lPY8YquxSeUMViYbd5IJ0HebXQcUuS3In08Osli48oI=
  462. =5Yzu
  463. -----END PGP SIGNATURE-----
  464. v=false
  465. # sha256sum: 8b3deb3dd2e339a6e8e173b565787a535f3b477576fecfbc09cfcedfabca9a40

paste.retronerd.at ist fuer Quelltexte und generellen Debugging Text.

Login oder Registrieren um zu bearbeiten, loeschen, um deine Pastes zu verfolgen und mehr.

Raw Paste

Login oder Registrieren um diesen Paste zu bearbeiten oder zu forken. Es ist kostenlos.