changed internal helper to makepgk

AUR packages can be build via the makepkg script and via AUR helpers.
AUR helpers further automate certain tasks for the AUR. makepkg is no helper.
Therefore, internal helper should be renamed to just makepkg.
pull/3/head
Christian Kotte 2018-05-16 21:06:06 +02:00
parent c402e57518
commit 47769a5195
2 changed files with 19 additions and 14 deletions

View File

@ -1,25 +1,29 @@
# Ansible AUR helper # Ansible AUR helper
Ansible module to use some Arch User Repository (AUR) helpers as well as a simple internal implementation as a fallback. The following helpers are supported and automatically selected in the order they are listed: 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:
- [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)
- [yaourt](https://github.com/archlinuxfr/yaourt) - [yaourt](https://github.com/archlinuxfr/yaourt)
- [yay](https://github.com/Jguer/yay) - [yay](https://github.com/Jguer/yay)
- internal helper
makepkg will be used if no helper was found or if it's specified explicitly.
- [makepkg](https://wiki.archlinux.org/index.php/makepkg)
## Options ## Options
|parameter |required |default |choices |comments| |parameter |required |default |choices |comments|
|--- |--- |--- |--- |---| |--- |--- |--- |--- |---|
|name |no | | |Name or list of names of the package(s) to install or upgrade.| |name |no | | |Name or list of names of the package(s) to install or upgrade.|
|upgrade |no |no |yes, no |Whether or not to upgrade whole system.| |upgrade |no |no |yes, no |Whether or not to upgrade whole system.|
|use |no |auto |auto, aurman, pacaur, trizen, pikaur, yaourt, yay, internal |The helper to use, 'auto' uses the first known helper found, 'internal' uses the internal helper.| |use |no |auto |auto, aurman, pacaur, trizen, pikaur, yaourt, yay, makepkg |The helper to use, 'auto' uses the first known helper found and makepkg as a fallback.|
|skip_installed |no |no |yes, no |Skip operations if the package is present.| |skip_installed |no |no |yes, no |Skip operations if the package is present.|
### Note ### Note
* Either *name* or *upgrade* is required, both cannot be used together. * Either *name* or *upgrade* is required, both cannot be used together.
* *skip_installed* cannot be used with *upgrade*. * *skip_installed* cannot be used with *upgrade*.
* In the *use*=*auto* mode, the internal helper is used as a fallback if no known helper is found. * In the *use*=*auto* mode, makepkg is used as a fallback if no known helper is found.
## Installing ## Installing
1. Clone the *ansibe-aur* repository in your playbook custom-module directory: 1. Clone the *ansibe-aur* repository in your playbook custom-module directory:
@ -42,8 +46,8 @@ ln --symbolic ansible-aur/aur.py aur
### Examples ### Examples
Use it in a task, as in the following examples: Use it in a task, as in the following examples:
``` ```
# Install trizen using the internal helper, skip if trizen is already installed # Install trizen using makepkg, skip if trizen is already installed
- aur: name=trizen use=internal skip_installed=true - aur: name=trizen use=makepkg skip_installed=true
become: yes become: yes
become_user: aur_builder become_user: aur_builder

17
aur.py
View File

@ -19,7 +19,7 @@ use_cmd = {
'pikaur': ['pikaur', '-S', '--noconfirm', '--noedit', '--needed'], 'pikaur': ['pikaur', '-S', '--noconfirm', '--noedit', '--needed'],
'yaourt': ['yaourt', '-S', '--noconfirm', '--needed'], 'yaourt': ['yaourt', '-S', '--noconfirm', '--needed'],
'yay': ['yay', '-S', '--noconfirm'], 'yay': ['yay', '-S', '--noconfirm'],
'internal': ['makepkg', '--syncdeps', '--install', '--noconfirm', '--needed'] 'makepkg': ['makepkg', '--syncdeps', '--install', '--noconfirm', '--needed']
} }
# optional: aurman, pacaur, trizen have a --aur option, do things only for aur # optional: aurman, pacaur, trizen have a --aur option, do things only for aur
@ -29,7 +29,6 @@ def package_installed(module, package):
return rc == 0 return rc == 0
def install_internal(module, package):
def check_packages(module, packages): def check_packages(module, packages):
""" """
Inform the user what would change if the module were run Inform the user what would change if the module were run
@ -55,6 +54,8 @@ def check_packages(module, packages):
message = 'package is already installed' message = 'package is already installed'
module.exit_json(changed=status, msg=message) module.exit_json(changed=status, msg=message)
def install_with_makepkg(module, package):
f = urllib.request.urlopen('https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'.format(package)) f = urllib.request.urlopen('https://aur.archlinux.org/rpc/?v=5&type=info&arg={}'.format(package))
result = json.loads(f.read().decode('utf8')) result = json.loads(f.read().decode('utf8'))
if result['resultcount'] != 1: if result['resultcount'] != 1:
@ -71,7 +72,7 @@ def check_packages(module, packages):
tar.extractall() tar.extractall()
tar.close() tar.close()
os.chdir(format(result['Name'])) os.chdir(format(result['Name']))
rc, out, err = module.run_command(use_cmd['internal'], check_rc=True) rc, out, err = module.run_command(use_cmd['makepkg'], check_rc=True)
os.chdir(current_path) os.chdir(current_path)
return (rc, out, err) return (rc, out, err)
@ -98,8 +99,8 @@ def install_packages(module, packages, use, skip_installed):
if package_installed(module, package): if package_installed(module, package):
rc = 0 rc = 0
continue continue
if use == 'internal': if use == 'makepkg':
rc, out, err = install_internal(module, package) rc, out, err = install_with_makepkg(module, package)
else: else:
rc, out, err = module.run_command(def_lang + use_cmd[use] + [package], check_rc=True) rc, out, err = module.run_command(def_lang + use_cmd[use] + [package], check_rc=True)
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)
@ -124,7 +125,7 @@ def main():
}, },
'use': { 'use': {
'default': 'auto', 'default': 'auto',
'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'internal'], 'choices': ['auto', 'aurman', 'pacaur', 'trizen', 'pikaur', 'yaourt', 'yay', 'makepkg'],
}, },
'skip_installed': { 'skip_installed': {
'default': False, 'default': False,
@ -141,7 +142,7 @@ def main():
check_packages(module, params['name']) check_packages(module, params['name'])
if params['use'] == 'auto': if params['use'] == 'auto':
use = 'internal' 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, False):
@ -150,7 +151,7 @@ def main():
else: else:
use = params['use'] use = params['use']
if params['upgrade'] and (params['name'] or params['skip_installed'] or use == 'internal'): if params['upgrade'] and (params['name'] or params['skip_installed'] or use == 'makepkg'):
module.fail_json(msg="Upgrade cannot be used with this option.") module.fail_json(msg="Upgrade cannot be used with this option.")
else: else:
if params['upgrade']: if params['upgrade']: