Browse Source

refactor: make bootstrap-osx.sh verbose and fail on error

Zetok Zalbavar 4 years ago
parent
commit
c9b1de0c27
1 changed files with 52 additions and 22 deletions
  1. 52 22
      bootstrap-osx.sh

+ 52 - 22
bootstrap-osx.sh

@@ -1,9 +1,9 @@
 #!/usr/bin/env bash
 
 # This script's purpose is to ease compiling qTox for users.
-# 
+#
 # NO AUTOMATED BUILDS SHOULD DEPEND ON IT.
-# 
+#
 # This script is and will be a subject to breaking changes, and at no time one
 # should expect it to work - it's something that you could try to use but
 # don't expect that it will work for sure.
@@ -14,26 +14,56 @@
 # With that being said, reporting that this script doesn't work would be nice.
 #
 # If you are contributing code to qTox that change its dependencies / the way
-# it's being build, please keep in mind that changing just bootstrap.sh 
+# it's being build, please keep in mind that changing just bootstrap.sh
 # *IS NOT* and will not be sufficient - you should update INSTALL.md first.
 
-echo Creating directories…
-mkdir -p libs/lib
-mkdir -p libs/include
-echo Copying libraries…
-cp /usr/local/lib/libsodium* libs/lib
-cp /usr/local/lib/libvpx* libs/lib
-cp /usr/local/lib/libopus* libs/lib
-cp /usr/local/lib/libav* libs/lib
-cp /usr/local/lib/libswscale* libs/lib
-cp /usr/local/lib/libqrencode* libs/lib
-cp /usr/local/lib/libsqlcipher* libs/lib
-echo Copying include files...
-cp -r /usr/local/include/vpx* libs/include
-cp -r /usr/local/include/sodium* libs/include
-cp -r /usr/local/include/qrencode* libs/include
-cp -r /usr/local/include/libav* libs/include
-cp -r /usr/local/include/libswscale* libs/include
-cp -r /usr/local/include/sqlcipher* libs/include
-echo Done.
+set -eu -o pipefail
+
+
+# copy libs to given destination
+copy_libs() {
+    local dest="$@"
+    local libs=(
+        /usr/local/lib/libsodium*
+        /usr/local/lib/libvpx*
+        /usr/local/lib/libopus*
+        /usr/local/lib/libav*
+        /usr/local/lib/libswscale*
+        /usr/local/lib/libqrencode*
+        /usr/local/lib/libsqlcipher*
+    )
+    echo Copying libraries…
+    for lib in "${libs[@]}"
+    do
+        cp -v "$lib" "$dest"
+    done
+}
+
+# copy includes to given destination
+copy_includes() {
+    local dest="$@"
+    local includes=(
+        /usr/local/include/vpx*
+        /usr/local/include/sodium*
+        /usr/local/include/qrencode*
+        /usr/local/include/libav*
+        /usr/local/include/libswscale*
+        /usr/local/include/sqlcipher*
+    )
+    echo Copying include files…
+    for include in "${includes[@]}"
+    do
+        cp -v -r "$include" "$dest"
+    done
+}
 
+main() {
+    local libs_dir="libs/lib"
+    local inc_dir="libs/include"
+    echo Creating directories…
+    mkdir -v -p "$libs_dir" "$inc_dir"
+    copy_libs "$libs_dir"
+    copy_includes "$inc_dir"
+    echo Done.
+}
+main