mirror of
https://github.com/kewlfft/ansible-aur.git
synced 2025-09-17 08:30:39 +03:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9f52f507c6 | ||
![]() |
e1443632a3 | ||
![]() |
f4868a5bac | ||
![]() |
9a2500338c | ||
![]() |
5acabdc819 | ||
![]() |
2766c2661c | ||
![]() |
473d06fe54 | ||
![]() |
59d69056a2 | ||
![]() |
8b1ba99cdc | ||
![]() |
72d432ac7a | ||
![]() |
b462d9893f | ||
![]() |
8f8af5fa5f | ||
![]() |
6ee60c77bb |
14
README.md
14
README.md
@@ -1,14 +1,14 @@
|
|||||||
# Ansible AUR helper
|
# Ansible AUR helper
|
||||||
Ansible module to use some Arch User Repository (AUR) helpers as well as makepkg.
|
Ansible module to use some Arch User Repository (AUR) helpers as well as makepkg.
|
||||||
|
|
||||||
The following helpers are supported and automatically selected in the order they are listed:
|
The following helpers are supported and automatically selected, if present, in the order listed below:
|
||||||
- [yay](https://github.com/Jguer/yay)
|
- [yay](https://github.com/Jguer/yay)
|
||||||
- [aurman](https://github.com/polygamma/aurman)
|
- [aurman](https://github.com/polygamma/aurman)
|
||||||
- [pacaur](https://github.com/rmarquis/pacaur)
|
- [pacaur](https://github.com/rmarquis/pacaur)
|
||||||
- [trizen](https://github.com/trizen/trizen)
|
- [trizen](https://github.com/trizen/trizen)
|
||||||
- [pikaur](https://github.com/actionless/pikaur)
|
- [pikaur](https://github.com/actionless/pikaur)
|
||||||
|
|
||||||
*makepkg* will be used if no helper was found or if it is explicitly specified.
|
*makepkg* will be used if no helper was found or if it is explicitly specified:
|
||||||
- [makepkg](https://wiki.archlinux.org/index.php/makepkg)
|
- [makepkg](https://wiki.archlinux.org/index.php/makepkg)
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
@@ -28,7 +28,7 @@ The following helpers are supported and automatically selected in the order they
|
|||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
### AUR package
|
### AUR package
|
||||||
The [aur-ansible-git](https://aur.archlinux.org/packages/ansible-aur-git) package is available in the AUR.
|
The [ansible-aur-git](https://aur.archlinux.org/packages/ansible-aur-git) package is available in the AUR.
|
||||||
Note the module is installed in `/usr/share/ansible/plugins/modules` which is one of the default module library paths.
|
Note the module is installed in `/usr/share/ansible/plugins/modules` which is one of the default module library paths.
|
||||||
|
|
||||||
### Manual installation
|
### Manual installation
|
||||||
@@ -38,9 +38,9 @@ git clone https://github.com/kewlfft/ansible-aur.git ~/.ansible/plugins/modules/
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
### Note
|
### Notes
|
||||||
* This module aims to cover the AUR; for package removal or system upgrade with the repositories, it is recommended to use the official *pacman* module,
|
* This module aims to cover the AUR; for package removal or system upgrade with the repositories, it is recommended to use the official *pacman* module.
|
||||||
* A package is reinstalled only if an update is available, using the *--needed* parameter.
|
* The *--needed* parameter of the helper is systematically used, it means if a package is up to date, it is not built and reinstalled.
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
Use it in a task, as in the following examples:
|
Use it in a task, as in the following examples:
|
||||||
@@ -68,7 +68,7 @@ Use it in a task, as in the following examples:
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Create the "aur_builder" user
|
### Create the "aur_builder" user
|
||||||
While Ansible expects to SSH as root, AUR helpers do not allow executing operations as root, they all fail with "you cannot perform this operation as root". It is therefore recommended to create a user, that we will call for example *aur_builder*, that has no need for password with pacman in sudoers.
|
While Ansible expects to SSH as root, AUR helpers do not allow executing operations as root, they all fail with "you cannot perform this operation as root". It is therefore recommended to create a user, let's call it *aur_builder*, that has no need for password with pacman in sudoers.
|
||||||
This can be done in Ansible with the following actions:
|
This can be done in Ansible with the following actions:
|
||||||
```
|
```
|
||||||
- user:
|
- user:
|
||||||
|
22
aur.py
22
aur.py
@@ -9,6 +9,7 @@ import tarfile
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
@@ -76,7 +77,7 @@ EXAMPLES = '''
|
|||||||
def_lang = ['env', 'LC_ALL=C']
|
def_lang = ['env', 'LC_ALL=C']
|
||||||
|
|
||||||
use_cmd = {
|
use_cmd = {
|
||||||
'yay': ['yay', '-S', '--noconfirm', '--needed'],
|
'yay': ['yay', '-S', '--noconfirm', '--needed', '--cleanafter'],
|
||||||
'aurman': ['aurman', '-S', '--noconfirm', '--noedit', '--needed', '--skip_news', '--pgp_fetch', '--skip_new_locations'],
|
'aurman': ['aurman', '-S', '--noconfirm', '--noedit', '--needed', '--skip_news', '--pgp_fetch', '--skip_new_locations'],
|
||||||
'pacaur': ['pacaur', '-S', '--noconfirm', '--noedit', '--needed'],
|
'pacaur': ['pacaur', '-S', '--noconfirm', '--noedit', '--needed'],
|
||||||
'trizen': ['trizen', '-S', '--noconfirm', '--noedit', '--needed'],
|
'trizen': ['trizen', '-S', '--noconfirm', '--noedit', '--needed'],
|
||||||
@@ -108,13 +109,13 @@ def check_packages(module, packages):
|
|||||||
|
|
||||||
if would_be_changed:
|
if would_be_changed:
|
||||||
status = True
|
status = True
|
||||||
if (len(packages) > 1):
|
if len(packages) > 1:
|
||||||
message = '%s package(s) would be installed' % str(len(would_be_changed))
|
message = '{} package(s) would be installed'.format(len(would_be_changed))
|
||||||
else:
|
else:
|
||||||
message = 'package would be installed'
|
message = 'package would be installed'
|
||||||
else:
|
else:
|
||||||
status = False
|
status = False
|
||||||
if (len(packages) > 1):
|
if len(packages) > 1:
|
||||||
message = 'all packages are already installed'
|
message = 'all packages are already installed'
|
||||||
else:
|
else:
|
||||||
message = 'package is already installed'
|
message = 'package is already installed'
|
||||||
@@ -126,10 +127,10 @@ def install_with_makepkg(module, package):
|
|||||||
Install the specified package with makepkg
|
Install the specified package with makepkg
|
||||||
"""
|
"""
|
||||||
module.get_bin_path('fakeroot', required=True)
|
module.get_bin_path('fakeroot', required=True)
|
||||||
f = open_url('https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'.format(package))
|
f = open_url('https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'.format(urllib.parse.quote(package)))
|
||||||
result = json.loads(f.read().decode('utf8'))
|
result = json.loads(f.read().decode('utf8'))
|
||||||
if result['resultcount'] != 1:
|
if result['resultcount'] != 1:
|
||||||
return (1, '', 'package not found')
|
return (1, '', 'package {} not found'.format(package))
|
||||||
result = result['results'][0]
|
result = result['results'][0]
|
||||||
f = open_url('https://aur.archlinux.org/{}'.format(result['URLPath']))
|
f = open_url('https://aur.archlinux.org/{}'.format(result['URLPath']))
|
||||||
current_path = os.getcwd()
|
current_path = os.getcwd()
|
||||||
@@ -184,10 +185,7 @@ def install_packages(module, packages, use, skip_installed, aur_only):
|
|||||||
|
|
||||||
changed_iter = changed_iter or not (out == '' or '-- skipping' in out or 'nothing to do' in out)
|
changed_iter = changed_iter or not (out == '' or '-- skipping' in out or 'nothing to do' in out)
|
||||||
|
|
||||||
if changed_iter:
|
message = 'installed package(s)' if changed_iter else 'package(s) already installed'
|
||||||
message = 'installed package(s)'
|
|
||||||
else:
|
|
||||||
message = 'package(s) already installed'
|
|
||||||
|
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
changed=changed_iter,
|
changed=changed_iter,
|
||||||
@@ -209,7 +207,7 @@ def main():
|
|||||||
},
|
},
|
||||||
'use': {
|
'use': {
|
||||||
'default': 'auto',
|
'default': 'auto',
|
||||||
'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'makepkg'],
|
'choices': ['auto'] + list(use_cmd.keys()),
|
||||||
},
|
},
|
||||||
'skip_installed': {
|
'skip_installed': {
|
||||||
'default': False,
|
'default': False,
|
||||||
@@ -237,7 +235,7 @@ def main():
|
|||||||
use = 'makepkg'
|
use = 'makepkg'
|
||||||
# auto: select the first helper for which the bin is found
|
# auto: select the first helper for which the bin is found
|
||||||
for k in use_cmd:
|
for k in use_cmd:
|
||||||
if module.get_bin_path(k, False):
|
if module.get_bin_path(k):
|
||||||
use = k
|
use = k
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user