From 3b5daf19c3aa52fd81bab2e97619411ae370c2bc Mon Sep 17 00:00:00 2001 From: yumaojun <719118794@qq.com> Date: Tue, 23 Feb 2016 15:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=91.=20=E4=BF=AE=E5=A4=8Dfreebsd=20?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=B8=A6sudo=E8=A7=84=E5=88=99=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=97=B6=20,=20sudo=E3=80=80=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=BC=95=E5=8F=91=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/jperm/role_sudo.j2 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/jperm/role_sudo.j2 b/templates/jperm/role_sudo.j2 index c48d354c1..46f96342f 100644 --- a/templates/jperm/role_sudo.j2 +++ b/templates/jperm/role_sudo.j2 @@ -4,6 +4,13 @@ real_file=/etc/sudoers tmp_file=$(mktemp /tmp/XXXXXXX) +# fixed sudoers file path in bsd +isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no") +if [ $isbsd == "yes" ]; then + real_file=/usr/local/etc/sudoers +fi + + # Backup sudoers file cp ${real_file} ${tmp_file} @@ -13,7 +20,6 @@ add_cmd_alias() { {% for sudo_name, sudo_cmd in sudo_alias.items %} {% if sudo_name != 'ALL' %} if $(grep '^Cmnd_Alias \<{{ sudo_name }}\>' ${sudo_file} &> /dev/null); then - isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no") if [ $isbsd == "yes" ]; then sed -i .bk 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file} else @@ -32,7 +38,6 @@ add_role_chosen() { sudo_file=$1 {% for user, alias in sudo_user.items %} if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then - isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no") if [ $isbsd == "yes" ]; then sed -i .bk 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file} else