From 1dabf5a8d511db458dd529588e57a8ed8185787a Mon Sep 17 00:00:00 2001 From: Cem Keylan Date: Thu, 28 May 2020 16:45:43 +0300 Subject: added new utilities, changed repository structure --- README | 23 +++++++++++++++-------- alt/kiss-exec | 23 +++++++++++++++++++++++ alt/kiss-getchoice | 16 ++++++++++++++++ kiss-cargo-urlgen | 17 ----------------- kiss-cargolock-urlgen | 21 --------------------- kiss-changelog | 11 ----------- kiss-exec | 23 ----------------------- kiss-getchoice | 16 ---------------- kiss-orphans | 23 ----------------------- kiss-reporevdepends | 17 ----------------- other/kiss-changelog | 11 +++++++++++ other/kiss-orphans | 23 +++++++++++++++++++++++ repo/git/kiss-add | 13 +++++++++++++ repo/git/kiss-bump | 12 ++++++++++++ repo/git/kiss-commit | 5 +++++ repo/git/kiss-maintainer | 18 ++++++++++++++++++ repo/git/kiss-rel | 16 ++++++++++++++++ repo/git/kiss-update | 2 ++ repo/kiss-cargo-urlgen | 17 +++++++++++++++++ repo/kiss-cargolock-urlgen | 21 +++++++++++++++++++++ repo/kiss-reporevdepends | 17 +++++++++++++++++ 21 files changed, 209 insertions(+), 136 deletions(-) create mode 100755 alt/kiss-exec create mode 100755 alt/kiss-getchoice delete mode 100755 kiss-cargo-urlgen delete mode 100755 kiss-cargolock-urlgen delete mode 100755 kiss-changelog delete mode 100755 kiss-exec delete mode 100755 kiss-getchoice delete mode 100755 kiss-orphans delete mode 100755 kiss-reporevdepends create mode 100755 other/kiss-changelog create mode 100755 other/kiss-orphans create mode 100755 repo/git/kiss-add create mode 100755 repo/git/kiss-bump create mode 100755 repo/git/kiss-commit create mode 100755 repo/git/kiss-maintainer create mode 100755 repo/git/kiss-rel create mode 100755 repo/git/kiss-update create mode 100755 repo/kiss-cargo-urlgen create mode 100755 repo/kiss-cargolock-urlgen create mode 100755 repo/kiss-reporevdepends diff --git a/README b/README index 2a9919a..f07589f 100644 --- a/README +++ b/README @@ -16,14 +16,27 @@ kiss). You can install by doing - for script in kiss-*; do - install -Dm755 "$script" "/usr/local/bin/$script" + find . -type f -name 'kiss-*' | while read -r script; do + install -Dm755 "$script" "/usr/local/bin/${script##*/}" done Or install the `kiss-extra` package on Carbs Linux. +Repository structure +-------------------- + +Scripts are dividied into categoried folders. + + + / + ├── alt - scripts related to the alternatives system. + ├── other - self explanatory + └── repo - scripts for repository management + └── git - scripts for git operations, commit messages etc. + + New Scripts ----------- @@ -54,9 +67,3 @@ Licensing This repository contains scripts that were initially in the package manager itself. Some of these were initially authored by Dylan Araps. License notices are made where needed. - - -Carbs Linux directory ---------------------- - -Carbs Linux directory is for diff --git a/alt/kiss-exec b/alt/kiss-exec new file mode 100755 index 0000000..d2b3217 --- /dev/null +++ b/alt/kiss-exec @@ -0,0 +1,23 @@ +#!/bin/sh +# Execute a command inside the alternatives system + +usage() { + printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg] [command]" + exit "$1" +} + +case "$1" in ''|--help|-h) usage 0; esac +[ "$2" ] || usage 1 + +pkg=$1 + +[ "${2##/*}" ] && command=">usr>bin>$2" || + command="$(printf '%s' "$2" | sed 's#/#>#g')" + +[ -h "${file:=/var/db/kiss/choices/$pkg$command}" ] && { + printf 'ERROR: %s\n' "$file is a symlink" + exit 1 +} + +shift 2 +exec "/var/db/kiss/choices/$pkg$command" "$@" diff --git a/alt/kiss-getchoice b/alt/kiss-getchoice new file mode 100755 index 0000000..75521b4 --- /dev/null +++ b/alt/kiss-getchoice @@ -0,0 +1,16 @@ +#!/bin/sh -e +# Prints the full path to a file in the alternatives system. + +case "$1" in ''|--help|-h) + printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg] [command]" + exit 0; esac + +~/proj/carbslinux/kiss/kiss l "$1" >/dev/null + +[ "$2" ] +file="/var/db/kiss/choices/$1$(printf '%s' "$2" | sed 's#/#>#g')" +[ -f "$file" ] || { + printf '\033[1;33m!> \033[1;36m%s \033[m%s\n' "$1" "choice '$2' not found" >&2 + exit 1 +} +printf '%s\n' "$file" diff --git a/kiss-cargo-urlgen b/kiss-cargo-urlgen deleted file mode 100755 index 2105329..0000000 --- a/kiss-cargo-urlgen +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# Create static cargo sources for Rust packages - -# Copyright (C) 2020 - Dylan Araps. -# Copyright (C) 2020 - Cem Keylan. -# Distributed under the terms of the MIT License - -case "$1" in ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [crate+ver] [crate+ver]"; exit 0 ; esac - -# We convert the name-version seperator from '+' to '-' to -# avoid issues that may arise from version numbers that include -# a '-'. - -for crate in "$@"; do - printf 'https://static.crates.io/crates/%s/%s.crate vendor\n' \ - "${crate%+*}" "$(echo "$crate" | sed 's/+/-/')" -done diff --git a/kiss-cargolock-urlgen b/kiss-cargolock-urlgen deleted file mode 100755 index 7d78a6a..0000000 --- a/kiss-cargolock-urlgen +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# Convert the given Cargo.lock file to sources - -case "$1" in - -) set -- /dev/stdin ;; - ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} " "" \ - "'-' can be used to read from stdin." ; exit 0 -esac - -# Word splitting is intentional -# shellcheck disable=2046 -set -- $(sed '/name =/b;/version =/b;d' "$1" | - sed 's/version = /#/g;s/name = //;s/"//g' | - tr '\n' ' ' | sed 's/ #/#/g') - -# We convert the name-version seperator to '#' and back to '-' -# to avoid issues that may arise from version names with a '-' -for crate in "$@" ; do - printf 'https://static.crates.io/crates/%s/%s.crate vendor\n' \ - "${crate%#*}" "$crate" | sed 's/#/-/g' -done diff --git a/kiss-changelog b/kiss-changelog deleted file mode 100755 index ed323d8..0000000 --- a/kiss-changelog +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -e -# Print the git log of the specific package - -case "$1" in ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg]"; exit 0; esac - -kiss s "$1" >/dev/null -cd "$(kiss s "$1" | sed 1q)" - -# Pipe to cat so it doesn't automatically paged -# by git. -git log --format='<%as> [%an] %s - %h' . | cat diff --git a/kiss-exec b/kiss-exec deleted file mode 100755 index d2b3217..0000000 --- a/kiss-exec +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# Execute a command inside the alternatives system - -usage() { - printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg] [command]" - exit "$1" -} - -case "$1" in ''|--help|-h) usage 0; esac -[ "$2" ] || usage 1 - -pkg=$1 - -[ "${2##/*}" ] && command=">usr>bin>$2" || - command="$(printf '%s' "$2" | sed 's#/#>#g')" - -[ -h "${file:=/var/db/kiss/choices/$pkg$command}" ] && { - printf 'ERROR: %s\n' "$file is a symlink" - exit 1 -} - -shift 2 -exec "/var/db/kiss/choices/$pkg$command" "$@" diff --git a/kiss-getchoice b/kiss-getchoice deleted file mode 100755 index 75521b4..0000000 --- a/kiss-getchoice +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -e -# Prints the full path to a file in the alternatives system. - -case "$1" in ''|--help|-h) - printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg] [command]" - exit 0; esac - -~/proj/carbslinux/kiss/kiss l "$1" >/dev/null - -[ "$2" ] -file="/var/db/kiss/choices/$1$(printf '%s' "$2" | sed 's#/#>#g')" -[ -f "$file" ] || { - printf '\033[1;33m!> \033[1;36m%s \033[m%s\n' "$1" "choice '$2' not found" >&2 - exit 1 -} -printf '%s\n' "$file" diff --git a/kiss-orphans b/kiss-orphans deleted file mode 100755 index fd8b9d1..0000000 --- a/kiss-orphans +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -e -# List orphaned packages - -# Copyright (C) 2019-2020 - Dylan Araps. -# Distributed under the terms of the MIT License. - -case "$1" in ''|--help|-h) - printf '\033[1;33m-> \033[m%s\n' \ - "${0##*/}: lists packages that do not have any packages depending on them" >&2 - exit 0 -esac - -cd "$KISS_ROOT/var/db/kiss/installed/" - -for pkg in *; do - case $pkg in - baseinit|baselayout|gcc|pkgconf|e2fsprogs|musl|\ - make|busybox|bzip2|grub|kiss|git|linux-headers) - continue - esac - - grep -q "^$pkg$" ./*/depends || printf '%s\n' "$pkg" -done diff --git a/kiss-reporevdepends b/kiss-reporevdepends deleted file mode 100755 index 59262f0..0000000 --- a/kiss-reporevdepends +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# Display packages on the repository which depend on package -# shellcheck disable=2086 - -case "$1" in ''|--help|-h) printf 'usage: %s \n' "${0##*/}"; exit 0; esac - -pkg="$1" -IFS=:; set -- $KISS_PATH; unset IFS - -for repo do - # Change directory to the upper directory of the repository - # so it outputs packages in this nice looking format. - # repository/package: - cd "$repo/.." ||: - # This grep only checks for the full word - grep "^$pkg\$\|^$pkg\s" -- "${repo##*/}"/*/depends 2>/dev/null ||: -done diff --git a/other/kiss-changelog b/other/kiss-changelog new file mode 100755 index 0000000..ed323d8 --- /dev/null +++ b/other/kiss-changelog @@ -0,0 +1,11 @@ +#!/bin/sh -e +# Print the git log of the specific package + +case "$1" in ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [pkg]"; exit 0; esac + +kiss s "$1" >/dev/null +cd "$(kiss s "$1" | sed 1q)" + +# Pipe to cat so it doesn't automatically paged +# by git. +git log --format='<%as> [%an] %s - %h' . | cat diff --git a/other/kiss-orphans b/other/kiss-orphans new file mode 100755 index 0000000..fd8b9d1 --- /dev/null +++ b/other/kiss-orphans @@ -0,0 +1,23 @@ +#!/bin/sh -e +# List orphaned packages + +# Copyright (C) 2019-2020 - Dylan Araps. +# Distributed under the terms of the MIT License. + +case "$1" in ''|--help|-h) + printf '\033[1;33m-> \033[m%s\n' \ + "${0##*/}: lists packages that do not have any packages depending on them" >&2 + exit 0 +esac + +cd "$KISS_ROOT/var/db/kiss/installed/" + +for pkg in *; do + case $pkg in + baseinit|baselayout|gcc|pkgconf|e2fsprogs|musl|\ + make|busybox|bzip2|grub|kiss|git|linux-headers) + continue + esac + + grep -q "^$pkg$" ./*/depends || printf '%s\n' "$pkg" +done diff --git a/repo/git/kiss-add b/repo/git/kiss-add new file mode 100755 index 0000000..3f29946 --- /dev/null +++ b/repo/git/kiss-add @@ -0,0 +1,13 @@ +#!/bin/sh +# Commit the current directory as a new package + +case "$1" in --help|-h) printf '%s\n' "usage: ${0##*/}"; exit 0; esac + +read -r ver _ < version || { + printf '%s\n' "could not find version file, are you on a package directory?" + exit 1 +} + +# Unstage all changes and stage the current directory +git reset; git add . +git commit -m "${PWD##*/}: add new package at $ver" diff --git a/repo/git/kiss-bump b/repo/git/kiss-bump new file mode 100755 index 0000000..e4b758f --- /dev/null +++ b/repo/git/kiss-bump @@ -0,0 +1,12 @@ +#!/bin/sh +# Commit the current directory as a version bump + +case "$1" in --help|-h) printf '%s\n' "usage: ${0##*/}"; exit 0 ; esac + +read ver _ < version || { + printf '%s\n' "could not find version file, are you on a package directory?" + exit 1 +} + +git reset; git add . +git commit -m "${PWD##*/}: bump to $ver" diff --git a/repo/git/kiss-commit b/repo/git/kiss-commit new file mode 100755 index 0000000..ae0315a --- /dev/null +++ b/repo/git/kiss-commit @@ -0,0 +1,5 @@ +#!/bin/sh +# Commit a package without the prefix of 'package:' + +[ "$1" ] || { printf 'usage: %s \n' "${0##*/}"; exit 0 ;} +git reset; git add .; git commit -m "${PWD##*/}: $*" diff --git a/repo/git/kiss-maintainer b/repo/git/kiss-maintainer new file mode 100755 index 0000000..629a893 --- /dev/null +++ b/repo/git/kiss-maintainer @@ -0,0 +1,18 @@ +#!/bin/sh -ef +# Find the maintainer of a package + +# Copyright (C) 2019-2020 Dylan Araps. +# Copyright (C) 2929 Cem Keylan. +# Distributed under the terms of the MIT License + +case "$1" in ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} " ; exit 0 ; esac + +kiss s "$1" | while read -r repo; do cd "$repo" + m=$(git log -1 version 2>/dev/null) ||: + m=${m##*Author: } + m=${m%%>*} + + [ "$m" ] || continue + + printf '=> %s\n%s>\n' "$PWD" "$m" +done diff --git a/repo/git/kiss-rel b/repo/git/kiss-rel new file mode 100755 index 0000000..ae76c6e --- /dev/null +++ b/repo/git/kiss-rel @@ -0,0 +1,16 @@ +#!/bin/sh +# Bump the release number of a package + +case "$1" in --help|-h) printf '%s\n' "usage: ${0##*/}"; exit 0; esac + +read -r ver rel < version || { + printf '%s\n' "could not find version file, are you on a package directory?" + exit 1 +} + +# Update the version file with the new release number +printf '%s\n' "$ver $(( rel += 1 ))" > version + +# Unstage all changes and add the version file +git reset; git add version +git commit -m "${PWD##*/}: bump release number" diff --git a/repo/git/kiss-update b/repo/git/kiss-update new file mode 100755 index 0000000..13f4793 --- /dev/null +++ b/repo/git/kiss-update @@ -0,0 +1,2 @@ +#!/bin/sh + diff --git a/repo/kiss-cargo-urlgen b/repo/kiss-cargo-urlgen new file mode 100755 index 0000000..2105329 --- /dev/null +++ b/repo/kiss-cargo-urlgen @@ -0,0 +1,17 @@ +#!/bin/sh +# Create static cargo sources for Rust packages + +# Copyright (C) 2020 - Dylan Araps. +# Copyright (C) 2020 - Cem Keylan. +# Distributed under the terms of the MIT License + +case "$1" in ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} [crate+ver] [crate+ver]"; exit 0 ; esac + +# We convert the name-version seperator from '+' to '-' to +# avoid issues that may arise from version numbers that include +# a '-'. + +for crate in "$@"; do + printf 'https://static.crates.io/crates/%s/%s.crate vendor\n' \ + "${crate%+*}" "$(echo "$crate" | sed 's/+/-/')" +done diff --git a/repo/kiss-cargolock-urlgen b/repo/kiss-cargolock-urlgen new file mode 100755 index 0000000..7d78a6a --- /dev/null +++ b/repo/kiss-cargolock-urlgen @@ -0,0 +1,21 @@ +#!/bin/sh +# Convert the given Cargo.lock file to sources + +case "$1" in + -) set -- /dev/stdin ;; + ''|--help|-h) printf '\033[1;33m-> \033[m%s\n' "usage: ${0##*/} " "" \ + "'-' can be used to read from stdin." ; exit 0 +esac + +# Word splitting is intentional +# shellcheck disable=2046 +set -- $(sed '/name =/b;/version =/b;d' "$1" | + sed 's/version = /#/g;s/name = //;s/"//g' | + tr '\n' ' ' | sed 's/ #/#/g') + +# We convert the name-version seperator to '#' and back to '-' +# to avoid issues that may arise from version names with a '-' +for crate in "$@" ; do + printf 'https://static.crates.io/crates/%s/%s.crate vendor\n' \ + "${crate%#*}" "$crate" | sed 's/#/-/g' +done diff --git a/repo/kiss-reporevdepends b/repo/kiss-reporevdepends new file mode 100755 index 0000000..59262f0 --- /dev/null +++ b/repo/kiss-reporevdepends @@ -0,0 +1,17 @@ +#!/bin/sh +# Display packages on the repository which depend on package +# shellcheck disable=2086 + +case "$1" in ''|--help|-h) printf 'usage: %s \n' "${0##*/}"; exit 0; esac + +pkg="$1" +IFS=:; set -- $KISS_PATH; unset IFS + +for repo do + # Change directory to the upper directory of the repository + # so it outputs packages in this nice looking format. + # repository/package: + cd "$repo/.." ||: + # This grep only checks for the full word + grep "^$pkg\$\|^$pkg\s" -- "${repo##*/}"/*/depends 2>/dev/null ||: +done -- cgit v1.2.3