118 lines
3.8 KiB
YAML
118 lines
3.8 KiB
YAML
---
|
||
# The home-server project produces a multi-purpose setup using Ansible.
|
||
# Copyright © 2018–2023 Y. Gablin, under the GPL-3.0-or-later license.
|
||
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
||
|
||
# mandatory parameters: pkg_name, pre_cmd, aur_name, aur_home
|
||
|
||
- name: AUR → {{pkg_name}} → read current version
|
||
shell: |
|
||
pacman -Qi '{{pkg_name}}' | awk -F ': ' '/^Version/{print $2}'
|
||
register: pacmanQi
|
||
changed_when: false
|
||
|
||
- name: AUR → {{pkg_name}} → get metadata from AurJson
|
||
uri:
|
||
url: https://aur.archlinux.org/rpc/?v=5&type=info&arg={{pkg_name | mandatory}}
|
||
delegate_to: localhost
|
||
register: aurjson
|
||
changed_when: false
|
||
|
||
- name: AUR → {{pkg_name}} → get package recipe
|
||
get_url:
|
||
url: https://aur.archlinux.org{{aurjson.json.results[0].URLPath}}
|
||
dest: /tmp/
|
||
delegate_to: localhost
|
||
when:
|
||
- (aurjson.json.results[0].Version != (pacmanQi.stdout | default()))
|
||
register: aur_recipe
|
||
changed_when: false
|
||
|
||
- name: AUR → {{pkg_name}} → proceed with the install/upgrade
|
||
block:
|
||
|
||
- name: AUR → {{pkg_name}} → extract the recipe files
|
||
unarchive:
|
||
src: '{{aur_recipe.dest}}'
|
||
dest: /var/tmp/
|
||
changed_when: false
|
||
|
||
- name: AUR → {{pkg_name}} → work with the recipe
|
||
block:
|
||
|
||
- name: AUR → {{pkg_name}} → run custom pre-processing commands
|
||
shell: |
|
||
set -x
|
||
{{pre_cmd}}
|
||
args:
|
||
chdir: /var/tmp/{{aurjson.json.results[0].PackageBase}}
|
||
when: pre_cmd
|
||
environment:
|
||
HOME: "{{aur_home}}"
|
||
register: debugCustom
|
||
|
||
- name: AUR → {{pkg_name}} → see custom pre-processing commands’ result
|
||
debug:
|
||
var: debugCustom
|
||
when: pre_cmd
|
||
changed_when: false
|
||
|
||
- name: AUR → {{pkg_name}} → read the real version
|
||
command: >
|
||
bash -c
|
||
" makepkg -do >/dev/null 2>&1
|
||
; makepkg --printsrcinfo
|
||
| awk '$1==\"pkgver\"{v=$3};$1==\"pkgrel\"{r=$3};END{printf \"%s-%s\",v,r}'"
|
||
args:
|
||
chdir: /var/tmp/{{aurjson.json.results[0].PackageBase}}
|
||
register: realVersion
|
||
changed_when: false
|
||
ignore_errors: true
|
||
|
||
- name: AUR → {{pkg_name}} → proceed with building the package
|
||
block:
|
||
|
||
- name: AUR → {{pkg_name}} → install dependencies and build
|
||
command: |
|
||
makepkg --noconfirm --noprogressbar -Cmfs
|
||
args:
|
||
chdir: /var/tmp/{{aurjson.json.results[0].PackageBase}}
|
||
changed_when: false
|
||
|
||
- name: AUR → {{pkg_name}} → install package
|
||
shell: |
|
||
pacman --noconfirm --noprogressbar --needed -U *.pkg.tar.*
|
||
args:
|
||
chdir: /var/tmp/{{aurjson.json.results[0].PackageBase}}
|
||
become: false
|
||
register: pacman_output
|
||
changed_when:
|
||
- (pacman_output.stdout is defined)
|
||
- (pacman_output.stdout.find('there is nothing to do') == -1)
|
||
|
||
environment:
|
||
HOME: "{{aur_home}}"
|
||
when:
|
||
- (realVersion.stdout != (pacmanQi.stdout | default()))
|
||
|
||
always:
|
||
- name: AUR → {{pkg_name}} → clean the build directory
|
||
file:
|
||
path: /var/tmp/{{aurjson.json.results[0].PackageBase}}
|
||
state: absent
|
||
changed_when: false
|
||
|
||
become: true
|
||
become_user: "{{aur_name}}"
|
||
when:
|
||
- (aurjson.json.results[0].Version != (pacmanQi.stdout | default()))
|
||
|
||
always:
|
||
- name: AUR → {{pkg_name}} → clean package recipe
|
||
file:
|
||
path: '{{aur_recipe.dest}}'
|
||
state: absent
|
||
delegate_to: localhost
|
||
become: false
|
||
changed_when: false
|