Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

rewrite entirely in bash #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
all: install

install:
cp pacstall-qa.wrapper $(DESTDIR)/usr/bin/pacstall-qa
install -Dm755 pacstall-qa -t $(DESTDIR)/usr/share/pacstall-qa/
install -Dm755 pacstall-qa -t $(DESTDIR)/usr/bin/
install -Dm644 README.md -t $(DESTDIR)/usr/share/pacstall-qa/

uninstall:
Expand Down
110 changes: 74 additions & 36 deletions pacstall-qa
Original file line number Diff line number Diff line change
@@ -1,42 +1,80 @@
#!/usr/bin/env nu
#!/bin/bash

def parse-pr [pr: string, request: string] -> list {
return ($"($pr)/($request)" | parse "{provider}:{user}/{repo}/{pr}")
}
ansi_red=$(tput setaf 1)
ansi_green=$(tput setaf 2)
ansi_purple=$(tput setaf 5)
ansi_reset=$(tput sgr0)

def parse-link [provider: list, pkg: string] -> [list<string, list>] {
match $provider.provider.0 {
"github" => {
let gh_provides = (http get $"https://api.github.com/repos/($provider.user.0)/($provider.repo.0)/pulls/($provider.pr.0)")
return [$"https://raw.githubusercontent.com/($gh_provides.head.repo.full_name)/($gh_provides.head.sha)" $gh_provides]
},
_ => {
error make -u {
msg: $"(ansi red)'($provider.provider.0)' is not a valid provider!(ansi reset)"
}
},
}
parse_pr() {
IFS=':' read -ra ADDR <<< "$1"
local provider user repo pr
provider="${ADDR[0]}"
user=$(echo "${ADDR[1]}" | cut -d'/' -f1)
repo=$(echo "${ADDR[1]}" | cut -d'/' -f2)
pr="$2"
echo "$provider" "$user" "$repo" "$pr"
}

# A tool to target and install packages based off of PRs
def main [
--metalink (-m): string = "github:pacstall/pacstall-programs" # Parse a URL to target for pacstall, default to pacstall-programs
--number (-n): string # PR number
--install (-I): string # Package to install
] -> int {

if ($number | is-empty) or ($install | is-empty) {
print -e "'--number' and '--install' cannot be empty!"
parse_link() {
unset login
local provider="$1" user="$2" repo="$3" pr="$4" pkg="$5"
if [[ "$provider" == "github" ]]; then
gh_provides=$(curl -s "https://api.github.com/repos/$user/$repo/pulls/$pr")
head_repo_full_name=$(echo "$gh_provides" | jq -r '.head.repo.full_name')
head_sha=$(echo "$gh_provides" | jq -r '.head.sha')
login=$(echo "$gh_provides" | jq -r '.head.user.login')
echo "https://raw.githubusercontent.com/$head_repo_full_name/$head_sha" "$login"
else
echo "${ansi_red}$provider${ansi_reset} is not a valid provider!"
exit 1
}
let parsed_pr = (parse-pr $metalink $number)
let provider_url = (parse-link $parsed_pr $install)
print $"Backing up '/usr/share/pacstall/repo/pacstallrepo'"
^sudo mv /usr/share/pacstall/repo/pacstallrepo /usr/share/pacstall/repo/pacstallrepo.pacstall-qa.bak
echo $"($provider_url.0)\n" | ^sudo tee /usr/share/pacstall/repo/pacstallrepo out> /dev/null
print $"Installing (ansi green)($install)(ansi reset)\((ansi purple)($provider_url.1.head.user.login)(ansi reset):(ansi red)($parsed_pr.pr.0)(ansi reset)\)"
^pacstall -I $"($install)"
print $"Returning '/usr/share/pacstall/repo/pacstallrepo' backup"
^sudo rm -f /usr/share/pacstall/repo/pacstallrepo
^sudo mv /usr/share/pacstall/repo/pacstallrepo.pacstall-qa.bak /usr/share/pacstall/repo/pacstallrepo
fi
}

cleanup() {
if [[ -f /usr/share/pacstall/repo/pacstallrepo.pacstall-qa.bak ]]; then
echo "Returning '/usr/share/pacstall/repo/pacstallrepo' backup"
sudo rm -f /usr/share/pacstall/repo/pacstallrepo
sudo mv /usr/share/pacstall/repo/pacstallrepo.pacstall-qa.bak /usr/share/pacstall/repo/pacstallrepo
fi
}

trap cleanup EXIT INT

metalink="github:pacstall/pacstall-programs"
unset number inst

while (("$#">0)); do
case "$1" in
-m|--metalink)
metalink="$2"
shift
;;
-n|--number)
number="$2"
shift
;;
-I|--install)
inst="$2"
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done

if [[ -z "$number" || -z "$inst" ]]; then
echo "'--number' and '--install' cannot be empty!"
exit 1
fi

read provider user repo pr <<< $(parse_pr "$metalink" "$number")
read provider_url login <<< $(parse_link "$provider" "$user" "$repo" "$pr" "$inst")

echo "Backing up '/usr/share/pacstall/repo/pacstallrepo'"
sudo mv /usr/share/pacstall/repo/pacstallrepo /usr/share/pacstall/repo/pacstallrepo.pacstall-qa.bak
echo "$provider_url" | sudo tee /usr/share/pacstall/repo/pacstallrepo > /dev/null
echo "Installing ${ansi_green}$inst${ansi_reset}(${ansi_purple}$login${ansi_reset}:${ansi_red}$pr${ansi_reset})"
pacstall -I "$inst"
11 changes: 0 additions & 11 deletions pacstall-qa.wrapper

This file was deleted.