Skip to content

Instantly share code, notes, and snippets.

@yuuan
Created December 2, 2015 05:40
Show Gist options
  • Select an option

  • Save yuuan/4d5477ee8f1f084f39fb to your computer and use it in GitHub Desktop.

Select an option

Save yuuan/4d5477ee8f1f084f39fb to your computer and use it in GitHub Desktop.
SELinux が有効な環境で、指定したディレクトリに対して HTTPD が書き込みできるようにするスクリプト。
#!/bin/zsh -eu
function writable {
TARGET=$*
echo -e "\e[37m'$TARGET'\e[m のパーミッションを変更します。"
/usr/bin/sudo /usr/bin/chmod -R a+w "$TARGET"
echo -e "\e[37m'$TARGET'\e[m に \e[32m'httpd_sys_rw_content_t'\e[m を付与します。"
/usr/bin/sudo /usr/sbin/semanage fcontext -a -t httpd_sys_rw_content_t "$TARGET(/.*)?"
/usr/bin/sudo /usr/sbin/restorecon -RFv "$TARGET"
echo
}
function info {
TARGET=$*
/usr/bin/ls -dlFZ "$TARGET"
}
function warn {
echo -e "$*" 1>&2
}
function die {
warn "$*"; exit 255
}
[[ $# -ne 1 ]] && die "対象のディレクトリをひとつ指定してください。"
TARGET=`/usr/bin/readlink -f $1`
[[ ! -d "$TARGET" ]] && die "\e[31mディレクトリ '$TARGET'\e[31m が見付かりません。\e[m"
writable $TARGET
info $TARGET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment