From 3f72ffb85f9a7ba0474dbf5c827ff3f0b1b1ae41 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 16 Apr 2019 15:55:53 +0200 Subject: bin/pkgs: Adding option to initially create a new package upon adding it (-n flag). This automatically retrieves name and email from git config --global for maintainer info. --- bin/pkgs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/bin/pkgs b/bin/pkgs index a64f969..1e0eb0d 100755 --- a/bin/pkgs +++ b/bin/pkgs @@ -6,6 +6,7 @@ package_dir_base="$HOME/packages/" repo="" package="" mode="" +new_package=0 declare -A upstreams=( ["aur"]="aur@aur.archlinux.org" @@ -42,6 +43,31 @@ add_package() { rm "$tmp_file" } +create_package() { + local name="$1" + local pkgbuild="" + local maintainer="" + local mail="" + maintainer="$(git config --get --global user.name)" + mail="$(git config --get --global user.email)" + create_repo_dir + cd "${package_dirs[$repo]}" + if [ "$repo" == "aur" ]; then + git clone "${upstreams[$repo]}:${name}" + pkgbuild="${name}/PKGBUILD" + else + mkdir -p "${name}"/{trunk,repos} + pkgbuild="${name}/trunk/PKGBUILD" + fi + if [ ! -f "${pkgbuild}" ]; then + cp /usr/share/pacman/PKGBUILD.proto "${pkgbuild}" + sed -e "s/NAME/$name/g" \ + -e "1i# $maintainer <$mail>" \ + -e '/#/d' \ + -i "${pkgbuild}" + fi +} + remove_package() { local name="$1" local tmp_file="" @@ -129,7 +155,7 @@ update_packages() { } if [ ${#@} -gt 0 ]; then - while getopts ':a:chlur:ACEP' flag; do + while getopts ':a:chlnur:ACEP' flag; do case "${flag}" in a) check_mode_set @@ -152,6 +178,9 @@ if [ ${#@} -gt 0 ]; then check_mode_set mode="list" ;; + n) + new_package=1 + ;; # TODO: introduce -m flag for moving package (e.g. community2extra, extra2community) # TODO: introduce -n flag for creating new package (with PKGBUILD copied # from default) @@ -205,6 +234,7 @@ case "${mode}" in exit 1 else add_package "$package" + [ $new_package ] && create_package "$package" fi ;; remove) -- cgit v1.2.3-70-g09d2