Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
freddylist committed Apr 2, 2023
0 parents commit 128ff54
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 Frederik List

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PREFIX=${HOME}/.local
DESTDIR=

install:
for f in x*; do \
install -Dm0755 $$f $(DESTDIR)$(PREFIX)/bin/$$f; \
done
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# `xtools-extra`

Extra [`xtools`](https://github.com/leahneukirchen/xtools)-style scripts.

## Requirements

- `xtools`

## Usage

### xpunt

```
xpunt [path/to/pkg...]
```

Punt packages into `${XBPS_DISTDIR}/srcpkgs` if not already there.

### xupdate

```
xupdate [-H <hostdir>] [-f] <template>
```

- `-H <hostdir>` hostdir to pass to `xgensum`
- `-f` force generating checksum
- `<template>` path to template

`xupdate` will move templates (and `update` files) to `${XBPS_DISTDIR}/srcpkgs` if not already there. Then it will try to heuristically detect new versions for given templates, bump the version of the template and generate the checksum for new distfiles. Afterwards, it will move the updated template back to its original location.

### xwrapper

```
xwrapper [xbps-src options] [xbps-src target] [name or path to package]
```

`xwrapper` will `xpunt` given packages, then invoke `xbps-src` with whatever options you gave.
25 changes: 25 additions & 0 deletions xpunt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -e

XBPS_DISTDIR="$(xdistdir)" || exit 1
XBPS_SRCPKGS="${XBPS_DISTDIR}/srcpkgs"

for pkg; do
pkgdir="$(readlink -f "${pkg}")"

# Template already in distdir?
[[ -n "$(find "${XBPS_SRCPKGS}" -samefile "${pkgdir}" -print -quit)" ]] && continue

pkgname="$(basename "${pkgdir}")"

# Copy template to distdir for fetchineg
rm -rf "${XBPS_SRCPKGS:?}/${pkgname}"
cp -r "${pkgdir}" "${XBPS_SRCPKGS}"

# Handle subpackages
"${XBPS_DISTDIR}/xbps-src" show "${pkgname}" \
| grep '^subpackages:' \
| cut -f2 \
| xargs -I'{}' ln -sf "${pkgname}" "${XBPS_DISTDIR}/srcpkgs/{}"
done
113 changes: 113 additions & 0 deletions xupdate
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash

XBPS_DISTDIR="$(xdistdir)" || exit 1

function usage() {
echo >&2 'Usage: xupdate [-f] [-H <hostdir>] <template>'
exit 1
}

while getopts fhH: opt; do
case "${opt}" in
f) flag_f="-f" ;;
H) flag_H="-H ${OPTARG}" ;;
h|?) usage ;;
esac
done
shift $(( OPTIND - 1 ))

if [[ -f "${1}" ]]; then
template="${1}"
elif [[ -f "$1/template" ]]; then
template="$1/template"
elif [[ -f "${XBPS_DISTDIR}/srcpkgs/$1/template" ]]; then
template="${XBPS_DISTDIR}/srcpkgs/$1/template"
else
usage
fi

template="$(readlink -f "${template}")"

# shellcheck source=template
source "${template}"

# Set error *after* sourcing template as sourcing the template can give errors
set -e

# Template not already in distdir?
if [[ -z "$(find "${XBPS_DISTDIR}/srcpkgs" -samefile "${template}" -print -quit)" ]]; then
# Copy template to distdir for fetching
pkgdir="${template%/*}"
xbps_pkgdir="${XBPS_DISTDIR}/srcpkgs/${pkgname}"
mkdir -p "${xbps_pkgdir}"
cp "${template}" "${xbps_pkgdir}"
[[ -f "${pkgdir}/update" ]] && cp "${pkgdir}/update" "${xbps_pkgdir}"
template="$xbps_pkgdir/template"
fi

function finish() {
[[ -z "${pkgdir}" ]] && return

cp "${template}" "${pkgdir}"
}

trap 'finish' EXIT

function msg() {
printf >&2 '%s: %s\n' "${0##*/}" "$@"
}

# Update hashes for *-git packages
function update_hash() {
local remote latest today
# Remote url is likely the first 4 or so components of the URL
remote="$(echo "${distfiles}" | cut -d/ -f1,2,3,4,5)"
latest="$(git ls-remote "${remote}" | grep '\sHEAD$' | cut -f1)"

[[ "${latest}" = "${_commit}" ]] && return

today="$(date -u +%Y%m%d)"

sed -i \
-e "s/^revision=.*/revision=1/" \
-e "s/^version=.*/version=${today}/" \
-e "s/^_commit=.*/_commit=${latest}/" "${template}"

echo "${today}"
}

function update_version() {
local latest_version

latest_version="$("${XBPS_DISTDIR}/xbps-src" $flag_H update-check "${pkgname}" \
| grep -e '->' \
| tail -n1 \
| sed -e 's/.*-\(.*\)/\1/')"

[[ -z "${latest_version}" ]] && return

sed -i \
-e "s/^revision=.*/revision=1/" \
-e "s/^version=.*/version=${latest_version}/" "${template}"

echo "${latest_version}"
}

msg "Checking for ${pkgname} updates..."
new_version="$(case "${pkgname}" in
*-git) update_hash ;;
*) update_version ;;
esac)"

if [[ -z "${new_version}" ]]; then
msg "No ${pkgname} updates."
[[ -z "${flag_f}" ]] && exit 0
fi

msg "Generating checksum in '${template}'..."
xgensum -i $flag_f $flag_H "${template}" 1>&2

[[ -z "${new_version}" ]] && exit 0

msg "New version:"
echo "${new_version}"
22 changes: 22 additions & 0 deletions xwrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
#
# Build by directory instead of by package name.

set -e

XBPS_DISTDIR="$(xdistdir)" || exit 1

# Extract last argument.
pkg="${*: -1}"

# We probably weren't passed a path to a template,
# could've been another target (like clean) or a package already in distdir.
[[ ! -f "${pkg}/template" ]] && { "${XBPS_DISTDIR}/xbps-src" "$@"; exit 1; }

pkgname="$(basename "${pkg}")"

xpunt "${pkg}"

# Remove last argument $@.
set -- "${@:1:$#-1}"
"${XBPS_DISTDIR}/xbps-src" "$@" "${pkgname}"

0 comments on commit 128ff54

Please sign in to comment.