-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
18.x php update helper #291
Merged
JedMeister
merged 5 commits into
turnkeylinux:18.x
from
JedMeister:18.x-php-update-helper
Jan 25, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51b42c0
insert tkl-upgrade-php.sh
9b8b726
Apply shellcheck & visual tweaks
JedMeister 570026b
Give Marcos his credit where credit is due :)
JedMeister 1de5088
Actually remove file ext - as it's in the PATH
JedMeister ea16e4b
Fix minor mistake/typo as noted by @ongle
JedMeister File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
|
||
# Function to display PHP version choices and get user input | ||
choose_php_version() { | ||
echo "Select the PHP version to install:" | ||
echo "1) PHP 7.3" | ||
echo "2) PHP 7.4" | ||
echo "3) PHP 8.0" | ||
echo "4) PHP 8.1" | ||
echo "5) PHP 8.2" | ||
echo "6) PHP 8.3" | ||
read -p -r "Enter choice [1-5]: " php_choice | ||
|
||
case $php_choice in | ||
1) PHPV_NEW="7.3";; | ||
2) PHPV_NEW="7.4";; | ||
3) PHPV_NEW="8.0";; | ||
4) PHPV_NEW="8.1";; | ||
5) PHPV_NEW="8.2";; | ||
6) PHPV_NEW="8.3";; | ||
*) echo "Invalid choice. Exiting."; exit 1;; | ||
esac | ||
} | ||
|
||
# Function to check if new packages exist and exclude json if PHP version is >= 7.2 | ||
check_new_packages() { | ||
missing_pkgs=() | ||
for pkg in $PHP_NEW_PKGS; do | ||
if ! apt-cache show "$pkg" > /dev/null 2>&1; then | ||
missing_pkgs+=("$pkg") | ||
fi | ||
done | ||
|
||
if [ ${#missing_pkgs[@]} -ne 0 ]; then | ||
echo "The following packages do not exist in PHP version $PHPV_NEW: ${missing_pkgs[*]}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Start of the script | ||
echo "Starting PHP upgrade script..." | ||
|
||
# Display current PHP version | ||
echo "Current PHP version:" | ||
php -v | ||
|
||
# Step 1: Set PHP version to install and collect current PHP version & packages | ||
choose_php_version | ||
PHPV_OLD=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;') | ||
PHP_OLD_PKGS=$(apt-cache policy -- "*php${PHPV_OLD}*" \ | ||
| grep -v "Installed: (none)" \ | ||
| grep "Installed:" -B1 \ | ||
| sed -n "\|php${PHPV_OLD}| s|^\([a-z0-9\.-]*\).*$|\1|p" \ | ||
| grep -v "json") | ||
PHP_NEW_PKGS="${PHP_OLD_PKGS//$PHPV_OLD/$PHPV_NEW}" | ||
|
||
# Step 2: Set up sury.org PHP | ||
curl -sSL https://packages.sury.org/php/README.txt | bash -x | ||
|
||
# Step 3: Install relevant new packages | ||
check_new_packages | ||
echo "Installing new packages..." | ||
# shellcheck disable=SC2086 | ||
apt install -y $PHP_NEW_PKGS | ||
|
||
# Detect the web server and handle PHP module accordingly | ||
if systemctl is-active --quiet apache2; then | ||
# Apache is running | ||
a2dismod "php${PHPV_OLD}" | ||
a2enmod "php${PHPV_NEW}" | ||
systemctl restart apache2 | ||
elif systemctl is-active --quiet nginx; then | ||
# Nginx is running, restart PHP-FPM if installed | ||
systemctl restart php${PHPV_NEW}-fpm | ||
elif systemctl is-active --quiet lighttpd; then | ||
# Lighttpd is running, restart PHP-FPM if installed | ||
systemctl restart php${PHPV_NEW}-fpm | ||
else | ||
echo "No supported web server detected. Please manually configure your web server to use the new PHP version." | ||
fi | ||
|
||
# Update CLI version | ||
update-alternatives --set php /usr/bin/php${PHPV_NEW} | ||
|
||
echo "PHP upgrade completed successfully." |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
[1-6]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch man!