home-server/roles/aur.inc/tasks/install.yml

99 lines
3.2 KiB
YAML

---
# The home-server project produces a multi-purpose setup using Ansible.
# Copyright © 2018 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 and aur_user
- 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}}
connection: local
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/
connection: local
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}} → 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.xz
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)
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_user}}"
when:
- (aurjson.json.results[0].Version != (pacmanQi.stdout | default()))
always:
- name: AUR → {{pkg_name}} → clean package recipe
file:
path: '{{aur_recipe.dest}}'
state: absent
connection: local
become: false
changed_when: false