summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xaurget3
-rwxr-xr-xgeoip-hostnames6
-rwxr-xr-xpdf-shrink7
-rw-r--r--upgrade_pg.sh41
4 files changed, 57 insertions, 0 deletions
diff --git a/aurget b/aurget
new file mode 100755
index 0000000..f4db01a
--- /dev/null
+++ b/aurget
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+git clone https://aur.archlinux.org/$1.git
diff --git a/geoip-hostnames b/geoip-hostnames
new file mode 100755
index 0000000..bd6849f
--- /dev/null
+++ b/geoip-hostnames
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+for i in "$@"; do
+ printf '%s ' "$i"
+ geoiplookup "$i" | grep 'GeoIP City Edition, Rev 1:' | sed 's#GeoIP City Edition, Rev 1: ##'
+done
diff --git a/pdf-shrink b/pdf-shrink
new file mode 100755
index 0000000..6e1313e
--- /dev/null
+++ b/pdf-shrink
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+# Source: http://tex.stackexchange.com/a/41273
+
+file=$1
+
+gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile="${1%.pdf}_small.pdf" "$file"
diff --git a/upgrade_pg.sh b/upgrade_pg.sh
new file mode 100644
index 0000000..21ee18a
--- /dev/null
+++ b/upgrade_pg.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+set -e
+
+## Set the old version that we want to upgrade from.
+TO_VERSION=$(pacman -Q postgresql | grep -Po '(?<=postgresql )[0-9]\.[0-9]')
+to_major=$(echo "$TO_VERSION" | awk -F'.' '{print $1}')
+to_minor=$(echo "$TO_VERSION" | awk -F'.' '{print $2}')
+if [[ ${to_major} -ne 9 ]]; then
+ echo "WARNING: major upgrade detected, aborting..."
+ exit 1
+fi
+from_major="${to_major}"
+from_minor="$((to_minor - 1))"
+export FROM_VERSION="${from_major}.${from_minor}"
+
+# free space check
+used_space=$(df --local --output=pcent /var/lib/postgres/ | grep -Po '[0-9]{1,3}(?=%)')
+if [[ ${used_space} -ge 50 ]]; then
+ echo "ERROR: not enough free space for upgrade with backup, aborting..."
+ exit 2
+fi
+
+pacman -S --needed postgresql-old-upgrade
+chown postgres:postgres /var/lib/postgres/
+if [[ -d "/var/lib/postgres/data-${FROM_VERSION}" ]]; then
+ echo "ERROR: backup data-${FROM_VERSION} directory already exists, aborting..."
+ exit 3
+fi
+su - postgres -c "mv /var/lib/postgres/data /var/lib/postgres/data-${FROM_VERSION}"
+su - postgres -c 'mkdir /var/lib/postgres/data'
+su - postgres -c "initdb --locale $LANG -E UTF8 -D /var/lib/postgres/data"
+vimdiff "/var/lib/postgres/data/pg_hba.conf" "/var/lib/postgres/data-${FROM_VERSION}/pg_hba.conf"
+vimdiff "/var/lib/postgres/data/postgresql.conf" "/var/lib/postgres/data-${FROM_VERSION}/postgresql.conf"
+cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.crt" "/var/lib/postgres/data/server.crt"
+cp -avx "/var/lib/postgres/data-${FROM_VERSION}/server.key" "/var/lib/postgres/data/server.key"
+systemctl stop postgresql.service
+su - postgres -c "pg_upgrade -b /opt/pgsql-${FROM_VERSION}/bin/ -B /usr/bin/ -d /var/lib/postgres/data-${FROM_VERSION} -D /var/lib/postgres/data"
+systemctl daemon-reload
+systemctl start postgresql.service
+su - postgres -c '/var/lib/postgres/analyze_new_cluster.sh'
+su - postgres -c '/var/lib/postgres/delete_old_cluster.sh'