203 lines
5.1 KiB
Bash
Executable File
203 lines
5.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Pre-release toggle
|
|
PRERELEASE="false"
|
|
# Anti-root check
|
|
[ "$EUID" -eq 0 ] && echo "For security reasons, you cannot run this as root." && exit
|
|
case "$PRERELEASE" in
|
|
"true") printf "warning: a liteaur pre-release is being used\n\n" ;;
|
|
"*") ;;
|
|
esac
|
|
# Working directory for upgrading/installing packages
|
|
DUMP=$HOME/.cache/liteaur
|
|
# Config
|
|
CONFIGFOLDER=$HOME/.config/liteaur
|
|
|
|
# Version number
|
|
VERSION='1.7.2'
|
|
|
|
# Colors
|
|
G='\033[0;32m'
|
|
NC='\033[0;0m'
|
|
B='\033[1m'
|
|
NB='\033[0m'
|
|
BL='\033[0;34m'
|
|
R='\033[0;31m'
|
|
O='\033[0;33m'
|
|
|
|
# Database lock
|
|
DBLCK="${R}${B}error: ${NC}${B}unable to lock database"
|
|
|
|
# Config-related stuff
|
|
SKIPCHECKSUMS="false"
|
|
SKIPPGPCHECK="false"
|
|
SKIPINSTALLVERIFICATION="false"
|
|
source "$CONFIGFOLDER"/config.sh 2>/dev/null
|
|
|
|
# Credits to stackoverflow for this <3
|
|
spinner() {
|
|
local i sp n
|
|
sp='/-\|'
|
|
n=${#sp}
|
|
printf ' '
|
|
while sleep 0.1; do
|
|
printf "%s\b" "${sp:i++%n:1}"
|
|
done
|
|
}
|
|
|
|
print_no_argument() {
|
|
echo -e "${R}${B}error: ${NC}no operation provided (use -h for help)";
|
|
exit 1;
|
|
}
|
|
|
|
help() {
|
|
printf "%s\n" "usage: liteaur <operation> [...]
|
|
liteaur -i Install AUR package(s)
|
|
liteaur -r Remove package(s) from update cache
|
|
liteaur -u Upgrade all available AUR packages
|
|
liteaur -s Searches for a package in the AUR
|
|
liteaur -v Prints the version of LiteAUR
|
|
liteaur -h Shows this message"
|
|
}
|
|
|
|
search() {
|
|
# No arguments
|
|
if [ -z "$1" ]; then
|
|
echo -e "${R}${B}error: ${NC}no search argument provided";
|
|
exit 1;
|
|
else
|
|
# Search query
|
|
search="$(curl -s "https://aur.archlinux.org/rpc/?v=5&type=search&arg=${1}")"
|
|
# for loop (requires base64)
|
|
trap "printf '${R}${B}error: ${NC}results exceeded aur webrpc limit' & exit 1" ERR;
|
|
for row in $(echo "$search" | jq -e -r '.results[] | @base64' || printf "${R}${B}error: ${nc}search query not found or too large" && exit 1); do
|
|
# function to simplify stuff
|
|
function jq2 {
|
|
echo "$row" | base64 --decode | jq -r "$1";
|
|
}
|
|
# Find package info
|
|
printf "${G}==> ${NC}${B}$(echo "$search" | jq2 '.Name')\n${BL}${B} -> ${NC}${B}Maintainer: $(jq2 '.Maintainer')\n${BL}${B} -> ${NC}${B}Description: $(jq2 '.Description')\n${BL}${B} -> ${NC}${B}Version: $(jq2 '.Version')\n${BL}${B} -> ${NC}${B}Upstream: $(jq2 '.URL')\n";
|
|
# finished
|
|
done
|
|
fi;
|
|
}
|
|
|
|
install_init() {
|
|
# No package provided
|
|
if [ -z "$1" ]; then
|
|
echo -e "${R}${B}error: ${NC}${B}no package provided";
|
|
exit 1;
|
|
# Checking if lck.db exists
|
|
else
|
|
if [ -f "$DUMP/lck.db" ]; then
|
|
echo -e "${DBLCK}";
|
|
exit 1;
|
|
fi
|
|
fi
|
|
# Lock the database
|
|
touch "$DUMP"/lck.db;
|
|
for var in "${@:1}"; do
|
|
# Cleans up if exited
|
|
trap 'rm -f ${DUMP}/lck.db && rm -rf "${DUMP}/${var}" && exit 2' 2;
|
|
cd "$DUMP" || exit;
|
|
git clone --quiet https://aur.archlinux.org/"$var".git 2>/dev/null;
|
|
if [ -f "$DUMP/$var/PKGBUILD" ]; then
|
|
echo -e "${G}${B}==> ${NC}${B}Cloned $var.git${NB}";
|
|
# Check if end-user has SKIPINSTALLVERIFICATION set to true or false in their config.
|
|
case $SKIPINSTALLVERIFICATION in
|
|
"false") verification_prompt ;;
|
|
"true") install_process ;;
|
|
*) verification_prompt ;;
|
|
esac
|
|
else
|
|
echo -e "${R}${B}==> ERROR: ${NC}${B}target not found: $var";
|
|
rm -rf "$DUMP/${var:?}";
|
|
rm -f "$DUMP"/lck.db;
|
|
exit 1;
|
|
fi
|
|
done
|
|
}
|
|
|
|
install_process() {
|
|
cd "$var" || exit
|
|
case $SKIPPGPCHECK in
|
|
"false") skippgpcheck_check_disabled ;;
|
|
"true") skippgpcheck_check ;;
|
|
esac
|
|
rm -f "$DUMP"/lck.db;
|
|
}
|
|
|
|
verification_prompt() {
|
|
trap 'rm -f ${DUMP}/lck.db && rm -rf "${DUMP}/${var}" && exit 2' 2;
|
|
less "$DUMP/$var"/PKGBUILD;
|
|
read -p "Install $var? [y/N] ";
|
|
case $REPLY in
|
|
Y) install_process ;;
|
|
y) install_process ;;
|
|
*) rm -f $DUMP/lck.db && rm -rf "$DUMP/$var" && exit 1 ;;
|
|
esac
|
|
}
|
|
|
|
unimplemented() {
|
|
printf "${R}${B}error: ${NC}${B}unimplemented function\n"
|
|
}
|
|
|
|
skippgpcheck_check() {
|
|
case $SKIPCHECKSUMS in
|
|
"true") makepkg -si --skipinteg ;;
|
|
"false") makepkg -si --skippgpcheck ;;
|
|
esac
|
|
}
|
|
|
|
skippgpcheck_check_disabled() {
|
|
case $SKIPCHECKSUMS in
|
|
"true") makepkg -si --skipchecksums ;;
|
|
"false") makepkg -si ;;
|
|
esac
|
|
}
|
|
|
|
update() {
|
|
if [ -f "$DUMP/lck.db" ]; then
|
|
echo -e "${DBLCK}";
|
|
exit 1;
|
|
fi
|
|
trap 'rm -f ${DUMP}/lck.db && exit 2' 2;
|
|
printf "${G}${B}==> ${NC}${B}Starting full AUR package upgrade\n";
|
|
cd "$DUMP" || exit;
|
|
for folder in *; do
|
|
if [ -f "$DUMP/$folder/PKGBUILD" ]; then
|
|
# Locks the database
|
|
touch "$DUMP"/lck.db;
|
|
cd "$DUMP"/"$folder";
|
|
makepkg -si --needed;
|
|
fi
|
|
done
|
|
rm -f "$DUMP"/lck.db;
|
|
}
|
|
|
|
removecache() {
|
|
for var in "${@:1}"; do
|
|
if [ -d "$DUMP/$var" ]; then
|
|
printf "${G}${B}==> ${NC}${B}removing cached package: $var "
|
|
spinner &
|
|
rm -rf "$DUMP/$var"
|
|
kill "$!"
|
|
printf "\n"
|
|
printf "${G}${B}==> ${NC}${B}cached package successfully removed: $var\n"
|
|
else
|
|
printf "${R}${B}==> ERROR: ${NC}${B}package not in update cache: $var\n";
|
|
rm -f "$DUMP"/lck.db;
|
|
exit 1;
|
|
fi
|
|
done
|
|
}
|
|
|
|
case $1 in
|
|
"-i") install_init "${@:2}" ;;
|
|
"-s") search "$2" ;;
|
|
"-u") update ;;
|
|
"-v") printf "LiteAUR ${VERSION}\n" ;;
|
|
"-h") help ;;
|
|
"-r") removecache "${@:2}" ;;
|
|
* ) print_no_argument
|
|
esac
|