summaryrefslogtreecommitdiffstats
path: root/roles/upload/tasks/main.yml
blob: ca87a1c9403490cba678e7cf17c3a8fe960bf79a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
- name: Set up packages as root
  block:
  - name: Add GPG
    apt:
      update_cache: yes
      name:
        - gnupg
        - sudo
      state: present
  - name: Import the NodeSource GPG key into apt
    apt_key:
      url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
      state: present
  - name: Add nodesource repository
    ansible.builtin.apt_repository:
      repo: deb https://deb.nodesource.com/node_20.x nodistro main
      update_cache: yes
  - name: Install packages
    apt:
      update_cache: yes
      name:
        - nodejs
      state: present
- name: Create upload user
  become: true
  user:
    name: "{{ upload_user }}"
    shell: /bin/bash
    state: present
- name: Ensure upload directory exists
  file:
    path: "{{ upload_dir }}"
    owner: "{{ upload_user }}"
    state: directory
- name: Install precompiled version  
  unarchive:
    src: https://github.com/psi-4ward/psitransfer/releases/download/v2.1.2/psitransfer-v2.1.2.tar.gz
    dest: "/home/{{ upload_user }}"
    remote_src: yes
- name: Create link
  file:
    src: "/home/{{ upload_user }}/psitransfer-v2.1.2"
    dest: "/home/{{ upload_user }}/psitransfer"
    state: link
- name: Upload production config
  become: true
  template:
    src: config.production.js
    dest: "/home/{{ upload_user }}/psitransfer/config.production.js"
- name: Copy the SSL key
  become: true
  copy:
    remote_src: yes
    src: "{{ upload_ssl_key }}"
    dest: "/home/{{ upload_user }}/privkey.pem"
- name: Copy the SSL cert
  become: true
  copy:
    remote_src: yes
    src: "{{ upload_ssl_cert }}"
    dest: "/home/{{ upload_user }}/fullchain.pem"
    owner: "{{ upload_user }}"
    group: "{{ upload_group }}"
- name: Install dependencies
  npm:
    path: "/home/{{ upload_user }}/psitransfer"
    production: yes
    ci: yes
- name: Add LibreJS tag start
  lineinfile:
    path: /home/{{ upload_user }}/psitransfer/public/app/{{ item.path }}
    line: // @license {{ item.license }}
    insertbefore: BOF
  loop:
    - path: common.js
      license: magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
    - path: upload.js
      license: magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
    - path: admin.js
      license: magnet:?xt=urn:btih:87f119ba0b429ba17a44b4bffcab33165ebdacc0&dn=freebsd.txt BSD-2-Clause
    - path: download.js
      license: magnet:?xt=urn:btih:87f119ba0b429ba17a44b4bffcab33165ebdacc0&dn=freebsd.txt BSD-2-Clause
- name: Add license tag end
  lineinfile:
    path: /home/{{ upload_user }}/psitransfer/public/app/{{ item.path }}
    line: // @license-end
  loop:
    - path: common.js
    - path: upload.js
    - path: admin.js
    - path: download.js
- name: Update head template
  template:
    src: head.pug
    dest: /home/{{ upload_user }}/psitransfer/public/pug/partials/head.pug
- name: Change ownership
  file:
    path: "/home/{{ upload_user }}"
    owner: "{{ upload_user }}"
    group: "{{ upload_group }}"
    recurse: true
- name: Install systemd configuration
  tags: system
  become: true
  template:
    src: upload.service
    dest: /etc/systemd/system/upload.service
    owner: root
    group: root
    mode: 0755
  when: not use_initd
- name: Restart Upload
  become: true
  when: upload_enabled
  service:
    name: upload
    state: restarted
    enabled: true
- name: Stop upload
  become: true
  when: not upload_enabled
  service:
    name: upload
    state: stopped
    enabled: false