secret
Last active

  • Download Gist
Swift Geek revised this gist . 1 changed file with 2 additions and 2 deletions. View gist @ 4016cc5
changeling.sh
4 
... 63 64 65 66   67 68 69 ... 63 64 65   66 67 68 69
@@ -63,7 +63,7 @@ else
pkgname="$1"
if [ -n "$2" ] && [[ "$2" =~ ^[a-z0-9@_.]+-[0-9]+$ ]]; then
target_pkgver="$2"
- else
+ elif [ -n "$2" ]; then
fail_msg "Wrong format of second argument!"
fi
fi
... 116 117 118 119     ... 116 117 118     119
@@ -116,4 +116,4 @@ if [ -d "${pkgdir}-${target_pkgver}" ]; then
fi
fi
-fail_msg 'Failed wtf'
\ No newline at end of file
+fail_msg 'Failed wtf'
Swift Geek revised this gist . 1 changed file with 7 additions and 2 deletions. View gist @ 20ec59f
changeling.sh
9 
... 57 58 59 60   61   62 63           64 65 66 ... 57 58 59   60 61 62 63   64 65 66 67 68 69 70 71
@@ -57,10 +57,15 @@ if [ -L "$0" ]; then
fi
else
# If started via script
- [ -z "$@" ] && fail_msg "No args were passed!"
+ [ -z "$*" ] && fail_msg "No args were passed!"
[ $# -gt 2 ] && fail_msg "Too many arguments passed!"
+ [[ "$1" =~ ^[a-z0-9@_+.-]+$ ]] || fail_msg "First arg is not a valid pkgname"
pkgname="$1"
- [ -n "$2" ] && [[ "$2" =~ ^[0-9]*-[0-9]*$ ]] && target_pkgver="$2"
+ if [ -n "$2" ] && [[ "$2" =~ ^[a-z0-9@_.]+-[0-9]+$ ]]; then
+ target_pkgver="$2"
+ else
+ fail_msg "Wrong format of second argument!"
+ fi
fi
#Check && query pacman
Swift Geek revised this gist . 1 changed file with 7 additions and 7 deletions. View gist @ 5d4af21
changeling.sh
14 
... 11 12 13   14 15 16 ... 11 12 13 14 15 16 17
@@ -11,6 +11,7 @@
# Author: Swift Geek swiftgeek@gmɐil.com
#TODO: Provide help message for bad amount of args
+#TODO: Detect syntax error and write some message to log
# We don't care about epoch till somebody wants it
info_log() {
... 64 65 66 67   68 69 70 71 72 73       74 75 76 77 78 79 80 ... 65 66 67   68 69 70 71 72 73   74 75 76 77 78     79 80 81
@@ -64,17 +65,17 @@ fi
#Check && query pacman
pgrep -x pacman > /dev/null
-[ "$?" != "0" ] && fail_msg "Pacman is up and running"
+[ "$?" = "0" ] && fail_msg "Pacman is up and running"
/usr/bin/pacman -Qsq "$pkgname" > /dev/null
[ "$?" != "0" ] && fail_msg "Package not found?"
orig_pkgver=$(/usr/bin/pacman -Qs "^$pkgname\$" | grep 'local/' | awk '{print $2}')
-if [ "$orig_pkgver" = "$target_pkgver" ]; then
+if [ -z "$orig_pkgver" ] || [ -z $target_pkgver ] ; then
+ fail_msg "Pacman query failed"
+elif [ "$orig_pkgver" = "$target_pkgver" ]; then
echo 'Already downgraded!'
exit 0
-elif [ -n "$orig_pkgver" ] && [ -n $target_pkgver ] ; then
- fail_msg "Pacman query failed"
fi
pkgdir="/var/lib/pacman/local/${pkgname}" # WARNING: doesn't contain version
... 89 90 91 92 93   94 95   96 97 98 ... 90 91 92     93 94   95 96 97 98
@@ -89,10 +90,9 @@ info_log "Downgrading $pkgname $orig_pkgver to $target_pkgver"
# Actual changing
if [ -d "${pkgdir}-${orig_pkgver}" ]; then
sed -i '/\%VERSION\%/{n; s/.*/'"$target_pkgver"'/}' "${pkgdir}-${orig_pkgver}/desc"
- if [ "$?" != 0 ] && fail_log "Failed at sedding desc file. No harm was done"
- fi
+ [ "$?" != 0 ] && fail_log "Failed at sedding desc file. No harm was done"
mv "${pkgdir}-${orig_pkgver}" "${pkgdir}-${target_pkgver}"
- if [ "$?" != 0 ] && fail_log "Failed at renaming pkgdir. Pacman DB is slightly broken at this point"
+ [ "$?" != 0 ] && fail_log "Failed at renaming pkgdir. Pacman DB is slightly broken at this point"
else
fail_log "Pacman DB might be broken"
fi
Swift Geek revised this gist . 2 changed files with 114 additions and 48 deletions. View gist @ 6b943b8
changeling.sh
114 
...                                                                                                                                                                                                                                       ... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114  
@@ -0,0 +1,114 @@
+#!/bin/bash
+# Repo desc: Changes pkgver and pkgrel of installed package
+#
+# Changeling: Changes package ($1) version directly in pacman's db to a version given in $2 or $target_pkgver
+# Example uses:
+# Just downgrade to 0-0 to force update (default):
+# changeling firefox-nightly
+# For specific version:
+# changeling firefox-nightly 666-666
+#
+# Author: Swift Geek swiftgeek@gmɐil.com
+
+#TODO: Provide help message for bad amount of args
+# We don't care about epoch till somebody wants it
+
+info_log() {
+ echo "changeling: $1" # Check if not null ?
+ echo "changeling: $1" >> /var/log/pacman.log #Disable stderr?
+ return 0
+}
+fail_log() {
+ echo "changeling: $1"
+ echo "changeling: $1" >> /var/log/pacman.log
+ exit 1
+}
+fail_msg() {
+ echo "changeling: $1"
+ exit 1
+}
+
+# Check for root and if has tty - run sudo
+if [ $UID != 0 ]; then
+ tty -s
+ if [ $? = 0 ]; then
+ /usr/bin/sudo -i $(realpath -s $0) $@ && exit 0
+ exit 1
+ else
+ fail_msg "This script needs to be executed as root!"
+ fi
+fi
+
+
+# Set variables
+target_pkgver=0-0
+
+if [ -L "$0" ]; then
+ # If started from symlink
+ shname=`basename $0`
+ if [[ "$shname" =~ ^[a-z0-9@_+.-]+-[a-z0-9@_.]+-[0-9]+$ ]]; then
+ pkgname="${shname%-[a-z0-9@_.]*-[0-9]*}" # fix this perhaps * instead of + ? nah we know it's right from upper regex
+ target_pkgver=${shname:${#pkgname}+1}
+ elif [[ "$shname" =~ ^[a-z0-9@_+.-]+$ ]]; then
+ pkgname="$shname"
+ else
+ fail_msg "Invalid symlink filename - not a package"
+ fi
+else
+ # If started via script
+ [ -z "$@" ] && fail_msg "No args were passed!"
+ [ $# -gt 2 ] && fail_msg "Too many arguments passed!"
+ pkgname="$1"
+ [ -n "$2" ] && [[ "$2" =~ ^[0-9]*-[0-9]*$ ]] && target_pkgver="$2"
+fi
+
+#Check && query pacman
+pgrep -x pacman > /dev/null
+[ "$?" != "0" ] && fail_msg "Pacman is up and running"
+
+/usr/bin/pacman -Qsq "$pkgname" > /dev/null
+[ "$?" != "0" ] && fail_msg "Package not found?"
+
+orig_pkgver=$(/usr/bin/pacman -Qs "^$pkgname\$" | grep 'local/' | awk '{print $2}')
+if [ "$orig_pkgver" = "$target_pkgver" ]; then
+ echo 'Already downgraded!'
+ exit 0
+elif [ -n "$orig_pkgver" ] && [ -n $target_pkgver ] ; then
+ fail_msg "Pacman query failed"
+fi
+pkgdir="/var/lib/pacman/local/${pkgname}" # WARNING: doesn't contain version
+
+# Lock DB
+[ -e /var/lib/pacman/db.lck ] && fail_msg "Pacman DB already locked!"
+#RW stage
+echo "$$" > /var/lib/pacman/db.lck
+[ "$?" != 0 ] && fail_msg "Failed to lock pacman db"
+
+info_log "Downgrading $pkgname $orig_pkgver to $target_pkgver"
+
+# Actual changing
+if [ -d "${pkgdir}-${orig_pkgver}" ]; then
+ sed -i '/\%VERSION\%/{n; s/.*/'"$target_pkgver"'/}' "${pkgdir}-${orig_pkgver}/desc"
+ if [ "$?" != 0 ] && fail_log "Failed at sedding desc file. No harm was done"
+ fi
+ mv "${pkgdir}-${orig_pkgver}" "${pkgdir}-${target_pkgver}"
+ if [ "$?" != 0 ] && fail_log "Failed at renaming pkgdir. Pacman DB is slightly broken at this point"
+else
+ fail_log "Pacman DB might be broken"
+fi
+
+rm /var/lib/pacman/db.lck
+# 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
+ info_log 'Success'
+ exit 0
+ else
+ fail_log "RO check failed."
+ fi
+fi
+
+fail_msg 'Failed wtf'
\ No newline at end of file
downgrade_pkgver.sh
48 
... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ...                                                                                                
@@ -1,48 +0,0 @@
-#!/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
Swift Geek created this gist . View gist @ d2b84ae
downgrade_pkgver.sh
48 
...                                                                                                 ... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
@@ -0,0 +1,48 @@
+#!/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
Something went wrong with that request. Please try again.