diff --git a/bin/initDesktop b/bin/initDesktop index a0ab9a1..7082205 100755 --- a/bin/initDesktop +++ b/bin/initDesktop @@ -93,6 +93,17 @@ function do_salt_call(){ $salt state.apply pillar="{username: $USER}" } +function firefox_addons(){ + new_log "Installing firefox addons" + if [[ ! -f "$HOME/bin/install_firefox_addon" ]];then + printf "install firefox addon script not found, run dotfile sync first" + fi + if asktobreak;then + return + fi + exec $HOME/bin/install_firefox_addon +} + setup_dotfiles do_salt_call gnome_key_bindings diff --git a/salt/states/files/install_firefox_addon b/salt/states/files/install_firefox_addon index 84e157b..32c6673 100755 --- a/salt/states/files/install_firefox_addon +++ b/salt/states/files/install_firefox_addon @@ -2,15 +2,16 @@ set -aeo pipefail filename="$1" url="$2" -tmpfile=$(mktemp /tmp/install_firefox_addon.XXXXXX) +tmpfile=$(mktemp /tmp/install_firefox_addon.XXXXXX.xpi) -readarray -t profiles <<<"$(sed -n 's/^Path=\(.*\)$/\1/p' $HOME/.mozilla/firefox/profiles.ini)" +{% for name, args in pillar['firefox']['addons'].items() %} +if [[ $(grep -oP '(?<=\},\"name\":\"){{ name }}' {{ salt['user.info']( pillar['username'] ).home }}/.mozilla/firefox/*.default*/addons.json) ]]; then + printf "{{ name }} is already installed\n" +else + printf "installing {{ name }}\n" + curl -sLo "$tmpfile" "$url" + firefox "$tmpfile" +fi +{% endfor %} - - -curl -sLo "$tmpfile" "$url" -for p in $(sed -n 's/^Path=\(.*\)$/\1/p' $HOME/.mozilla/firefox/profiles.ini);do - echo "Installing in profile $p" - cp "$tmpfile" "$HOME/.mozilla/firefox/$p/extensions/$filename" -done rm "$tmpfile" diff --git a/salt/states/firefox.sls b/salt/states/firefox.sls index 5b0e169..4167c0b 100644 --- a/salt/states/firefox.sls +++ b/salt/states/firefox.sls @@ -2,14 +2,7 @@ copy the install addon script: file.managed: - name: {{ salt['user.info']( pillar['username'] ).home }}/bin/install_firefox_addon - source: salt://files/install_firefox_addon + - template: jinja - user: {{ pillar['username'] }} - group: users - mode: "0755" - -{% for name, args in pillar['firefox']['addons'].items() %} -Downloading {{ name }} Firefox xpi: - cmd.run: - - name: {{ salt['user.info']( pillar['username'] ).home }}/bin/install_firefox_addon {{ args['name'] }} {{ args['url'] }} - - unless: grep -oP '(?<=\},\"name\":\"){{ name }}' {{ salt['user.info']( pillar['username'] ).home }}/.mozilla/firefox/*.default*/addons.json - - runas: {{ pillar['username'] }} -{% endfor %}