---
# Create file to easily push git changes and call SCM.

- name: General | Scripts | Root | scm.sh
  blockinfile:
    path: "{{ user_root.home }}/bin/scm.sh"
    block: |
      # 20210211 - Make life easier!
      push.sh
      time curl https://scm.hyperling.com | bash
    marker: '{mark}'
    marker_begin: "#!{{ bash_exec.stdout }}"
    marker_end: "exit 0"
    state: present
    create: yes

- name: General | Scripts | Root | scm.sh Permissions
  file: 
    path: "{{ user_root.home }}/bin/scm.sh"
    mode: '0755'


- name: General | Scripts | Root | push.sh
  blockinfile:
    path: "{{ user_root.home }}/bin/push.sh"
    block: |
      # 20210215 - Make life even easier!
      ssh ling@leet "cd Code/Ansible/ansible-pull; git push"
    marker: '{mark}'
    marker_begin: "#!{{ bash_exec.stdout }}"
    marker_end: "exit 0"
    state: present
    create: yes

- name: General | Scripts | Root | push.sh Permissions
  file: 
    path: "{{ user_root.home }}/bin/push.sh"
    mode: '0755'


- name: General | Scripts | Root | scm-dev.sh
  blockinfile:
    path: "{{ user_root.home }}/bin/scm-dev.sh"
    block: |
      # 20210713 - Make life easier for development!
      
      ## Variables ##

      # Use a specific branch if it was asked for.
      branch="dev"
      if [[ $1 != "" ]]; then
        branch="$1"
      fi


      ## Main ##

      push.sh
      time {{ ansible_pull_exec.stdout }} -U https://github.com/Hyperling/ansible.git --checkout $branch

    marker: '{mark}'
    marker_begin: "#!{{ bash_exec.stdout }}"
    marker_end: "exit 0"
    state: present
    create: yes

- name: General | Scripts | Root | scm-dev.sh Permissions
  file: 
    path: "{{ user_root.home }}/bin/scm-dev.sh"
    mode: '0755'