-
-
Save swiftgeek/570d3ff3e700f8699c16 to your computer and use it in GitHub Desktop.
Just for archlinux and still needs heavy testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Author: Swift Geek swiftgeek@gmɐil.com | |
#TODO: Check for pacman | |
#TODO: Check for db.lock | |
#TODO: Lock db.lock | |
#TODO: Check if package is as old as told in arg | |
#TODO: Log this info to pacman log | |
#TODO: Check if there is anything passed as argument` | |
#TODO: Target_pkgver from arg | |
target_pkgver=0-0 | |
pkgname="$1" | |
[ -z "$@" ] && echo "No args passed!" && exit 1 | |
/usr/bin/pacman -Qsq "$pkgname" > /dev/null | |
if [ "$?" = "0" ]; then | |
orig_pkgver=$(/usr/bin/pacman -Qs "^$pkgname\$" | grep 'local/' | awk '{print $2}') | |
[ "$orig_pkgver" = "$target_pkgver" ] && echo 'Already downgraded!' && exit 0 | |
pkgdir="/var/lib/pacman/local/${pkgname}" # WARNING: doesn't contain version | |
#RW stage | |
if [ -n "$orig_pkgver" -a -d "${pkgdir}-${orig_pkgver}" ]; then | |
echo "Exist && nonzero. Proceed to sedding" | |
sed -i '/\%VERSION\%/{n; s/.*/'"$target_pkgver"'/}' "${pkgdir}-${orig_pkgver}/desc" | |
[ "$?" != 0 ] && echo "Failed at sedding desc file" && exit 1 # TODO fix this when stdout is innaccesible :< terrbile bug | |
echo "Proceed to moving" | |
mv "${pkgdir}-${orig_pkgver}" "${pkgdir}-${target_pkgver}" | |
[ "$?" != 0 ] && echo "Failed at renaming pkgdir" && exit 1 | |
fi | |
# RW stage gone | |
# Basic RO check | |
if [ -d "${pkgdir}-${target_pkgver}" ]; then | |
check_pkgver=$(awk '/^%VERSION%$/ { getline; print $0 }' "${pkgdir}-${target_pkgver}/desc" ) | |
if [ "$check_pkgver" = "$target_pkgver" ]; then | |
# TODO: Do TODO | |
echo 'Done' | |
exit 0 | |
fi | |
fi | |
echo 'Failed wtf' | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment