From 8d262d67be847e8bf34eabbfe3780d39ddc6719b Mon Sep 17 00:00:00 2001 From: Fleshless Builder Date: Mon, 20 Nov 2017 05:12:54 +0300 Subject: [PATCH] kek --- repo-clean | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ repo-sign | 15 ++++++++++ sprunge | 3 ++ syntax | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100755 repo-clean create mode 100755 repo-sign create mode 100755 sprunge create mode 100755 syntax diff --git a/repo-clean b/repo-clean new file mode 100755 index 0000000..16db969 --- /dev/null +++ b/repo-clean @@ -0,0 +1,81 @@ +#!/usr/bin/bash + +parse_pkg_filename() { + declare filename=$1 + declare -a filename_array + + IFS='-' read -r -a filename_array <<< "$filename" + + for (( i=${#filename_array[@]}; i>=0; i-- )); do + printf '%s ' "${filename_array[$i]}" + done +} + +is_latest() { + declare filename=$1 p + + for p in "${latest[@]}"; do + if [[ "$filename" == "$p" ]]; then + return 0 + fi + done + + return 1 +} + +_pacsort() { + declare i + + for i in *.pkg.tar.xz; do + printf '%s\n' "$i" + done | pacsort -f +} + +while (( $# )); do + case "$1" in + -r) flag_rm=1;; + esac + shift +done + +if ! (( flag_rm )); then + if ! [[ -d old ]]; then + mkdir -p old || { + return 1 + } + fi +fi + +read -d '' -r -a package_files < <( _pacsort ) + +for f in "${package_files[@]}"; do + unset revision version end package_name + + read -r end revision version _ < <(parse_pkg_filename "$f") + package_name=${f%%-$version-$revision*} + + declare -g -A latest["$package_name"]="$package_name-$version-$revision-$end" +done + +for f in ${package_files[@]}; do + if is_latest "$f"; then + printf '%s is the latest version available\n' "$f" + else + printf 'Removing: %s\n' "$f" + + if (( flag_rm )); then + rm -f "$f" "${f}.sig" + else + mv "$f" old/ + + if [[ -f "${f}.sig" ]]; then + mv "${f}.sig" old/ + fi + fi + fi +done + +if [[ -d old ]]; then + cd old + exec bash "$0" -r +fi diff --git a/repo-sign b/repo-sign new file mode 100755 index 0000000..f8b756a --- /dev/null +++ b/repo-sign @@ -0,0 +1,15 @@ +#!/usr/bin/bash + +for i in *.pkg.*; do + if ! [[ "$i" == "${i%.*}.sig" ]]; then + if ! [[ -f "${i}.sig" ]]; then + unsigned_pkgs+=( "$i" ) + fi + fi +done + +for i in "${unsigned_pkgs[@]}"; do + echo $i + gpg --pinentry-mode loopback --passphrase-fd 0 --batch --no-tty --detach-sign --no-armor "$i" < ~/.gnupg/passphrase + #gpg --batch --no-tty --detach-sign --no-armor "$i" +done diff --git a/sprunge b/sprunge new file mode 100755 index 0000000..48301e7 --- /dev/null +++ b/sprunge @@ -0,0 +1,3 @@ +#!/bin/sh + +curl -F 'sprunge=<-' http://sprunge.us diff --git a/syntax b/syntax new file mode 100755 index 0000000..479611c --- /dev/null +++ b/syntax @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +_highlight() { + declare -n syn=$1 + + if [[ "$syn" ]]; then + exec highlight --force --inline-css -f -I -O xhtml -S "$syn" 2>/dev/null + else +# echo " :cgit: No syntax type provided." + exec cat + fi +} + +file_name=$1 +file_extension="${file_name##*.}" + +if ! [[ "$file_name" == "$file_extension" ]]; then + case "$file_extension" in + (md) exec cmark;; + (bash|zsh) syntax='sh';; + (*) syntax=$file_extension;; + esac +fi + +case "$file_name" in + (Makefile) syntax='makefile';; + (PKGBUILD) syntax='sh';; +esac + +# Read and output the first line +read -r + +# Set syntax if the first line is a shebang +if [[ "$REPLY" =~ ^'#!' ]]; then + case "$REPLY" in + (*sh) syntax='sh';; + (*ruby*) syntax='ruby';; + esac +fi + +{ + # Print the first line + printf '%s\n' "$REPLY" + + # Read and output everything + while read -r; do + printf '%s\n' "$REPLY" + done +} | _highlight syntax