Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  1. swiftgeek revised this gist . 1 changed file with 4 additions and 4 deletions.
    View
    8 changeling.sh
    @@ -3,7 +3,7 @@
    #
    # 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):
    +# Just downgrade to a-0 to force update (default):
    # changeling firefox-nightly
    # For specific version:
    # changeling firefox-nightly 666-666
    @@ -42,12 +42,12 @@ fi
    # Set variables
    -target_pkgver=0-0
    +target_pkgver=a-0
    -if [ -L "$0" ]; then
    +if [ -L "$0" ]; then
    # If started from symlink
    shname=`basename $0`
    - if [[ "$shname" =~ ^[a-z0-9@_+.-]+-[a-z0-9@_.]+-[0-9]+$ ]]; then
    + 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
  2. Swift Geek revised this gist . 1 changed file with 2 additions and 2 deletions.
    View
    4 changeling.sh
    @@ -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,4 +116,4 @@ if [ -d "${pkgdir}-${target_pkgver}" ]; then
    fi
    fi
    -fail_msg 'Failed wtf'
    +fail_msg 'Failed wtf'
  3. Swift Geek revised this gist . 1 changed file with 7 additions and 2 deletions.
    View
    9 changeling.sh
    @@ -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
  4. Swift Geek revised this gist . 1 changed file with 7 additions and 7 deletions.
    View
    14 changeling.sh
    @@ -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,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,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
  5. Swift Geek revised this gist . 2 changed files with 114 additions and 48 deletions.
    View
    114 changeling.sh
    @@ -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'
    View
    48 downgrade_pkgver.sh
    @@ -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
  6. Swift Geek created this gist .
    View
    48 downgrade_pkgver.sh
    @@ -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.