From 1c3f458315ea32ea70f48c3011b08a4cc0c6a030 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Tue, 1 Dec 2020 10:49:31 +0100
Subject: [PATCH] Update install script

---
 .gitignore |  1 +
 install.sh | 55 ++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/.gitignore b/.gitignore
index d26b33d..87f0ab8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 working
+stickerpicker/
diff --git a/install.sh b/install.sh
index dbd8cfb..6502f3d 100755
--- a/install.sh
+++ b/install.sh
@@ -1,20 +1,51 @@
 #!/bin/bash
 
+BASE_DIR="$PWD"
+
+die() {
+    error $*
+    cd $PWD # Go to initial directory
+    exit 1
+}
+
+error() {
+    echo -ne '\e[31m'$*'\e[39m\n'
+}
+
+warn() {
+    echo -ne '\e[33m'$*'\e[39m\n'
+}
+
+info() {
+    echo -ne '\e[32m'$*'\e[39m\n'
+}
+
 # Clone the stickerpicker into the html repository
-cd ~/html
-git clone https://github.com/maunium/stickerpicker.git
+cd ~/html >/dev/null 2>&1 \
+    || warn "Could not cd to '~/html', will clone to '$PWD/stickerpicker'"
+
+git clone https://github.com/maunium/stickerpicker.git stickerpicker \
+    || die "Failed to git clone the stickerpicker project." \
+           "If you already installed stickerpicker, remove it or use the 'stpkg' command"
 
 # Initialize the stickerpicker with the pack
 # scalar-privacy_pam.json
-cd stickerpicker
-mv packs/* web/packs
-cd web/packs
-touch index.json
-echo "{
-  \"homeserver_url\": \"https://matrix.iiens.net\",
-  \"packs\": [
-    \"scalar-privacy_pam.json\"
+cd stickerpicker        || die "Could not cd to '$PWD/stickerpicker'"
+mv packs/* web/packs    || die "Failed to cp packs to '$PWD/web/packs'"
+cd web/packs            || die "Failed to cd to '$PWD/web/packs'"
+
+cat > index.json << EOF
+{
+  "homeserver_url": "https://matrix.iiens.net",
+  "packs": [
+    "scalar-privacy_pam.json"
   ]
 }
-" >> index.json
-echo "Created index.json in ~/html/stickerpicker/web/packs"
+EOF
+
+[ ! -f index.json ] && die "Failed to create the $PWD/index.json file"
+
+info "Created index.json in '$PWD'"
+
+# Go to initial directory
+cd $BASE_DIR
-- 
GitLab