Last active
February 15, 2022 21:34
-
-
Save notriddle/8c0e0892ca1ac0d24d1539656282b035 to your computer and use it in GitHub Desktop.
A basic script I wrote for myself to compare package versions
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 | |
print-usage-and-die() { | |
echo "Usage: diffpkg.bash [cargo|npm] [pkg1] [pkg2]" | |
echo " pkg1 and pkg2 can have formats NAME-VERS, NAME@VERS, NAME:VERS, or NAME=VERS" | |
exit 1 | |
} | |
extract-name() { | |
case "$1" in | |
*@*) | |
echo "$1" | awk -F@ '{print $1}' | |
;; | |
*=*) | |
echo "$1" | awk -F= '{print $1}' | |
;; | |
*:*) | |
echo "$1" | awk -F: '{print $1}' | |
;; | |
*-*) | |
echo "$1" | awk -F- '{print $1}' | |
;; | |
*) print-usage-and-die ;; | |
esac | |
} | |
extract-vers() { | |
case "$1" in | |
*@*) | |
echo "$1" | awk -F@ '{print $(NF)}' | |
;; | |
*=*) | |
echo "$1" | awk -F= '{print $(NF)}' | |
;; | |
*:*) | |
echo "$1" | awk -F: '{print $(NF)}' | |
;; | |
*-*) | |
echo "$1" | awk -F- '{print $(NF)}' | |
;; | |
*) print-usage-and-die ;; | |
esac | |
} | |
case "$1" in | |
cargo) | |
type cargo-download 2>&1 > /dev/null || cargo install cargo-download | |
name1=$(extract-name $2) | |
vers1=$(extract-vers $2) | |
name2=$(extract-name $3) | |
vers2=$(extract-vers $3) | |
set -ex | |
cargo download $name1==$vers1 > $name1-$vers1.tgz | |
tar -xf $name1-$vers1.tgz | |
cargo download $name2==$vers2 > $name2-$vers2.tgz | |
tar -xf $name2-$vers2.tgz | |
;; | |
npm) | |
type cargo-download 2>&1 > /dev/null || cargo install cargo-download | |
name1=$(extract-name $2) | |
vers1=$(extract-vers $2) | |
name2=$(extract-name $3) | |
vers2=$(extract-vers $3) | |
set -ex | |
npm pack $name1@$vers1 | |
tar -xf $name1-$vers1.tgz | |
mv package $name1-$vers1 | |
npm pack $name2@$vers2 | |
tar -xf $name2-$vers2.tgz | |
mv package $name2-$vers2 | |
;; | |
*) print-usage-and-die ;; | |
esac | |
diff -ur $name1-$vers1 $name2-$vers2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment