Refactor linux.sh

This commit is contained in:
Shivam Mathur 2020-05-13 20:48:18 +05:30
parent 5af5f992ec
commit 55fe8db60d
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A

View File

@ -20,17 +20,14 @@ add_log() {
update_ppa() { update_ppa() {
if [ "$ppa_updated" = "false" ]; then if [ "$ppa_updated" = "false" ]; then
sudo "$debconf_fix" apt-get update >/dev/null 2>&1 sudo "$debconf_fix" apt-get update >/dev/null 2>&1
#find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
#ppa_updated="true"
fi fi
} }
# Function to configure PECL # Function to configure PECL
configure_pecl() { configure_pecl() {
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
sudo touch "$scan_dir"/99-pecl.ini >/dev/null 2>&1
for tool in pear pecl; do for tool in pear pecl; do
sudo "$tool" config-set php_ini "$scan_dir"/99-pecl.ini >/dev/null 2>&1 sudo "$tool" config-set php_ini "$pecl_file" >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1 sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1 sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done done
@ -65,6 +62,7 @@ check_extension() {
delete_extension() { delete_extension() {
extension=$1 extension=$1
sudo sed -i "/$extension/d" "$ini_file" sudo sed -i "/$extension/d" "$ini_file"
sudo sed -i "/$extension/d" "$pecl_file"
sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1 sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1 sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
} }
@ -103,7 +101,7 @@ add_pecl_extension() {
pecl_version=$2 pecl_version=$2
prefix=$3 prefix=$3
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then
echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" echo "$prefix=$ext_dir/$extension.so" >>"$pecl_file"
fi fi
ext_version=$(php -r "echo phpversion('$extension');") ext_version=$(php -r "echo phpversion('$extension');")
if [ "$ext_version" = "$pecl_version" ]; then if [ "$ext_version" = "$pecl_version" ]; then
@ -195,12 +193,15 @@ setup_master() {
update_ppa && $apt_install libzip-dev update_ppa && $apt_install libzip-dev
tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz
install_dir=~/php/"$version" install_dir=~/php/"$version"
bintray_url=https://dl.bintray.com/shivammathur/php/"$tar_file"
sudo mkdir -m 777 -p ~/php sudo mkdir -m 777 -p ~/php
update_ppa && $apt_install libicu64 libicu-dev >/dev/null 2>&1 curl -o /tmp/"$tar_file" -sSL "$bintray_url"
curl -SLO https://dl.bintray.com/shivammathur/php/"$tar_file" >/dev/null 2>&1 sudo tar xf /tmp/"$tar_file" -C ~/php
sudo tar xf "$tar_file" -C ~/php >/dev/null 2>&1 for tool_path in "$install_dir"/bin/*; do
rm -rf "$tar_file" tool=$(basename "$tool_path")
sudo ln -sf -S "$version" "$install_dir"/bin/* /usr/bin/ sudo cp "$tool_path" /usr/bin/"$tool$version"
sudo update-alternatives --install /usr/bin/"$tool" "$tool" /usr/bin/"$tool$version" 50
done
sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini
} }
@ -245,8 +246,7 @@ existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
# Setup PHP # Setup PHP
step_log "Setup PHP" step_log "Setup PHP"
sudo mkdir -p /var/run sudo mkdir -p /var/run /run/php
sudo mkdir -p /run/php
if [ "$existing_version" != "$version" ]; then if [ "$existing_version" != "$version" ]; then
if [ ! -e "/usr/bin/php$version" ]; then if [ ! -e "/usr/bin/php$version" ]; then
@ -267,8 +267,10 @@ else
fi fi
semver=$(php_semver) semver=$(php_semver)
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") pecl_file="$scan_dir"/99-pecl.ini
sudo chmod 777 "$ini_file" "$tool_path_dir" sudo touch "$pecl_file" >/dev/null 2>&1
sudo chmod 777 "$ini_file" "$tool_path_dir" "$pecl_file"
add_log "$tick" "PHP" "$status PHP $semver" add_log "$tick" "PHP" "$status PHP $semver"