From 59aaf63d4a061e72f71077513c7d08ae637c93ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sat, 12 Jun 2021 17:15:21 +0200 Subject: [PATCH] New way to install packages! Probably the fourth I ever created? Will this one last? I don't know! Doesn't have pip support for now, but probably something requirements.txt based will be a bit more proper --- .../roles/software/handlers/main.yml | 16 ++++ .../automatrop/roles/software/tasks/base.yml | 55 -------------- .../automatrop/roles/software/tasks/main.yml | 74 +++++++++++++------ .../roles/software/templates/PKGBUILD.j2 | 14 ++++ .../software/templates/package_manager.j2 | 26 +++++++ 5 files changed, 108 insertions(+), 77 deletions(-) create mode 100644 config/automatrop/roles/software/handlers/main.yml delete mode 100644 config/automatrop/roles/software/tasks/base.yml create mode 100644 config/automatrop/roles/software/templates/PKGBUILD.j2 create mode 100644 config/automatrop/roles/software/templates/package_manager.j2 diff --git a/config/automatrop/roles/software/handlers/main.yml b/config/automatrop/roles/software/handlers/main.yml new file mode 100644 index 0000000..77440be --- /dev/null +++ b/config/automatrop/roles/software/handlers/main.yml @@ -0,0 +1,16 @@ +- name: Create and install meta package for Arch Linux + block: + - name: Generate meta package PKGBUILD + template: + src: PKGBUILD.j2 + dest: "{{ ansible_user_dir }}/.cache/automatrop/PKGBUILD" + listen: "software changed" + + - name: Install meta package + aur: + name: "automatrop-packages-{{ inventory_hostname_short }}" + local_pkgbuild: "{{ ansible_user_dir }}/.cache/automatrop" + use: makepkg + state: latest + listen: "software changed" + when: arch_based diff --git a/config/automatrop/roles/software/tasks/base.yml b/config/automatrop/roles/software/tasks/base.yml deleted file mode 100644 index 2d72779..0000000 --- a/config/automatrop/roles/software/tasks/base.yml +++ /dev/null @@ -1,55 +0,0 @@ -- name: Install base shell packages (Pacman) - pacman: - name: - - base - - coreutils - - bash - - grep - - sed - - tar - - openssl # Used for machines script - when: arch - -- name: Install base shell packages (Apt) - apt: - name: - - coreutils - - bash - - grep - - sed - - tar - - openssl - when: apt - -- name: Install extended shell packages (Pacman) - pacman: - name: - - moreutils - - tmux - - bash-completion - - fzf - - highlight - - powerline-go-bin - when: arch - -- name: Install extended shell packages (Debian) - pacman: - name: - - moreutils - - tmux - - bash-completion - - fzf - - highlight - - powerline-go - when: debian - -- name: Install extended shell packages (Termux) - pacman: - name: - - moreutils - - tmux - - bash-completion - - fzf - # - highlight - # - powerline-go - when: termux diff --git a/config/automatrop/roles/software/tasks/main.yml b/config/automatrop/roles/software/tasks/main.yml index 51c2a62..aee4dfc 100644 --- a/config/automatrop/roles/software/tasks/main.yml +++ b/config/automatrop/roles/software/tasks/main.yml @@ -1,16 +1,24 @@ - name: Set variables set_fact: - arch: "{{ ansible_distribution == 'Archlinux' }}" + arch_based: "{{ ansible_distribution == 'Archlinux' }}" + arch: "{{ ansible_lsb.id == 'Arch' }}" + manjaro: "{{ ansible_lsb.id == 'Manjaro' or ansible_lsb.id == 'Manjaro-ARM' }}" termux: "{{ ansible_distribution == 'OtherLinux' and ansible_python.executable == '/data/data/com.termux/files/usr/bin/python' }}" - debian: "{{ ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' }}" + debian_based: "{{ ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' }}" + debian: "{{ ansible_distribution == 'Debian' }}" + ubuntu: "{{ ansible_distribution == 'Ubuntu' }}" + tags: softwarelist +# TODO Is this used? - name: Set secondary variables set_fact: - pacman: "{{ arch }}" + pacman: "{{ arch_based }}" apt: "{{ termux or debian }}" sudo: "{{ not termux }}" # TODO Install python if not done +# Or maybe not, it requires a lot of automation for something that can be done +# very quickly manually and is usually uneccessary - name: Install python-apt dependency for Termux block: @@ -67,30 +75,52 @@ # You should consider upgrading via the '/data/data/com.termux/files/usr/bin/python3 -m pip install --upgrade pip' command. # Install alternative package managers -- name: Install AUR package manager +- name: Install dependencies for AUR helpers + pacman: + name: + - fakeroot + - base-devel + when: arch_based + become: "{{ sudo }}" + +- name: Install AUR package manager (Arch) aur: name: yay-bin when: arch -- name: Install python pip (Pacman) +- name: Install AUR package manager (Manjaro) pacman: - name: python-pip - when: arch - become: "{{ sudo }}" - become_user: root + name: yay + when: manjaro +# Not sure if regular Manjaro has yay in its community packages, +# but Manjaro-ARM sure does -- name: Install python pip (Debian) - apt: - name: python3-pip - when: debian - become: "{{ sudo }}" - become_user: root +- name: Create cache folder + file: + state: directory + mode: "u=rwx,g=rx,o=rx" + path: "{{ ansible_user_dir }}/.cache/automatrop" -# Termux: pip is included with Python +- name: Generate list of packages for package manager + set_fact: + packages: "{{ query('template', 'package_manager.j2')[0].split('\n')[:-1]|sort }}" + tags: softwarelist + +- name: Install packages (Arch-based) + aur: + name: "{{ packages }}" + extra_args: "--asdeps" + # Nothing is set as installed manually so it can + # be removed by dependency check. + # Current packages will be kept by the meta package + use: yay + when: arch_based + tags: softwarelist + +- name: Check if list of packages changed + copy: + content: "{% for package in packages %}{{ package }}\n{% endfor %}" + dest: "{{ ansible_user_dir }}/.cache/automatrop/package_manager" + notify: "software changed" + tags: softwarelist -- name: Install base packages - include_tasks: - file: base.yml - apply: - become: "{{ sudo }}" - become_user: root diff --git a/config/automatrop/roles/software/templates/PKGBUILD.j2 b/config/automatrop/roles/software/templates/PKGBUILD.j2 new file mode 100644 index 0000000..8f424c6 --- /dev/null +++ b/config/automatrop/roles/software/templates/PKGBUILD.j2 @@ -0,0 +1,14 @@ +# Maintainer: Geoffrey Frogeye + +pkgname=automatrop-packages-{{ inventory_hostname_short }} +pkgver={{ ansible_date_time.iso8601_basic_short }} +pkgrel=1 +pkgdesc='Metapackage for packages wanted by Geoffrey via automatrop for {{ inventory_hostname }}' +url='https://git.frogeye.fr/geoffrey/dotfiles/src/branch/master/config/automatrop' +arch=('any') +license=('GPL') +depends=( +{% for package in packages %} + '{{ package }}' +{% endfor %} +) diff --git a/config/automatrop/roles/software/templates/package_manager.j2 b/config/automatrop/roles/software/templates/package_manager.j2 new file mode 100644 index 0000000..2648920 --- /dev/null +++ b/config/automatrop/roles/software/templates/package_manager.j2 @@ -0,0 +1,26 @@ +{# Base shell packages #} +coreutils +bash +grep +sed +tar +openssl +{% if debian_based %} +python3-pip +{% elsif termux %} +python +{% else %} +python-pip +{% endif %} +{# Extended shell packages #} +moreutils +tmux +bash-completion +fzf +highlight +{% if arch_based %} +powerline-go-bin +{% else %} +powerline-go +{% endif %} +zsh