Compare commits

...

11 Commits

Author SHA1 Message Date
a12d0a4778 buildiso: default to 'default' tree name 2021-06-05 16:04:09 +02:00
4293f5a967 Merge pull request 'commitpkg: adjust msg' (#52) from msg into master
Reviewed-on: #52
2021-06-01 19:27:33 +02:00
d3e42f60e1 commitpkg: adjust msg 2021-05-30 19:43:51 +02:00
7605aaf55c buildiso: don't write calamares unpack.conf 2021-05-26 20:20:49 +02:00
b57c5e668c links-add: fix db check 2021-05-26 17:52:13 +02:00
db17939f7d buildiso: don't write postcfg.conf 2021-05-25 16:35:19 +02:00
0818ea40e8 links-add: arch backports
* handle GPGKEY with spaces
* do not accept public-only keys for signing
* use more libmakepkg to handle common compression routines
2021-05-22 20:57:29 +02:00
9b2a478aed add missing m4_include 2021-05-20 20:19:08 +02:00
2c3578a850 gitea (#51)
Reviewed-on: #51
Co-authored-by: artoo <artoo@artixlinux.org>
Co-committed-by: artoo <artoo@artixlinux.org>
2021-05-15 20:51:00 +02:00
2dcb55cef4 gitea-api (#50)
Reviewed-on: #50
Co-authored-by: artoo <artoo@artixlinux.org>
Co-committed-by: artoo <artoo@artixlinux.org>
2021-05-15 16:41:18 +02:00
81d890cead default to gz for repo databases 2021-05-15 00:57:33 +02:00
12 changed files with 226 additions and 178 deletions

View File

@@ -1,4 +1,4 @@
VERSION=0.23
VERSION=0.24
TOOLS = artools
PREFIX ?= /usr
@@ -38,7 +38,8 @@ PKG_BIN = \
bin/pkg/find-libdeps \
bin/pkg/batchpkg \
bin/pkg/signpkg \
bin/pkg/checkrepo
bin/pkg/checkrepo \
bin/pkg/gitearepo
LN_COMMITPKG = \
extrapkg \

View File

@@ -18,17 +18,13 @@ artools
##### Runtime:
- base:
* openssh
* rsync
* haveged
* os-prober
* gnupg
* pacman
- pkg:
* namcap
* git-subrepo
* jq
* rsync
- iso:
* dosfstools

View File

@@ -15,54 +15,35 @@
m4_include(lib/util-base.sh)
m4_include(lib/util-pkg.sh)
m4_include(lib/base/message.sh)
m4_include(lib/pkg/common.sh)
m4_include(lib/pkg/git.sh)
m4_include(lib/pkg/gitea.sh)
m4_include(lib/pkg/repo.sh)
m4_include(lib/pkg/jenkins.sh)
#{{{ new git repo
get_compliant_name(){
local gitname="$1"
case "$gitname" in
*+) gitname=${gitname//+/plus} ;;
*+*) gitname=${gitname//+/-} ;;
esac
echo "$gitname"
}
subrepo_clone(){
local pkg="$1" org="$2" gitname
gitname=$(get_compliant_name "$pkg")
msg2 "Subrepo clone [%s] from (%s)" "$pkg" "$org/$gitname"
git subrepo clone "${GIT_SSH}":"$org"/"$gitname".git "$pkg"
}
local pkg="$1"
local org="$2"
local name="$3"
create_repo() {
local pkg="$1" org="$2" gitname
gitname=$(get_compliant_name "$pkg")
local json="{ \"auto_init\": true, \"name\":\"$gitname\", \"gitignores\":\"ArchLinuxPackages\", \"readme\": \"Default\" }"
msg2 "Create package repo [%s] in org (%s)" "${pkg}" "${org}"
curl -s -X POST "${GIT_URL}/api/v1/org/$org/repos?access_token=${GIT_TOKEN}" \
-H "accept: application/json" \
-H "content-type: application/json" \
-d "$json"
echo
msg2 "Subrepo clone [%s] from (%s)" "$pkg" "$org/$name"
git subrepo clone "${GIT_SSH}":"$org"/"$name".git "$pkg"
}
subrepo_new(){
cd "${TREE_DIR_ARTIX}/${group}" || return
local org
local org gitname
org=$(get_pkg_org "${package}")
gitname=$(get_compliant_name "${package}")
create_repo "${package}" "$org"
gitearepo -cr "$gitname"
add_repo_to_team "${package}" "$org" "${team}"
add_team_to_repo "$gitname" "$org" "${team}"
subrepo_clone "${package}" "$org"
subrepo_clone "${package}" "$org" "$gitname"
mkdir -p "${TREE_DIR_ARTIX}/${group}/${package}/trunk"

View File

@@ -15,7 +15,9 @@
m4_include(lib/util-base.sh)
m4_include(lib/util-pkg.sh)
m4_include(lib/base/message.sh)
m4_include(lib/pkg/common.sh)
m4_include(lib/pkg/git.sh)
m4_include(lib/pkg/gitea.sh)
m4_include(lib/pkg/repo.sh)
#{{{ functions
@@ -47,7 +49,7 @@ subrepo_pull(){
prepare_commit(){
# create new layout, copy & remove repos
if [[ -d repos ]]; then
msg "Switching to new layout ..."
msg2 "Switching to new layout ..."
[[ ! -d "$CARCH" ]] && mkdir "$CARCH"
for r in repos/*; do
@@ -61,7 +63,7 @@ prepare_commit(){
git rm -r repos
git commit -m "switch to new repo layout"
msg "Done switch"
msg2 "Done switch"
fi
if [[ $action == 'add' ]] || [[ $action == 'move' ]] ;then
@@ -85,7 +87,7 @@ check_rebuild(){
check_team(){
if [[ "${repo_src}" == "${valid_names[0]}" \
&& "${repo_dest}" == "${valid_names[1]}" ]] || \
&& "${repo_dest}" == "${valid_names[1]}" ]] || \
[[ "${repo_src}" == "${valid_names[1]}" \
&& "${repo_dest}" == "${valid_names[0]}" ]] || \
[[ "${repo_src}" == "${valid_names[1]}" \
@@ -93,10 +95,11 @@ check_team(){
[[ "${repo_src}" == "${valid_names[2]}" \
&& "${repo_dest}" == "${valid_names[1]}" ]] ;then
local org
local org gitname
org=$(get_pkg_org "${package}")
add_repo_to_team "${package}" "$org" "${repo_dest}"
remove_repo_from_team "${package}" "$org" "${repo_src}"
gitname=$(get_compliant_name "${package}")
add_team_to_repo "$gitname" "${org}" "${repo_dest}"
remove_team_from_repo "$gitname" "${org}" "${repo_src}"
fi
}
@@ -112,22 +115,24 @@ path_config() {
. "$pkgbuild"
}
get_commit_msg() {
echo "[${repo_src}] -> [${repo_dest}] '${package}-$(get_full_version)' ${action}"
}
commit_pkg() {
local commit_msg pkg
if ${remove};then
if ${remove}; then
action='remove'
commit_msg="[${repo_src}] '$pkg' ${action}"
msg "Action: %s" "$commit_msg"
if [[ "${repo_src}" == 'trunk' ]];then
pkg=${package}
git rm -r trunk
else
pkg="${package}-$(get_full_version)"
prepare_commit
git rm -r "$CARCH/${repo_src}"
fi
commit_msg="[${repo_src}] '$pkg' ${action}"
msg "Action: %s" "$commit_msg"
else
action='modify'
commit_msg="[${repo_src}] '${package}-$(get_full_version)' ${action}"
@@ -139,25 +144,22 @@ commit_pkg() {
repo_commit_pkg() {
local commit_msg
if [[ "${repo_src}" == 'trunk' ]];then
if [[ "${repo_src}" == 'trunk' ]]; then
action='add'
commit_msg=$(get_commit_msg)
msg "Action: %s" "$commit_msg"
prepare_commit
check_rebuild
cp trunk/* "$CARCH/${repo_dest}"/
else
action='move'
[[ ! -f $pkgbuild ]] && die "%s does not exist!" "$pkgbuild"
commit_msg=$(get_commit_msg)
msg "Action: %s" "$commit_msg"
prepare_commit
cp "$CARCH/${repo_src}"/* "$CARCH/${repo_dest}"/
git rm -r "$CARCH/${repo_src}"
fi
commit_msg="[${repo_src}] -> [${repo_dest}] '${package}-$(get_full_version)' ${action}"
msg "Action: %s" "$commit_msg"
git add .
git commit -m "$commit_msg"
}

89
bin/pkg/gitearepo.in Normal file
View File

@@ -0,0 +1,89 @@
#!/bin/bash
#
# Copyright (C) 2018-21 artoo@artixlinux.org
# Copyright (C) 2021 Artix Linux Developers
#
# 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; version 2 of the License.
#
# 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.
m4_include(lib/util-base.sh)
m4_include(lib/util-pkg.sh)
m4_include(lib/base/message.sh)
m4_include(lib/pkg/common.sh)
#{{{ functions
create_repo() {
local name="$1"
local org="$2"
local json url
json="{ \"auto_init\": true, \"name\":\"$name\", \"gitignores\":\"ArchLinuxPackages\", \"readme\": \"Default\" }"
url="${GIT_URL}/api/v1/org/$org/repos?access_token=${GIT_TOKEN}"
msg2 "Create package repo [%s] in org (%s)" "$name" "$org"
api_post "$url" -H "accept: application/json" \
-H "content-type: application/json" \
-d "$json"
}
transfer_repo() {
local name="$1"
local old_owner="$2"
local new_owner="landfill" json url
local json url
json="{ \"new_owner\": \"$new_owner\", \"team_ids\": []}"
url="${GIT_URL}/api/v1/repos/$old_owner/$name/transfer?access_token=${GIT_TOKEN}"
msg2 "Transfer package repo [%s] in org (%s)" "$name" "$new_owner"
api_post "$url" -H "accept: application/json" \
-H "Content-Type: application/json" \
-d "$json"
}
#}}}
usage() {
echo "Usage: ${0##*/} [options]"
echo ' -r <repo> Repo name'
echo ' -c Create git repo'
echo ' -t Transfer git repo to landfill org'
echo ' -h This help'
echo ''
echo ''
exit "$1"
}
create=false
transfer=false
opts='r:cth'
while getopts "${opts}" arg; do
case "${arg}" in
r) repo="$OPTARG" ;;
c) create=true ;;
t) transfer=true ;;
h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;;
esac
done
shift $(( OPTIND - 1 ))
org=$(get_pkg_org "${repo}")
${create} && create_repo "${repo}" "${org}"
${transfer} && transfer_repo "${repo}" "${org}"

View File

@@ -35,7 +35,7 @@ REPO_DB_PREFIX=
REPO_DB_SUFFIX=
LOCKFILE=
CLEAN_LOCK=0
# PREVENT_DOWNGRADE=0
PREVENT_DOWNGRADE=0
# ensure we have a sane umask set
umask 0022
@@ -53,7 +53,7 @@ Multiple packages to add can be specified on the command line.\n"
printf -- "\n"
printf -- "Options:\n"
printf -- " -n, --new only add packages that are not already in the database\n"
# printf -- "$(gettext " -p, --prevent-downgrade do not add package to database if a newer version is already present\n")"
printf -- " -p, --prevent-downgrade do not add package to database if a newer version is already present\n"
elif [[ $cmd == "links-remove" ]] ; then
printf -- "Usage: links-remove [options] <path-to-db> <packagename> ...\n"
printf -- "\n"
@@ -103,7 +103,7 @@ check_gpg() {
fi
if (( ! VERIFY )); then
if ! gpg --list-key "${GPGKEY}" &>/dev/null; then
if ! gpg --list-secret-key ${GPGKEY:+"$GPGKEY"} &>/dev/null; then
if [[ -n "$GPGKEY" ]]; then
error "The key ${GPGKEY} does not exist in your keyring."
elif (( ! KEY )); then
@@ -121,11 +121,11 @@ create_signature() {
local ret=0
msg "Signing database '%s'..." "${dbfile##*/.tmp.}"
local SIGNWITHKEY=""
local SIGNWITHKEY=()
if [[ -n $GPGKEY ]]; then
SIGNWITHKEY="-u ${GPGKEY}"
SIGNWITHKEY=(-u "${GPGKEY}")
fi
gpg --detach-sign --use-agent --no-armor "${SIGNWITHKEY}" "$dbfile" &>/dev/null || ret=$?
gpg --detach-sign --use-agent --no-armor "${SIGNWITHKEY[@]}" "$dbfile" &>/dev/null || ret=$?
if (( ! ret )); then
msg2 "Created signature file '%s'" "${dbfile##*/.tmp.}.sig"
@@ -155,21 +155,13 @@ verify_signature() {
}
verify_repo_extension() {
local repofile=$1
local junk=()
if [[ $1 = *.links.tar* ]] && get_compression_command "$1" junk; then
return 0
fi
case $repofile in
*.links.tar.gz) TAR_OPT="z" ;;
*.links.tar.bz2) TAR_OPT="j" ;;
*.links.tar.xz) TAR_OPT="J" ;;
*.links.tar.zst) TAR_OPT="--zstd" ;;
*.links.tar.Z) TAR_OPT="Z" ;;
*.links.tar) TAR_OPT="" ;;
*) error "'%s' does not have a valid database archive extension." \
"$repofile"
exit 1 ;;
esac
printf '%s' "$TAR_OPT"
error "'%s' does not have a valid database archive extension." "$1"
exit 1
}
# write an entry to the pacman database
@@ -201,18 +193,18 @@ db_write_entry() {
if (( ONLYADDNEW )); then
return 0
fi
# else
# pkgentry=$(find_pkgentry "$pkgname")
# if [[ -n $pkgentry ]]; then
#
# local version=$(sed -n '/^%VERSION%$/ {n;p;q}' "$pkgentry/desc")
# if (( $(vercmp "$version" "$pkgver") > 0 )); then
# warning "$(gettext "A newer version for '%s' is already present in database")" "$pkgname"
# if (( PREVENT_DOWNGRADE )); then
# return 0
# fi
# fi
# fi
else
pkgentry=$(find_pkgentry "$pkgname")
if [[ -n $pkgentry ]]; then
local version=$(sed -n '/^%VERSION%$/ {n;p;q}' "$pkgentry/desc")
if (( $(vercmp "$version" "$pkgver") > 0 )); then
warning "A newer version for '%s' is already present in database" "$pkgname"
if (( PREVENT_DOWNGRADE )); then
return 0
fi
fi
fi
fi
# remove an existing entry if it exists, ignore failures
@@ -397,7 +389,6 @@ rotate_db() {
}
create_db() {
TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
# $LOCKFILE is already guaranteed to be absolute so this is safe
dirname=${LOCKFILE%/*}
@@ -406,13 +397,13 @@ create_db() {
tempname=$dirname/.tmp.$filename
pushd "$tmpdir/${REPO_DB_NAME}" >/dev/null
if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
bsdtar -c"${TAR_OPT}"f "$tempname" *
else
local files=(*)
if [[ ${files[*]} = '*' ]]; then
# we have no packages remaining? zip up some emptyness
warning "No packages remain, creating empty database."
bsdtar -c"${TAR_OPT}"f "$tempname" -T /dev/null
files=(-T /dev/null)
fi
bsdtar -cf - "${files[@]}" | compress_as "$filename" > "$tempname"
popd >/dev/null
create_signature "$tempname"
@@ -476,7 +467,7 @@ while (( $# )); do
-s|--sign) SIGN=1 ;;
-k|--key) KEY=1 ; shift; GPGKEY=$1 ;;
-v|--verify) VERIFY=1 ;;
# -p|--prevent-downgrade) PREVENT_DOWNGRADE=1 ;;
-p|--prevent-downgrade) PREVENT_DOWNGRADE=1 ;;
*) args+=("$1") ;;
esac
shift
@@ -494,7 +485,7 @@ else
LOCKFILE=$PWD/$REPO_DB_FILE.lck
fi
verify_repo_extension "$REPO_DB_FILE" >/dev/null
verify_repo_extension "$REPO_DB_FILE"
REPO_DB_PREFIX=${REPO_DB_FILE##*/}
REPO_DB_PREFIX=${REPO_DB_PREFIX%.links.*}

View File

@@ -36,37 +36,11 @@ write_services_66_conf(){
write_services_conf 'svDir' '/etc/66/service' 'runsvDir' '/var/lib/66/system' > "$conf"
}
write_postcfg(){
local yaml
yaml=$(write_yaml_header)
yaml+=$(write_yaml_map 0 'keyrings')
for k in archlinux artix;do
yaml+=$(write_yaml_seq 2 "$k")
done
yaml+=$(write_empty_line)
printf '%s' "${yaml}"
}
write_unpackfs() {
local yaml
yaml=$(write_yaml_header)
yaml+=$(write_yaml_map 0 'unpack')
local fs="squashfs"
# ${persist} && fs="ext4"
yaml+=$(write_yaml_seq_map 2 'source' '"/run/artix/bootmnt/LiveOS/rootfs.img"')
yaml+=$(write_yaml_map 4 'sourcefs' \'"$fs"\')
yaml+=$(write_yaml_map 4 'destination' '""')
yaml+=$(write_empty_line)
printf '%s' "${yaml}"
}
configure_calamares(){
local mods="$1/etc/calamares/modules"
if [[ -d "$mods" ]];then
msg2 "Configuring: Calamares"
write_services_"${INITSYS}"_conf "$mods"
write_postcfg > "$mods"/postcfg.conf
write_unpackfs > "$mods"/unpackfs.conf
sed -e "s|services-openrc|services-${INITSYS}|" \
-i "$1"/etc/calamares/settings.conf
fi

View File

@@ -45,11 +45,11 @@ add_svc_s6(){
add_svc_66(){
local mnt="$1" names="$2"
chroot "$mnt" 66-tree -cnE root &>/dev/null
chroot "$mnt" 66-tree -cnE default &>/dev/null
for svc in $names; do
if [[ -f "$mnt"/etc/66/service/"$svc" ]]; then
msg2 "Setting %s: [%s]" "${INITSYS}" "$svc"
chroot "$mnt" 66-enable -t root "$svc" &>/dev/null
chroot "$mnt" 66-enable -t default "$svc" &>/dev/null
fi
done
}

36
lib/pkg/common.sh Normal file
View File

@@ -0,0 +1,36 @@
#!/hint/bash
#{{{ common functions
get_compliant_name(){
local gitname="$1"
case "$gitname" in
*+) gitname=${gitname//+/plus}
esac
echo "$gitname"
}
get_pkg_org(){
local pkg="$1" org sub
case ${pkg} in
ruby-*) org="packagesRuby" ;;
perl-*) org="packagesPerl" ;;
python-*|python2-*) org="packagesPython" ;;
*) sub=${pkg:0:1}; org="packages${sub^^}" ;;
esac
echo "$org"
}
api_put() {
curl -s -X PUT "$@"
}
api_delete() {
curl -s -X DELETE "$@"
}
api_post() {
curl -s -X POST "$@"
}
#}}}

View File

@@ -2,59 +2,6 @@
#{{{ git
get_compliant_name(){
local gitname="$1"
case "$gitname" in
*+) gitname=${gitname//+/plus}
esac
echo "$gitname"
}
get_pkg_org(){
local pkg="$1" org sub
case ${pkg} in
ruby-*) org="packagesRuby" ;;
perl-*) org="packagesPerl" ;;
python-*|python2-*) org="packagesPython" ;;
*) sub=${pkg:0:1}; org="packages${sub^^}" ;;
esac
echo "$org"
}
get_team_id() {
local org="$1" team="$2"
local id
id=$(curl -s -X GET "${GIT_URL}/api/v1/orgs/$org/teams/search?q=$team&access_token=${GIT_TOKEN}" \
-H "accept: application/json" | jq '.data[] .id')
echo "$id"
}
add_repo_to_team() {
local pkg="$1" org="$2" team="$3"
local id
id=$(get_team_id "$org" "$team")
local gitname
gitname=$(get_compliant_name "$pkg")
msg2 "Adding package repo [%s] to team (%s)" "$gitname" "$team"
curl -s -X PUT "${GIT_URL}/api/v1/teams/$id/repos/$org/$gitname?access_token=${GIT_TOKEN}" \
-H "accept: application/json"
}
remove_repo_from_team() {
local pkg="$1" org="$2" team="$3"
local id
id=$(get_team_id "$org" "$team")
local gitname
gitname=$(get_compliant_name "$pkg")
msg2 "Removing package repo [%s] from team (%s)" "$gitname" "$team"
curl -s -X DELETE "${GIT_URL}/api/v1/teams/$id/repos/$org/$gitname?access_token=${GIT_TOKEN}" \
-H "accept: application/json"
}
get_local_head(){
git log --pretty=%H ...refs/heads/master^ | head -n 1
}

31
lib/pkg/gitea.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/hint/bash
#{{{ gitea api
add_team_to_repo() {
local name="$1"
local org="$2"
local team="$3"
local url
url="${GIT_URL}/api/v1/repos/$org/$name/teams/$team?access_token=${GIT_TOKEN}"
msg2 "Adding team (%s) to package repo [%s]" "$team" "$name"
api_put "$url" -H "accept: application/json"
}
remove_team_from_repo() {
local name="$1"
local org="$2"
local team="$3"
local url
url="${GIT_URL}/api/v1/repos/$org/$name/teams/$team?access_token=${GIT_TOKEN}"
msg2 "Removing team (%s) from package repo [%s]" "$team" "$name"
api_delete "$url" -H "accept: application/json"
}
#}}}

View File

@@ -61,7 +61,7 @@ load_pkg_config(){
HOST_TREE_ARCH=${HOST_TREE_ARCH:-'https://github.com/archlinux'}
DBEXT=${DBEXT:-'xz'}
DBEXT=${DBEXT:-'gz'}
return 0
}