fix sudo bug

pull/26/head
ibuler 2015-12-20 00:30:31 +08:00
parent a73fa7811c
commit 08cbaa1622
2 changed files with 6 additions and 6 deletions

View File

@ -701,7 +701,7 @@ class Nav(object):
break
if not file_path:
print "文件路径为空"
color_print("文件路径为空")
continue
runner.run('fetch', module_args='src=%s dest=%s' % (file_path, tmp_dir), pattern=pattern)

View File

@ -5,15 +5,15 @@ real_file=/etc/sudoers
tmp_file=$(mktemp /tmp/XXXXXXX)
# Backup sudoers file
cp ${sudo_file} ${sudo_file_bak}
cp ${real_file} ${tmp_file}
# Add Command Aliases
add_cmd_alias() {
sudo_file=$1
{% for sudo_name, sudo_cmd in sudo_alias.items %}
{% if sudo_name != 'ALL' %}
if $(grep '^Cmnd_Alias {{ sudo_name }}' ${sudo_file} &> /dev/null); then
sed -i 's@^Cmnd_Alias.*{{ sudo_name }}.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
if $(grep '^Cmnd_Alias \<{{ sudo_name }}\>' ${sudo_file} &> /dev/null); then
sed -i 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file}
else
echo "Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}" >> ${sudo_file}
fi
@ -26,8 +26,8 @@ add_cmd_alias() {
add_role_chosen() {
sudo_file=$1
{% for user, alias in sudo_user.items %}
if $(grep '^{{ user }}.*' ${sudo_file} &> /dev/null); then
sed -i 's@^{{ user }}.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then
sed -i 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file}
else
echo "{{ user }} ALL = (root) NOPASSWD: {{ alias }}" >> ${sudo_file}
fi