]> git.immae.eu Git - perso/Immae/Config/Ansible.git/commitdiff
Add a temporary bashrc when updating pam_environment
authorIsmaël Bouya <ismael.bouya@fretlink.com>
Sat, 3 Nov 2018 23:37:08 +0000 (00:37 +0100)
committerIsmaël Bouya <ismael.bouya@fretlink.com>
Sat, 3 Nov 2018 23:37:08 +0000 (00:37 +0100)
roles/init/tasks/main.yml
roles/shell/bash/templates/bash_profile.j2
roles/shell/bash/templates/bashrc.j2

index d3f0f6b0bf4c8271fdfed1dae745f36f09a301f6..1baec91605a47ef51220a03863586bbe83323931 100644 (file)
@@ -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:
index 06210fabb3c99331003b3ea613e6a40a8ea3c32b..9b9e86c9df32bdbe80ab15988e9f14d241d146a2 100644 (file)
@@ -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 %}
index 2285d2b656562b5c5ee957d3d95564ed05a37656..99ed55f9919c2cb7dbcdc10069003df462e4e77e 100644 (file)
@@ -2,6 +2,8 @@
 # ~/.bashrc
 #
 
+[[ -f "$HOME/.bashrc_temp" ]] && . $HOME/.bashrc_temp
+
 if [ -n "$HOME/.local/bin" ]; then
   PATH="$HOME/.local/bin:$PATH"
 fi