--- /dev/null
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+- name: Download from Google Drive
+ get_url:
+ url: "https://www.googleapis.com/drive/v3/files/{{ item.uid }}?alt=media"
+ headers:
+ Authorization: "Bearer {{ access_token }}"
+ dest: "/tmp/{{ item.uid }}"
+- name: Decrypt
+ command: |
+ python3 -c
+ "
+ from cryptography.fernet import Fernet
+
+ encryption_key = Fernet('{{ key }}')
+ with open('/tmp/{{ item.uid }}', 'rb') as in_file:
+ token = encryption_key.decrypt(in_file.read())
+ with open('/tmp/{{ item.name }}.zip', 'wb+') as outfile:
+ outfile.write(token)
+ "
+- name: Unarchive if necessary
+ command: |
+ python3 -c
+ "
+ import shutil
+ import zipfile
+
+ name = '/tmp/{{ item.name }}'
+ archive = name + '.zip'
+ if zipfile.is_zipfile(archive):
+ shutil.unpack_archive(archive, extract_dir='/tmp', format='zip')
+ else:
+ shutil.move(archive, name)
+ "
+- name: Ensure destination exists
+ file:
+ path: "{{ item.dest }}"
+ state: directory
+ become: true
+- name: Move to destination
+ command: mv "/tmp/{{ item.name }}" "{{ item.dest }}/"
+ become: true
+- name: Stat destination
+ stat:
+ path: "{{ item.dest }}/{{ item.name }}"
+ register: dest_file
+- name: Recursively set permissions at destination
+ file:
+ path: "{{ item.dest }}/{{ item.name }}"
+ owner: "{{ item.owner }}"
+ group: "{{ item.group }}"
+ state: directory
+ recurse: yes
+ become: true
+ when: dest_file.stat.isdir
+- name: Set permissions at destination
+ file:
+ path: "{{ item.dest }}/{{ item.name }}"
+ owner: "{{ item.owner }}"
+ group: "{{ item.group }}"
+ become: true
+ when: not dest_file.stat.isdir