]> code.delx.au - monosys/blobdiff - aur-install
gnome-shell-raise-window
[monosys] / aur-install
index 4c22cb030f754629e7cb05e69d81a1ba67760152..6c5b5a2fd5cc65ce5ff72294aa25e751f922168c 100755 (executable)
@@ -1,41 +1,51 @@
 #!/bin/bash
 
-set -e
+set -eu
 
-pkgname="$1"
-if [ -z "$pkgname" ]; then
+PKGNAME="$1"
+if [ -z "$PKGNAME" ]; then
     echo "Usage: $0 pkgname"
     exit 1
 fi
-absdir="/var/abs/local/${pkgname}"
-url="https://aur.archlinux.org/packages/${pkgname:0:2}/${pkgname}/${pkgname}.tar.gz"
-
-unpackdir="${absdir}/unpack"
-mkdir -p "$unpackdir"
-
-curl -s "$url" | tar zx --strip-components=1 -C "$unpackdir"
-for b in "$unpackdir"/*; do
-    a="${absdir}/$(basename "$b")"
-    if [ -r "$a" ]; then
-        diff -u "$a" "$b" || true
-    else
-        echo -e "\nNEW FILE: $a\n"
-        cat "$b"
-        echo -e "\n^^ NEW FILE: $a\n"
-    fi
-done
-
 
-read -p "Ok? (y/n) " ok
-if [ "$ok" != "y" ]; then
-    exit 1
+shift
+MAKEPKG_CMD=("$@")
+if [ ${#MAKEPKG_CMD[@]} -eq 0 ]; then
+    MAKEPKG_CMD=("makepkg" "-sri")
 fi
 
+function enter_directory {
+    mkdir -p "$1"
+    cd "$1"
+}
 
-mv -v "${unpackdir}"/* "${absdir}/"
-rm -f "${unpackdir}/.SRCINFO"
-rmdir "$unpackdir"
-
-
-(cd "$absdir" && makepkg -i)
-
+function fetch_latest_changes {
+    if [ ! -d .git ]; then
+        git init
+        git remote add origin "https://aur.archlinux.org/${PKGNAME}"
+    fi
+    git fetch
+    git reset origin/master
+}
+
+function show_diff {
+    git diff -R
+}
+
+function ask_user_to_continue {
+    read -r -p "Ok? (y/n) " ok
+    if [ "$ok" != "y" ]; then
+        return 1
+    fi
+}
+
+function build_and_install {
+    git checkout .
+    "${MAKEPKG_CMD[@]}"
+}
+
+enter_directory "/var/abs/${PKGNAME}"
+fetch_latest_changes
+show_diff
+ask_user_to_continue
+build_and_install