1. 修复freebsd 推送带sudo规则的用户时 , sudo 路径引发的问题。

pull/71/head^2
yumaojun 2016-02-23 15:21:27 +08:00
parent 4645029a27
commit 3b5daf19c3
1 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,13 @@
real_file=/etc/sudoers real_file=/etc/sudoers
tmp_file=$(mktemp /tmp/XXXXXXX) 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 # Backup sudoers file
cp ${real_file} ${tmp_file} cp ${real_file} ${tmp_file}
@ -13,7 +20,6 @@ add_cmd_alias() {
{% for sudo_name, sudo_cmd in sudo_alias.items %} {% for sudo_name, sudo_cmd in sudo_alias.items %}
{% if sudo_name != 'ALL' %} {% if sudo_name != 'ALL' %}
if $(grep '^Cmnd_Alias \<{{ sudo_name }}\>' ${sudo_file} &> /dev/null); then 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 if [ $isbsd == "yes" ]; then
sed -i .bk 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file} sed -i .bk 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
else else
@ -32,7 +38,6 @@ add_role_chosen() {
sudo_file=$1 sudo_file=$1
{% for user, alias in sudo_user.items %} {% for user, alias in sudo_user.items %}
if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then
isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no")
if [ $isbsd == "yes" ]; then if [ $isbsd == "yes" ]; then
sed -i .bk 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file} sed -i .bk 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
else else