Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Last active November 5, 2021 06:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Nia-TN1012/d7d8bbbd3288b2be88c95602d6b33b4b to your computer and use it in GitHub Desktop.
Save Nia-TN1012/d7d8bbbd3288b2be88c95602d6b33b4b to your computer and use it in GitHub Desktop.
WordPressにて、wp-content内の指定したファイルとディレクトリの所有者とパーミッションを設定するスクリプトです。

概要

WordPressのプラグインやテーマ、アップロードディレクトリ内の、ファイルとディレクトリの所有者及びパーミッションを設定するスクリプトです。

スクリプト

  • plugins.sh
  • themes.sh
  • uploads.sh

使い方(plugins.shでの例)

# すべてのプラグインのファイルとディレクトリの所有者及びパーミッションを設定します。
$ bash plugins.sh

# プラグインディレクトリ名(ここでは「lemon」)を指定して、所有者及びパーミッションを設定します。
$ bash plugins.sh lemon

# 複数のプラグインディレクトリ名(ここでは「lemon」、「lime」、「orange」)を指定して、所有者及びパーミッションを設定します。
$ bash plugins.sh lemon lime orange

注意

コマンドライン引数には、「../」を含む文字列を指定することができません。

$ bash plugins.sh ../../wp-admin
=> Error - Cannot contain '../' in commandline argments for security measures.

免責事項

本スクリプトファイルを使用した or 使用しなかったことにより生じたいかなるトラブル・損害において、作者は一切の責任を負いかねます。

ライセンス

MIT Licenseです。

#!/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
#!/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/themes内のディレクトリに設定するパーミッション
PERDIR=775
# wp-content/themes内のファイルに設定するパーミッション
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/themes/$i ]; then
echo -e "\033[1;32mInfo.\033[0;39m - Directory:'wp-content/themes/$i' is found."
# そのテーマのディレクトリ内の所有者とグループを設定します。
chown -R $OWNER:$GROUP $WPCDIR/themes/$i
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in the directory:'wp-content/themes/$i' to $OWNER:$GROUP."
# そのテーマのディレクトリ内のディレクトリのパーミッションを設定します。
find $WPCDIR/themes/$i/ -type d -exec chmod $PERDIR {} \;
echo -e "\033[1;32mInfo.\033[0;39m - Set the directories permissions in the directory:'wp-content/themes/$i' to $PERDIR."
# そのテーマのディレクトリ内のファイルのパーミッションを設定します。(但し、.htaccessと.htpasswdを除きます。)
find $WPCDIR/themes/$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/themes/$i' to $PERFILE."
# 指定されたテーマの翻訳ファイルがあるかどうかチェックします。
if [ -e $WPCDIR/languages/themes/$i-$LANG.mo ] || [ -e $WPCDIR/languages/themes/$i-$LANG.po ]; then
echo -e "\033[1;32mInfo.\033[0;39m - Directory of translation file:'$WPCDIR/languages/themes/$i-$LANG' is found."
# そのテーマの翻訳ファイルの所有者とグループを設定します。
chown $OWNER:$GROUP $WPCDIR/languages/themes/$i-$LANG.*
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in the directory:'wp-content/languages/themes/$i-$LANG' to $OWNER:$GROUP."
# そのテーマの翻訳ファイルのパーミッションを設定します。
chmod $PERFILE $WPCDIR/languages/themes/$i-$LANG.*
echo -e "\033[1;32mInfo.\033[0;39m - Set the files permissions in the directory:'wp-content/languages/themes/$i-$LANG' to $PERFILE."
fi
else
echo -e "\033[1;35mError\033[0;39m - Directory:'wp-content/themes/$i' is not found."
fi
done
# コマンドライン引数になにも指定していない場合、
else
# テーマディレクトリ内のすべてのファイルとディレクトリの所有者及びグループを設定します。
chown -R $OWNER:$GROUP $WPCDIR/themes
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in all of the theme directory to $OWNER:$GROUP."
# テーマの翻訳ファイルの所有者及びグループを設定します。
chown -R $OWNER:$GROUP $WPCDIR/languages/themes
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in all of the directory of theme translation file to $OWNER:$GROUP."
# テーマディレクトリ内のすべてのディレクトリのパーミッションを設定します。
find $WPCDIR/themes/ -type d -exec chmod $PERDIR {} \;
echo -e "\033[1;32mInfo.\033[0;39m - Set the directories permissions in all of the theme directory to $PERDIR."
# テーマディレクトリ内のすべてのファイルのパーミッションを設定します。(但し、.htaccessと.htpasswdを除きます。)
find $WPCDIR/themes/ -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/themes/$1' to $PERFILE."
# テーマの翻訳ファイルのパーミッションを設定します。
find $WPCDIR/languages/themes/ -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/themes/$1' to $PERFILE."
fi
#!/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/uploads内のディレクトリに設定するパーミッション
PERDIR=775
# wp-content/uploads内のファイルに設定するパーミッション
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/uploads/$i ]; then
echo -e "\033[1;32mInfo.\033[0;39m - Directory:'wp-content/uploads/$i' is found."
# そのアップロードディレクトリ内の所有者とグループを設定します。
chown -R $OWNER:$GROUP $WPCDIR/uploads/$i
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in the directory:'wp-content/uploads/$i' to $OWNER:$GROUP."
# そのアップロードディレクトリ内のディレクトリのパーミッションを設定します。
find $WPCDIR/uploads/$i/ -type d -exec chmod $PERDIR {} \;
echo -e "\033[1;32mInfo.\033[0;39m - Set the directories permissions in the directory:'wp-content/uploads/$i' to $PERDIR."
# そのアップロードディレクトリ内のファイルのパーミッションを設定します。(但し、.htaccessと.htpasswdを除きます。)
find $WPCDIR/uploads/$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/uploads/$i' to $PERFILE."
else
echo -e "\033[1;35mError\033[0;39m - Directory:'wp-content/uploads/$i' is not found."
fi
done
# コマンドライン引数になにも指定していない場合、
else
# アップロードディレクトリ内のすべてのファイルとディレクトリの所有者及びグループを設定します。
chown -R $OWNER:$GROUP $WPCDIR/uploads
echo -e "\033[1;32mInfo.\033[0;39m - Set the files and directories owner in all of the uploads directory to $OWNER:$GROUP."
# アップロードディレクトリ内のすべてのディレクトリのパーミッションを設定します。
find $WPCDIR/uploads/ -type d -exec chmod $PERDIR {} \;
echo -e "\033[1;32mInfo.\033[0;39m - Set the directories permissions in all of the uploads directory to $PERDIR."
# アップロードディレクトリ内のすべてのファイルのパーミッションを設定します。(但し、.htaccessと.htpasswdを除きます。)
find $WPCDIR/uploads/ -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/uploads/$1' to $PERFILE."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment