chore(style): add shebang, set bash strict mode, create function
[webi-installers/.git] / postgres / install.sh
index c21cdb7474822517be0aca0d8f2c4749942053ca..ca41f2c182baf94795244dae9c85e1ef96c324aa 100644 (file)
@@ -1,3 +1,5 @@
+#!/bin/bash
+
 set -e
 set -u
 
@@ -6,15 +8,15 @@ pkg_cmd_name="postgres"
 
 POSTGRES_DATA_DIR=$HOME/.local/share/postgres/var
 
-pkg_get_current_version() {
+function pkg_get_current_version() {
     # 'postgres --version' has output in this format:
     #       postgres (PostgreSQL) 10.13
     # This trims it down to just the version number:
     #       10.13
-    echo "$(postgres --version 2>/dev/null | head -n 1 | cut -d' ' -f3)"
+    echo "$(postgres --version 2> /dev/null | head -n 1 | cut -d' ' -f3)"
 }
 
-pkg_install() {
+function pkg_install() {
     # mkdir -p $HOME/.local/opt
     mkdir -p "$(dirname $pkg_src)"
 
@@ -22,17 +24,18 @@ pkg_install() {
     mv ./"p"* "$pkg_src"
 }
 
-pkg_link() {
+function pkg_link() {
     # rm -f "$HOME/.local/opt/postgres"
     rm -f "$pkg_dst"
-    rm -f "$HOME/Applications/pgAdmin*.app" || true
+    rm -f "$HOME/Applications/pgAdmin"*.app || true
 
     # ln -s "$HOME/.local/opt/postgres-v10.13" "$HOME/.local/opt/postgres"
     ln -s "$pkg_src" "$pkg_dst"
+    mkdir -p ~/Applications
     ln -s "$pkg_src/pgAdmin 4.app" "$HOME/Applications/pgAdmin 4.app" || true
 }
 
-pkg_post_install() {
+function pkg_post_install() {
     webi_path_add "$pkg_dst_bin"
 
     #echo "Initializing PostgreSQL with database at $POSTGRES_DATA_DIR/"
@@ -42,15 +45,15 @@ pkg_post_install() {
     chmod 0700 "$POSTGRES_DATA_DIR"
 
     if [ ! -f "$POSTGRES_DATA_DIR/postgresql.conf" ]; then
-      echo "postgres" > "$PWFILE"
-      "$pkg_src/bin/initdb" \
-        -D "$POSTGRES_DATA_DIR/" \
-        --username postgres --pwfile "$PWFILE" \
-        --auth-local=password --auth-host=password
+        echo "postgres" > "$PWFILE"
+        "$pkg_src/bin/initdb" \
+            -D "$POSTGRES_DATA_DIR/" \
+            --username postgres --pwfile "$PWFILE" \
+            --auth-local=password --auth-host=password
     fi
 }
 
-pkg_done_message() {
+function pkg_done_message() {
     # TODO show with serviceman
     echo "Installed 'postgres' and 'psql' at $pkg_dst"
     echo ""
@@ -63,4 +66,3 @@ pkg_done_message() {
     echo "    psql 'postgres://postgres:postgres@localhost:5432/postgres'"
     echo ""
 }
-