|
#!/bin/bash |
|
# |
|
# WordPressのプラグインディレクトリの所有者及びパーミッションを一括設定するスクリプト |
|
# |
|
# Author : Nia Tomonaka (@nia_tn1012) |
|
# License : MIT License |
|
|
|
# 変数 |
|
# 所有者 |
|
OWNER=ftp_username |
|
# グループ |
|
GROUP=www |
|
# wp-contentのディレクトリ |
|
WPCDIR=/var/www/html/wp-content |
|
# wp-content/plugins内のディレクトリに設定するパーミッション |
|
PERDIR=775 |
|
# wp-content/plugins内のファイルに設定するパーミッション |
|
PERFILE=664 |
|
# 翻訳ファイルの言語 |
|
LANG=ja |
|
|
|
# コマンドライン引数にプラグインのディレクトリ名が指定された時、 |
|
# そのディレクトリ内のファイルとディレクトリの所有者とパーミッションを設定します。 |
|
if [ $# -gt 0 ]; then |
|
# コマンドライン引数に指定されたプラグインディレクトリ名を列挙します。 |
|
for i in $@ |
|
do |
|
# コマンドライン引数に'../'が含まれているかどうかをチェックします。(意図しないディレクトリにアクセスするインジェクション対策) |
|
if [ `echo $i | grep '\.\./'` ]; then |
|
echo -e "\033[1;35mError\033[0;39m - Cannot contain '../' in commandline argments for security measures." |
|
# 指定されたプラグインのディレクトリが存在するかチェックします。 |
|
elif [ -e $WPCDIR/plugins/$i ]; then |
|
echo -e "\033[1;32mInfo.\033[0;39m - Directory:'wp-content/plugins/$i' is found." |
|
|
|
# そのプラグインのディレクトリ内の所有者とグループを設定します。 |
|
chown -R $OWNER:$GROUP $WPCDIR/plugins/$i |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in the directory:'wp-content/plugins/$i' to $OWNER:$GROUP." |
|
|
|
# そのプラグインのディレクトリ内のディレクトリのパーミッションを設定します。 |
|
find $WPCDIR/plugins/$i/ -type d -exec chmod $PERDIR {} \; |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the directories permissions in the directory:'wp-content/plugins/$i' to $PERDIR." |
|
|
|
# そのプラグインのディレクトリ内のファイルのパーミッションを設定します。(但し、.htaccessと.htpasswdを除きます。) |
|
find $WPCDIR/plugins/$i/ -type f -not -name '.htaccess' -not -name '.htpasswd' -exec chmod $PERFILE {} \; |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files permissions in the directory:'wp-content/plugins/$i' to $PERFILE." |
|
|
|
# 指定されたプラグインの翻訳ファイルがあるかどうかチェックします。 |
|
if [ -e $WPCDIR/languages/plugins/$i-$LANG.mo ] || [ -e $WPCDIR/languages/plugins/$i-$LANG.po ]; then |
|
echo -e "\033[1;32mInfo.\033[0;39m - Directory of translation file:'$WPCDIR/languages/plugins/$i-$LANG' is found." |
|
|
|
# そのプラグインの翻訳ファイルの所有者とグループを設定します。 |
|
chown $OWNER:$GROUP $WPCDIR/languages/plugins/$i-$LANG.* |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in the directory:'wp-content/languages/plugins/$i-$LANG' to $OWNER:$GROUP." |
|
|
|
# そのプラグインの翻訳ファイルのパーミッションを設定します。 |
|
chmod $PERFILE $WPCDIR/languages/plugins/$i-$LANG.* |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files permissions in the directory:'wp-content/languages/plugins/$i-$LANG' to $PERFILE." |
|
fi |
|
else |
|
echo -e "\033[1;35mError\033[0;39m - Directory:'wp-content/plugins/$i' is not found." |
|
fi |
|
done |
|
# コマンドライン引数になにも指定していない場合、 |
|
else |
|
# プラグインディレクトリ内のすべてのファイルとディレクトリの所有者及びグループを設定します。 |
|
chown -R $OWNER:$GROUP $WPCDIR/plugins |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in all of the plug-in directory to $OWNER:$GROUP." |
|
# プラグインの翻訳ファイルの所有者及びグループを設定します。 |
|
chown -R $OWNER:$GROUP $WPCDIR/languages/plugins |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in all of the directory of plug-in translation file to $OWNER:$GROUP." |
|
|
|
# プラグインディレクトリ内のすべてのディレクトリのパーミッションを設定します。 |
|
find $WPCDIR/plugins/ -type d -exec chmod $PERDIR {} \; |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the directories permissions in all of the plug-in directory to $PERDIR." |
|
|
|
# プラグインディレクトリ内のすべてのファイルのパーミッションを設定します。(但し、.htaccessと.htpasswdを除きます。) |
|
find $WPCDIR/plugins/ -type f -not -name '.htaccess' -not -name '.htpasswd' -exec chmod $PERFILE {} \; |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files permissions in the directory:'wp-content/plugins/$1' to $PERFILE." |
|
# プラグインの翻訳ファイルのパーミッションを設定します。 |
|
find $WPCDIR/languages/plugins/ -type f -not -name '.htaccess' -not -name '.htpasswd' -exec chmod $PERFILE {} \; |
|
echo -e "\033[1;32mInfo.\033[0;39m - Set the files permissions in the directory:'wp-content/languages/plugins/$1' to $PERFILE." |
|
fi |