Advertisement
ETFovac

Multiuser plugin updater

Sep 27th, 2016
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.26 KB | None | 0 0
  1. #!/bin/sh
  2. #usage ./update-plugin plugin-name pluginver
  3. function updateit {
  4.  
  5.         pluginpath=$1
  6.         pluginname=$2
  7.         user=$3
  8.  
  9.         pluginmain=${pluginpath%$pluginname}
  10.  
  11.         echo "Updating plugin for $user"
  12.  
  13.         $(rm -rf $pluginpath)
  14.         $(cp -R /opt/$pluginname/ $pluginmain)
  15.         $(chown -R $user:$user $pluginpath)
  16.         $(find $pluginpath -type f -print0 | xargs -0 chmod 0644)
  17.         $(find $pluginpath -type d -print0 | xargs -0 chmod 0755)
  18.  
  19. }
  20.  
  21. plugin=$1
  22. pluginver=$2
  23.  
  24. usernames=$(find /var/cpanel/users -type f -print0 | xargs -n 1 -0 echo)
  25. prefix="/var/cpanel/users/"
  26.  
  27. $(rm -rf /opt/"$plugin"*)
  28. #$(rm -rf /opt/$plugin.zip)
  29. $(wget -O /opt/$plugin.zip https://downloads.wordpress.org/plugin/$plugin.$pluginver.zip)
  30. $(unzip /opt/"$plugin".zip -d /opt)
  31.  
  32. for i in $usernames; do
  33.  
  34.         username=${i#$prefix}
  35.  
  36.         path=$(find /home/$username -type d -name "$plugin")
  37.  
  38.         if echo $path | grep -E '[ "]' >/dev/null
  39.         then
  40.  
  41.                 for pp in $path; do
  42.                         updateit $pp $plugin $username
  43.                 done
  44.  
  45.         else
  46.                 if [[ $path = *[!\ ]* ]]; then
  47.                         updateit $path $plugin $username
  48.                 fi
  49.  
  50.         fi
  51.  
  52.  
  53. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement