Selaa lähdekoodia

subo utils_wp.sh

develop
Pablo 3 vuotta sitten
vanhempi
commit
36e51a5fdf
1 muutettua tiedostoa jossa 131 lisäystä ja 0 poistoa
  1. +131
    -0
      utils_wp.sh

+ 131
- 0
utils_wp.sh Näytä tiedosto

@@ -0,0 +1,131 @@
#!/bin/bash -x

usage()
{
echo "Usage: $0 [-h ] [ -s website ] [ -l | -v | -u userid ]" >&2
exit 1
}


while getopts ":hs:lu:v" opt;
do
case "$opt" in
h)
echo "Usage:"
echo " $0 -h Display this help message."
echo " $0 -s <website> The website is a mandatory argument."
echo " $0 -s <website> -l List WordPress users."
echo " $0 -s <website> -v Display the WordPress version"
echo " $0 -s <website> -u <userid> Generate and set a random password for this WordPress userid."
exit 0
;;
s)
WEB=$OPTARG
;;
l)
LIST=1
;;
u)
USERID=$OPTARG
;;
v)
VERSION=1
;;
\?)
echo "Error: Invalid Option: -${OPTARG}" >&2
usage
;;
:)
echo "Error: -${OPTARG} requires an argument."
usage
;;
*)
usage
;;
esac
done

if [ -z ${WEB} ]; then
usage
fi

# declaration section


# functions section

check_err()
{
STATUS=$?
if [ ${STATUS} -ne 0 ]; then
echo "Unexpected error: ${STATUS}"
exit ${STATUS}
fi
}

function get_sysuser() {
SYSUSER=`ls -l /var/www/ | grep ${WEB} | awk '{ print $11 }' | awk -F'/' '{ print $6 }'`
echo ${SYSUSER}
}

function get_rootpath() {
ROOTPATH="/var/www/${WEB}"
echo ${ROOTPATH}
}

function get_php() {

VERSION=`echo "select server_php.name from server_php join web_domain where server_php.server_php_id=web_domain.server_php_id and web_domain.server_php_id=90 and web_domain.server_php_id!=0 and web_domain.domain like '${WEB}'\G" | mysql --defaults-file=/etc/mysql/debian.cnf dbispconfig | awk '$1 ~ /:/ { print $2 }'`
if [ -z "${VERSION}" ]; then
echo "/usr/bin/php"
else
echo "/opt/php-${VERSION}/bin/php"
fi
}

function change_user_password() {
MYUSER=$(get_sysuser)
MYPATH=$(get_rootpath)
MYPHP=$(get_php)
chsh -s /bin/bash ${MYUSER}
cp /root/bin/wp-cli.phar ${MYPATH}/private
NEWPASS=`openssl rand -base64 12`
su -c "cd web && ${MYPHP} ../private/wp-cli.phar user update ${USERID} --user_pass=${NEWPASS}" - ${MYUSER}
rm ${MYPATH}/private/wp-cli.phar
chsh -s /bin/false ${MYUSER}
echo ${NEWPASS}
}

function list_wp_users() {
MYUSER=$(get_sysuser)
MYPATH=$(get_rootpath)
MYPHP=$(get_php)
chsh -s /bin/bash ${MYUSER}
cp /root/bin/wp-cli.phar ${MYPATH}/private
su -c "cd web && ${MYPHP} ../private/wp-cli.phar user list" - ${MYUSER}
rm ${MYPATH}/private/wp-cli.phar
chsh -s /bin/false ${MYUSER}
}

function show_wp_version() {
MYUSER=$(get_sysuser)
MYPATH=$(get_rootpath)
MYPHP=$(get_php)
chsh -s /bin/bash ${MYUSER}
cp /root/bin/wp-cli.phar ${MYPATH}/private
su -c "cd web && ${MYPHP} ../private/wp-cli.phar core version --extra" - ${MYUSER}
rm ${MYPATH}/private/wp-cli.phar
chsh -s /bin/false ${MYUSER}
}

# main section

if [ "${LIST}" == 1 ]; then
list_wp_users
exit
elif [ "${VERSION}" == 1 ]; then
show_wp_version
exit
else
change_user_password
fi

Loading…
Peruuta
Tallenna