captaincore/lib/remote-scripts/activate
2023-11-15 14:55:10 -05:00

59 lines
No EOL
1.4 KiB
Bash

#!/usr/bin/env bash
#
# Activate
#
# `activate --wp_content=<wp-content-dir>`
#
# Loop through arguments and separate regular arguments from flags
for arg in "$@"; do
# Add to arguments array. (Does not starts with "--")
if [[ $arg != --* ]]; then
count=1+${#arguments[*]}
arguments[$count]=$arg
continue
fi
# Remove leading "--"
flag_name=$( echo $arg | cut -c 3- )
# Add to flags array
count=1+${#flags[*]}
flags[$count]=$arg
# Process flags without data (Assign to variable)
if [[ $arg != *"="* ]]; then
flag_name=${flag_name//-/_}
declare "$flag_name"=true
fi
# Process flags with data (Assign to variable)
if [[ $arg == *"="* ]]; then
flag_value=$( echo $flag_name | perl -n -e '/.+?=(.+)/&& print $1' ) # extract value
flag_name=$( echo $flag_name | perl -n -e '/(.+?)=.+/&& print $1' ) # extract name
flag_name=${flag_name/-/_}
# Remove first and last quote if found
flag_value="${flag_value%\"}"
flag_value="${flag_value#\"}"
declare "$flag_name"="$flag_value"
continue
fi
done
if [[ "$wp_content" == "" ]]; then
wp_content="wp-content"
fi
if [ -f "${wp_content}/mu-plugins/captaincore-deactivated.php" ]; then
echo "Removing ${wp_content}/mu-plugins/captaincore-deactivated.php"
rm "${wp_content}/mu-plugins/captaincore-deactivated.php"
fi
if [[ "$provider" == "kinsta" ]]; then
wp kinsta cache purge --all --skip-themes
fi