Skip to content

Instantly share code, notes, and snippets.

@abcarroll
Created February 12, 2020 18:45
Show Gist options
  • Select an option

  • Save abcarroll/7d95dceec573b4f528b01bc76d003877 to your computer and use it in GitHub Desktop.

Select an option

Save abcarroll/7d95dceec573b4f528b01bc76d003877 to your computer and use it in GitHub Desktop.
Interactive tool to install PHP on Debian based systems, including Ubuntu.
#!/bin/bash
# ----
# Written By
# A.B. Carroll <[email protected]>,
# Feb. 2020
#
# Released under the terms of "the Unlicense"
# For the complete license text, please see <http://unlicense.org/>
# ----
# This is free and unencumbered software released into the public domain.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
# ----
# This code is terrible. Many variables are unescaped. There are very long lines.
# HOWEVER, ... It does work on my system. Patches / PRs welcome.
# ----
dialog --ok-button "Next" --title "PHP Package Installer for Apt" --msgbox "Please note that this still relies on local system packages within apt. Only packages that are installable through apt-get will be shown. \n\nThis tool currently does NOT support uninstalling packages. You may uninstall them with apt-get yourself, of course.\n\nIf you use an apt repository that allows multiple versions to be installed at once, the default version which is invoked via the php command can usually be updated via the update-alternatives system. See the manual page update-alternatives(1) for more.\n\nThis tool always welcomes patches." 17 72
ALL_EXTENSIONS=$(sudo apt-cache search ^php | perl -ne '/^(php\d\.\d-[^\s]+).*/ && print "$1\n"' | sort -u | less)
dialog --title "Debugging Symbols?" --defaultno --trim --yes-label "Yes" --yesno "Are you planning on installing debugging symbols for the PHP packages? Unless you know you need them, select no." 0 0
USE_DEBUG=$?
if [[ ! $USE_DEBUG -eq 0 ]]
then
ALL_EXTENSIONS=$(echo "$ALL_EXTENSIONS" | grep -v 'dbgsym')
fi
ALL_VERSIONS=$(echo "$ALL_EXTENSIONS" | perl -ne 's/^php(\d\.\d).*/\1/g; /^\d\.\d/ && print unless $a{$1}++' | sort)
DIALOG_ARG=""
while read -r ver
do
DIALOG_ARG="${DIALOG_ARG} ${ver} off"
done <<< "$ALL_VERSIONS"
PIPE=$(mktemp -u)
mkfifo $PIPEA
exec 4<> $PIPEA
dialog --output-fd 4 --no-items --ok-label "Next" --checklist "Which version(s) of PHP do you wish to install? (You can select the default version later)" 0 0 0 ${DIALOG_ARG}
PIPE=$(mktemp -u)
mkfifo $PIPEB
exec 5<> $PIPEB
DIALOG_ARG=""
while IFS= read -r -u 4 -d " " -n 4 -t 0.05 VER || [ -n "$VER" ]s
do
while read -r EXT
do
if [[ "${EXT:0:6}" == "php$VER" ]]
then
#INSTALLABLE_EXT=("${INSTALLABLE_EXT[@]}" "$EXT")
DIALOG_ARG="${DIALOG_ARG} ${EXT} off"
fi
done <<< "$ALL_EXTENSIONS";
dialog --output-fd 5 --no-items --ok-label "Next" --checklist "For PHP $VER, which extensions do you wish to install?" 0 0 0 ${DIALOG_ARG}
done
INSTALL_ARG=""
while IFS= read -r -u 5 -d " " -t 0.05 PKG || [ -n "$PKG" ]
do
INSTALL_ARG="${INSTALL_ARG} $PKG"
done
sudo apt-get -y install $INSTALL_ARG
rm -- -f "$PIPEA"
rm -- -f "$PIPEB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment