---
- hosts: [ 'debian10' ]
  tasks:
    - name: Install direnv
      become_user: root
      shell: |
        command -v direnv > /dev/null || {
          curl -sfLo /usr/local/bin/direnv https://github.com/direnv/direnv/releases/download/v2.35.0/direnv.linux-amd64 && \
          chmod a+x /usr/local/bin/direnv
        }

    - name: Install Starship
      become_user: root
      shell: |
        command -v starship> /dev/null || {
          curl -sS https://starship.rs/install.sh | sh -s -- -f
        }

    - name: Install with init or update yadm
      become_user: root
      shell: |
        command -v yadm && {
          yadm remote set-url origin https://vcs.wpstudio.ru/gitea/dotfiles.git
          rm -rf .tmux/plugins/tmux-ip-address
          yadm pull && yadm checkout .
        } || {
          curl -sfLo /usr/local/bin/yadm https://github.com/TheLocehiliosan/yadm/raw/master/yadm && chmod a+x /usr/local/bin/yadm
          yadm clone --bootstrap https://vcs.wpstudio.ru/gitea/dotfiles.git && yadm checkout .
        }

      # For manual change: sed -i 's/#/\\$/g' ${HOME}/.config/starship.toml
    - name: 'Change character for non-root user'
      become_user: root
      shell: |
        HOME_USER=$(ls /home)
        test ! -z "${HOME_USER}" && su --login ${HOME_USER} -c 'yadm clone --bootstrap https://vcs.wpstudio.ru/gitea/dotfiles.git && yadm checkout .'
        test ! -z "${HOME_USER}" && su --login ${HOME_USER} -c 'sed -i "s/#/\\$/g" ${HOME}/.config/starship.toml'
        exit 0
      args:
        executable: /bin/bash