WP-tools/update_wp_sites.sh

148 lines
3.4 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
WEB_ROOT="/var/www"
# Check if the web root directory exists
if [ ! -d "$WEB_ROOT" ]; then
echo "Web root directory not found: $WEB_ROOT"
exit 1
fi
menu1="select the operation ************\r\n"
menu1="${menu1} 1) list admin users\r\n"
menu1="${menu1} 2) list themes\r\n"
menu1="${menu1} 3) update themes\r\n"
menu1="${menu1} 4) list plugins\r\n"
menu1="${menu1} 5) update plugins\r\n"
menu1="${menu1} E) Exit\r\n"
done=0
while [ $done -eq 0 ]
do
echo -e ${menu1}
read n
done=1
case $n in
1) selected_action="user list --role=administrator"
echo "You chose to list admin users";;
2) selected_action="theme list"
echo "You chose to list themes";;
3) selected_action="theme update"
echo "You chose to update themes";;
4) selected_action="plugin list"
echo "You chose to list plugins";;
5) selected_action="plugin update"
echo "You chose to update plugins";;
E) exit;;
e) exit;;
*) echo "invalid option"
done=0;;
esac
echo ""
done
# Loop through each directory in the web root
number=1
cd $WEB_ROOT
menu2="select the site(s) ************\r\n"
folders="$(find . -maxdepth 1 -type l)"
for site_dir in $folders; do
if [ -d "$site_dir"/web/wp-content ]; then
site_dir_name=$(basename "$site_dir")
site_dir_name_array+=("$site_dir_name")
menu2="${menu2} $number: $site_dir_name\r\n"
number=`expr $number + 1`
fi
done
menu2="${menu2} A: All\r\n"
menu2="${menu2} E) Exit\r\n"
#echo "---"$number
done=0
while [ $done -eq 0 ]
do
echo -e ${menu2}
read n
done=1
case $n in
A) selected_sites="all"
echo "You chose All";;
a) selected_sites="all"
echo "You chose All";;
[0-$number])
n=`expr $n - 1`
if [ -d ${site_dir_name_array[${n}]} ]; then
selected_sites=""${site_dir_name_array[${n}]}
echo "You chose "$selected_sites
else
echo "invalid option"
done=0
fi;;
E) exit;;
e) exit;;
*) echo "invalid option"
done=0;;
esac
echo ""
done
if [ $selected_sites == "all" ]; then
for site in "${site_dir_name_array[@]}"; do
link=$(readlink "$WEB_ROOT/$site")
owner=$(basename "$link")
cd $WEB_ROOT/$site/web/
sudo -u $owner wp $selected_action
cd -
done
else
link=$(readlink "$WEB_ROOT/$selected_sites")
owner=$(basename "$link")
cd $WEB_ROOT/$selected_sites/web/
sudo -u $owner wp $selected_action
cd -
fi
exit
# Loop through each directory in the web root
for client_dir in "$WEB_ROOT"/*/; do
if [ -d "$client_dir" ]; then
client_dir_name=$(basename "$client_dir")
if [[ "$client_dir_name" == client* ]]; then
for site_dir in "$client_dir"*/; do
if [ -d "$site_dir" ]; then
site_dir_name=$(basename "$site_dir")
if [[ "$site_dir_name" == web* ]]; then
if [ -d "$site_dir"web/wp-content ]; then
echo "Processing site: $site_dir_name"
echo
cd "$site_dir"web/
if [ "$1" ]; then
# sudo -u $site_dir_name wp theme list
# sudo -u $site_dir_name wp plugin list
#sudo -u $site_dir_name wp user list --role=administrator --format=csv
#sudo -u $site_dir_name wp $1
fi
cd -
fi
fi
fi
done
fi
echo "Finished processing client: $client_dir_name"
echo ""
fi
done