From 8030f44df32501cf65d711ec889907e3e33e182d Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Mon, 12 Sep 2022 20:51:02 +0200 Subject: [PATCH] Add wrapper for prusa-slicer for syncing configs --- .../files/usr/local/bin/prusa-slicer.wrapper | 19 ++++++++++++++ roles/prusa-slicer/tasks/checkout-git.yml | 6 ----- .../prusa-slicer/tasks/config-repository.yml | 26 +++++++++++++++++++ roles/prusa-slicer/tasks/install-program.yml | 17 ++++++++++-- roles/prusa-slicer/tasks/main.yml | 2 +- 5 files changed, 61 insertions(+), 9 deletions(-) create mode 100755 roles/prusa-slicer/files/usr/local/bin/prusa-slicer.wrapper delete mode 100644 roles/prusa-slicer/tasks/checkout-git.yml create mode 100644 roles/prusa-slicer/tasks/config-repository.yml diff --git a/roles/prusa-slicer/files/usr/local/bin/prusa-slicer.wrapper b/roles/prusa-slicer/files/usr/local/bin/prusa-slicer.wrapper new file mode 100755 index 0000000..21daada --- /dev/null +++ b/roles/prusa-slicer/files/usr/local/bin/prusa-slicer.wrapper @@ -0,0 +1,19 @@ +#!/usr/bin/env sh + +CONFIG_PATH="${HOME}/.config/PrusaSlicer" +CURRENT_DIR=$(pwd) +BIN_PATH=/usr/local/bin + +cd "$CONFIG_PATH" && \ +git pull + + +cd "${CURRENT_DIR}" +"${BIN_PATH}/prusa-slicer.real" + +cd "${CONFIG_PATH}" && \ +git add . && \ +git commit -m "$(date +%Y.%m.%d\ %H:%M)" && \ +git push + +cd "${CURRENT_DIR}" diff --git a/roles/prusa-slicer/tasks/checkout-git.yml b/roles/prusa-slicer/tasks/checkout-git.yml deleted file mode 100644 index 1a6caa8..0000000 --- a/roles/prusa-slicer/tasks/checkout-git.yml +++ /dev/null @@ -1,6 +0,0 @@ -- name: checkout prusa profiles repo - git: - repo: "{{ prusa_slicer.repo }}" - dest: "{{ ansible_user_dir }}/.config/PrusaSlicer" - clone: yes - update: yes diff --git a/roles/prusa-slicer/tasks/config-repository.yml b/roles/prusa-slicer/tasks/config-repository.yml new file mode 100644 index 0000000..57207f4 --- /dev/null +++ b/roles/prusa-slicer/tasks/config-repository.yml @@ -0,0 +1,26 @@ +- name: checkout prusa profiles repo + git: + repo: "{{ prusa_slicer.repo }}" + dest: "{{ ansible_user_dir }}/.config/PrusaSlicer" + clone: yes + update: yes + +- name: Install wrapper + become: yes + copy: + src: usr/local/bin/prusa-slicer.wrapper + dest: /usr/local/bin/prusa-slicer.wrapper + mode: '0755' + +- name: clean link + become: yes + file: + path: "/usr/local/bin/prusa-slicer" + state: absent + +- name: Create symbolic link to wrapper + become: yes + file: + src: "/usr/local/bin/prusa-slicer.wrapper" + dest: "/usr/local/bin/prusa-slicer" + state: link diff --git a/roles/prusa-slicer/tasks/install-program.yml b/roles/prusa-slicer/tasks/install-program.yml index 37784af..d143b3f 100644 --- a/roles/prusa-slicer/tasks/install-program.yml +++ b/roles/prusa-slicer/tasks/install-program.yml @@ -21,7 +21,7 @@ when: ansible_architecture == "x86_64" get_url: url: "{{ (git_info.json | json_query('assets[*].browser_download_url') | select('match', '.*x64-GTK3.*AppImage'))[0] }}" - dest: /usr/local/bin/prusa-slicer + dest: /usr/local/bin/prusa-slicer.real mode: 0755 - name: "Download URL" @@ -34,5 +34,18 @@ become: yes get_url: url: "{{ (git_info.json | json_query('assets[*].browser_download_url') | select('match', '.*armv7l-GTK2.*AppImage'))[0] }}" - dest: /usr/local/bin/prusa-slicer + dest: /usr/local/bin/prusa-slicer.real mode: 0755 + +- name: Clean symbolic link + become: yes + file: + path: "/usr/local/bin/prusa-slicer" + state: absent + +- name: Create symbolic link to real app + become: yes + file: + src: "/usr/local/bin/prusa-slicer.real" + dest: "/usr/local/bin/prusa-slicer" + state: link diff --git a/roles/prusa-slicer/tasks/main.yml b/roles/prusa-slicer/tasks/main.yml index f47ffca..f35ca25 100644 --- a/roles/prusa-slicer/tasks/main.yml +++ b/roles/prusa-slicer/tasks/main.yml @@ -1,3 +1,3 @@ - include: install-program.yml -- include: checkout-git.yml +- include: config-repository.yml