From 99f8d86b7ea1f325dc0f8bc8585494485af7be68 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Sun, 23 Apr 2023 14:27:07 +0300 Subject: [PATCH] Add 'dummypkg' tool --- README.md | 1 + tools/PKGBUILD | 4 +- tools/dummypkg.sh | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tools/dummypkg.sh diff --git a/README.md b/README.md index c02f5eb..c47149d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Various shell tools, bundled in a custom `archtools` package. See [PKGBUILD](too | `bininfo` | Show information about an executable in PATH on Arch Linux | | `buildpkg` | Build a local package on the current directory which has `PKGBUILD` on Arch Linux | | `deltmpfiles` | Delete current temporary files from pre-defined locations | +| `dummypkg` | Create a dummy Arch Linux package | | `extract` | Extract wide range of various archive types with native tools | | `findinpkg` | Find text patterns & print occurences with matching lines numbers in Arch Linux package files | | `findmatch` | Grep/List matching strings in a specific folder | diff --git a/tools/PKGBUILD b/tools/PKGBUILD index 4974311..1983beb 100644 --- a/tools/PKGBUILD +++ b/tools/PKGBUILD @@ -42,6 +42,7 @@ genmac.sh getsource.sh # TODO: More implementation needed. See the file for details nowner.sh # TODO: More implementation needed. See the file for details pkgdeps.sh # TODO: More implementation needed. See the file for details +dummypkg.sh archrisks.sh showpkg.sh deltmpfiles.sh @@ -71,9 +72,10 @@ sha256sums=('891d763f852d3a61216a384a15ca01c57178d3a5fea8aa858de0643998e9ba58' 'c96b43cc49e6872cdd3b6e51cb490ca8ea2d990f2c3545bed106a21df86648eb' '3bfac88603fe0f19383bc8b1ca7e2bc6795a90e851eaefd0758d515edd916100' '3cf521359e473256a52e2a9fbcbfa3f0d39f42befa2d9a79cb7c51372f925c7b' - '8ed38b8f9020280a29999a524f1ad6fb1145d4f00827df45b256bf5eb5a450a1' + '89d421e4981e0907b9095165631791ac034c0d33a215a71c21a59acbf2c41480' '1424ad779f5f673c01ac2845f5e3749b7c7b47dfdaa173bd45c4e866dfa4da22' '7493ff8f2321b04fab6c4b743a15708d9aca4383ce0c934c6ed4d091f1dfd76f' + '0524c509b1378dd275c8e396bcafb6df9de48248739c528bc335f879c4b08bfc' '6290400b493a6e498ffe4a457274c3c4da4de60f5f3043cb36d08c9ca29cce63' '4a9693bdc1d6a10e54266bf7b3d440e926d66c61ef6d18774a2db951aa4dd478' '8bbcb61e6283bda4988468271cbaee0d7c537342a095466b4ea309bcb782eaf2' diff --git a/tools/dummypkg.sh b/tools/dummypkg.sh new file mode 100644 index 0000000..3f5b46d --- /dev/null +++ b/tools/dummypkg.sh @@ -0,0 +1,105 @@ +#!/bin/env sh + +# dummypkg - Create a dummy Arch Linux package +# +# Copyright (C) 2023 Pekka Helenius +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. /usr/share/makepkg/util/message.sh +colorize + +if [[ -z $1 ]] +then + error "Provide a package name" + exit 1 +fi + +PKG=$1 +PKGBUILD_FILE="PKGBUILD.tmp" +PACMAN_FILE="pacman.tmp" + +msg "Preparing dummy package: $PKG" + +description="dummy package" +version="0.1" +release="1" +provides=($PKG) + +purge() { + + msg "Cleaning up..." + + pkgfile_prefix="$PKG-$version-$release-any.pkg.tar" + pkgfile=$(find . -maxdepth 1 -type f -iname "${pkgfile_prefix}*" | head -1) + + [[ -f ${pkgfile} ]] && rm -f ${pkgfile} + [[ -f ${PKGBUILD_FILE} ]] && rm -f ${PKGBUILD_FILE} + [[ -f ${PACMAN_FILE} ]] && rm -f ${PACMAN_FILE} + [[ -d src ]] && rm -rf src + [[ -d pkg ]] && rm -rf pkg + + exit $1 + +} + +remote_info() { + pacman_info=$(pacman -Si $PKG > $PACMAN_FILE) + if [[ $? -eq 0 ]] + then + + # Description + description=$(echo $(grep -oP "^Description.*: \K.*(?=.*)" $PACMAN_FILE) "("$description")") + + # Provides + provides_pkgs=($(grep -oP "^Provides.*: \K[^A-Z]*(?=[^A-Z]*)" $PACMAN_FILE)) + provides=(${provides[@]} ${provides_pkgs[@]}) + + # Version + version_full=$(grep -oP "^Version.*: \K.*(?=.*)" $PACMAN_FILE) + version=$(echo $version_full | awk '{sub(/-.*/,"",$0); print $0}') + release=$(echo $version_full | awk '{sub(/.*-/,"",$0); print $0}') + + fi + +} + +trap "purge 1" SIGINT SIGKILL SIGABRT SIGTERM + +msg "Setting version number and provided packages information..." +remote_info + +msg2 "Description: ${description}" +msg2 "Provides: ${provides[*]}" +msg2 "Version: $version" +msg2 "Release: $release" + +cat < ${PKGBUILD_FILE} +pkgname="${PKG}" +pkgver=$version +pkgrel=$release +pkgdesc="${description}" +arch=(any) +provides=(${provides[@]}) +groups=(dummy) +EOF + +if [[ ! -f ${PKGBUILD_FILE} ]] +then + error "No PKGBUILD found" + exit 1 +fi + +makepkg -Cfi -p ${PKGBUILD_FILE} +purge 0