From f68e91466e77fee3dc3fe46e8251f2c8ce2451f6 Mon Sep 17 00:00:00 2001
From: Pierre-Emmanuel Wulfman <pierre.emmanuel.wulfman@gmail.com>
Date: Thu, 24 Oct 2019 13:04:16 +0000
Subject: [PATCH] Make install script works on archlinux

---
 scripts/install_build_environment.sh   | 84 +++++++++++++++++---------
 scripts/install_native_dependencies.sh | 39 ++++++++----
 scripts/setup_switch.sh                |  2 +-
 3 files changed, 84 insertions(+), 41 deletions(-)

diff --git a/scripts/install_build_environment.sh b/scripts/install_build_environment.sh
index 958f855b1..0dd33f068 100755
--- a/scripts/install_build_environment.sh
+++ b/scripts/install_build_environment.sh
@@ -18,50 +18,76 @@ then
     fi
 fi
 
+echo "Installing dependencies.."
+if [ -n "`uname -a | grep -i arch`" ]
+then
+    sudo pacman -Sy --noconfirm \
+        make \
+        m4 \
+        gcc \
+        patch \
+        bubblewrap \
+        rsync \
+        curl 
+fi
+
+if [ -n "`uname -a | grep -i ubuntu`" ]
+then
 sudo apt-get install -y make \
      m4 \
      gcc \
      patch \
      bubblewrap \
      rsync \
-     curl \
+     curl 
+fi
     
 if [ -n "`uname -a | grep -i ubuntu`" ]
 then
+    echo "ubuntu"
     sudo add-apt-repository -y ppa:avsm/ppa
     sudo apt-get update
     sudo apt-get install opam
 else
-    # I'm going to assume here that we're on x86_64, 32-bit users should be basically
-    # extinct at this point right?
-    curl -L https://github.com/ocaml/opam/releases/download/2.0.4/opam-2.0.4-x86_64-linux \
-	 --output opam_temp_version_2_0_4.bin
-    if [ "`openssl sha256 -r opam_temp_version_2_0_4.bin`" = "373e34f92f282273d482537f8103caad0d17b6f2699ff504bed77f474cb0c951 *opam_temp_version_2_0_4.bin" ]
+    if [ -n "`uname -a | grep -i arch`" ]
     then
-	# Stay paranoid, in case other checks fail don't want to overrwrite
-	# user's opam on accident
-	chmod +x opam_temp_version_2_0_4.bin # Set execute so we can get version
-	if [ -e /usr/local/bin/opam ]
-	then
-	    opam_old_v=`/usr/local/bin/opam --version`
-	    opam_new_v=`opam_temp_version_2_0_4.bin --version`
-	    read -p "This will overrwrite the opam you have in /usr/local/bin (version $opam_old_v) with version $opam_new_v, do you actually want to do that? Type yes. (yes/n)" choice2
-	else
-	    choice2="yes"
-	fi
-	if [ $choice2 = "yes" ]
-	then
-	    sudo mv opam_temp_version_2_0_4.bin /usr/local/bin/opam
-	else
-	    rm opam_temp_version_2_0_4.bin
-	    exit
-	fi
+        echo "arch"
+        sudo pacman -Sy --noconfirm opam
     else
-	echo "opam file hash doesn't match what was recorded at time of signature verification!"
-	echo "(If you actually get this message, you should probably file an issue)"
-	echo "https://gitlab.com/ligolang/ligo/issues"
-	exit 1
-    fi	   	   
+        echo "unknown distro"
+        #I'm going to assume here that we're on x86_64, 32-bit users should be basically
+        #extinct at this point right?
+        curl -L https://github.com/ocaml/opam/releases/download/2.0.4/opam-2.0.4-x86_64-linux \
+            --output opam_temp_version_2_0_4.bin
+        if [ "`openssl sha256 -r opam_temp_version_2_0_4.bin`" = "373e34f92f282273d482537f8103caad0d17b6f2699ff504bed77f474cb0c951 *opam_temp_version_2_0_4.bin" ]
+        then
+            # Stay paranoid, in case other checks fail don't want to overrwrite
+            # user's opam on accident
+            chmod +x opam_temp_version_2_0_4.bin # Set execute so we can get version
+            if [ -e /usr/local/bin/opam ]
+            then
+                opam_old_v=`/usr/local/bin/opam --version`
+                opam_new_v=`opam_temp_version_2_0_4.bin --version`
+                read -p "This will overrwrite the opam you have in /usr/local/bin (version $opam_old_v) with version $opam_new_v, do you actually want to do that? Type yes. (yes/n)" choice2
+            else
+                choice2="yes"
+            fi
+            if [ $choice2 = "yes" ]
+            then
+                sudo mv opam_temp_version_2_0_4.bin /usr/local/bin/opam
+            else
+                rm opam_temp_version_2_0_4.bin
+                exit
+            fi
+        else
+            echo "opam file hash doesn't match what was recorded at time of signature verification!"
+            echo "(If you actually get this message, you should probably file an issue)"
+            echo "https://gitlab.com/ligolang/ligo/issues"
+            exit 1
+        fi	   	   
+    fi
 fi
 
 opam init -a --bare
+
+
diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh
index 6b06f51ad..46e354711 100755
--- a/scripts/install_native_dependencies.sh
+++ b/scripts/install_native_dependencies.sh
@@ -1,14 +1,31 @@
 #!/bin/sh
 set -e
+. /etc/os-release
 
-apt-get update -qq
-apt-get -y -qq install \
-    libev-dev \
-    perl \
-    pkg-config \
-    libgmp-dev \
-    libhidapi-dev \
-    m4 \
-    libcap-dev \
-    bubblewrap \
-    rsync
+if [ $ID = arch ]
+then
+    pacman -Sy
+    sudo pacman -S --noconfirm \
+        libevdev \
+        perl \
+        pkg-config \
+        gmp \
+        hidapi \
+        m4 \
+        libcap \
+        bubblewrap \
+        rsync
+
+else
+    apt-get update -qq
+    apt-get -y -qq install \
+        libev-dev \
+        perl \
+        pkg-config \
+        libgmp-dev \
+        libhidapi-dev \
+        m4 \
+        libcap-dev \
+        bubblewrap \
+        rsync
+fi
diff --git a/scripts/setup_switch.sh b/scripts/setup_switch.sh
index ed1e839b2..ee1179109 100755
--- a/scripts/setup_switch.sh
+++ b/scripts/setup_switch.sh
@@ -2,5 +2,5 @@
 set -e
 set -x
 
-printf '' | opam switch create . 4.07.1 # toto ocaml-base-compiler.4.06.1
+printf '' | opam switch create . ocaml-base-compiler.4.07.1 # toto ocaml-base-compiler.4.06.1
 eval $(opam config env)