From c235f9bea368316f1c1a441ebf6877e05e7df21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 4 Nov 2018 00:37:08 +0100 Subject: Add a temporary bashrc when updating pam_environment --- roles/init/tasks/main.yml | 18 ++++++++++++++++++ roles/shell/bash/templates/bash_profile.j2 | 1 + roles/shell/bash/templates/bashrc.j2 | 2 ++ 3 files changed, 21 insertions(+) diff --git a/roles/init/tasks/main.yml b/roles/init/tasks/main.yml index d3f0f6b..1baec91 100644 --- a/roles/init/tasks/main.yml +++ b/roles/init/tasks/main.yml @@ -7,6 +7,24 @@ template: src: pam_environment.j2 dest: $XDG_CONFIG_HOME/pam_environment +- name: Remove old lines in bashrc_temp + lineinfile: + line: "{{ ('unset ' ~ item | regex_replace('=.*')) if item != '' and item.0 != '#' else '' }}" + dest: $HOME/.bashrc_temp + insertafter: EOF + create: true + state: present + loop: "{{ pam_environment.diff.0.before.split('\n')|difference(pam_environment.diff.0.after.split('\n')) | regex_replace('[\\\\t]*DEFAULT') }}" + when: pam_environment.changed +- name: Add new lines in bashrc_temp + lineinfile: + line: "{{ ('export ' ~ item) if item != '' and item.0 != '#' else '' }}" + dest: $HOME/.bashrc_temp + insertafter: EOF + create: true + state: present + loop: "{{ pam_environment.diff.0.after.split('\n')|difference(pam_environment.diff.0.before.split('\n')) | regex_replace('[\\\\t]*DEFAULT', '') }}" + when: pam_environment.changed - name: Signal the change when: pam_environment.changed debug: diff --git a/roles/shell/bash/templates/bash_profile.j2 b/roles/shell/bash/templates/bash_profile.j2 index 06210fa..9b9e86c 100644 --- a/roles/shell/bash/templates/bash_profile.j2 +++ b/roles/shell/bash/templates/bash_profile.j2 @@ -4,6 +4,7 @@ {% if "graphical_vt" in features.get(profile, []) %} if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then + [[ -f "$HOME/.bashrc_temp" ]] && rm -f $HOME/.bashrc_temp exec startx $XDG_CONFIG_HOME/xinitrc > $XDG_STATE_HOME/xsession_errors 2>&1 fi {% endif %} diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2 index 2285d2b..99ed55f 100644 --- a/roles/shell/bash/templates/bashrc.j2 +++ b/roles/shell/bash/templates/bashrc.j2 @@ -2,6 +2,8 @@ # ~/.bashrc # +[[ -f "$HOME/.bashrc_temp" ]] && . $HOME/.bashrc_temp + if [ -n "$HOME/.local/bin" ]; then PATH="$HOME/.local/bin:$PATH" fi -- cgit v1.2.3