From c47daad439ccf1ce64a7d2bb75e62a4550002c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Tue, 28 May 2019 20:54:37 +0200 Subject: [PATCH] Use sh, not bash --- docker/Dockerfile | 10 +-- scripts/build_docker_image.sh | 4 +- scripts/install_ligo_with_dependencies.sh | 7 +- scripts/install_opam.sh | 4 +- scripts/installer.sh | 8 +-- scripts/ligo.sh | 9 ++- scripts/setup_ligo_opam_repository.sh | 4 +- .../rewrite-local-opam-repository.sh | 68 +++++++++++++++---- 8 files changed, 80 insertions(+), 34 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index d4db809d4..dbc051aee 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,16 +16,16 @@ ADD . /ligo # the upcoming scripts WORKDIR /ligo -# Setup a custom opam repository where ligo is published -RUN bash scripts/setup_ligo_opam_repository.sh - # Install required native dependencies -RUN bash scripts/install_native_dependencies.sh +RUN sh scripts/install_native_dependencies.sh + +# Setup a custom opam repository where ligo is published +RUN sh scripts/setup_ligo_opam_repository.sh RUN opam update # Install ligo -RUN bash scripts/install_ligo_with_dependencies.sh +RUN sh scripts/install_ligo_with_dependencies.sh # Use the ligo binary as a default command ENTRYPOINT [ "/home/opam/.opam/4.06/bin/ligo" ] diff --git a/scripts/build_docker_image.sh b/scripts/build_docker_image.sh index 8a84fc2f6..273fa92c6 100755 --- a/scripts/build_docker_image.sh +++ b/scripts/build_docker_image.sh @@ -1,4 +1,4 @@ -#!/bin/bash -set -euET -o pipefail +#!/bin/sh +set -e docker build -t ligolang/ligo -f docker/Dockerfile . diff --git a/scripts/install_ligo_with_dependencies.sh b/scripts/install_ligo_with_dependencies.sh index 0fbbc166b..78e5d8b62 100755 --- a/scripts/install_ligo_with_dependencies.sh +++ b/scripts/install_ligo_with_dependencies.sh @@ -1,4 +1,5 @@ -#!/bin/bash -set -euET -o pipefail +#!/bin/sh +set -e -cd src && opam install . --yes +cd src +opam install . --yes diff --git a/scripts/install_opam.sh b/scripts/install_opam.sh index b65cee626..1a89f6a9b 100644 --- a/scripts/install_opam.sh +++ b/scripts/install_opam.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set -euET -o pipefail +#!/bin/sh +set -e # TODO: this has many different modes of failure (file temp.opam-2.0.1-x86_64-linux.download-in-progress already exists, /usr/local/bin/opam already exists and is a directory or hard link, …) # Try to improve these aspects. diff --git a/scripts/installer.sh b/scripts/installer.sh index 7da6107c8..3f38109a7 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set -euET -o pipefail +#!/bin/sh +set -e # You can run this installer like this: # curl https://gitlab.com/ligolang/ligo/blob/master/scripts/installer.sh | bash @@ -68,7 +68,7 @@ else && (umask 0600 > /dev/null 2>&1; UMASK=0600 touch /usr/local/bin/.temp.ligo.before-atomic-move) \ && chmod 0600 /usr/local/bin/.temp.ligo.before-atomic-move \ && cat > /usr/local/bin/.temp.ligo.before-atomic-move \ - ) || rm /usr/local/bin/.temp.ligo.before-atomic-move' + ) || (rm /usr/local/bin/.temp.ligo.before-atomic-move; exit 1)' # sudo become root (sudo) for the rest of the commands # ( subshell (to clean up temporary file if anything goes wrong) @@ -88,7 +88,7 @@ else && if test -d /usr/local/bin/ligo; then printf "/usr/local/bin/ligo already exists and is a directory, cancelling installation"'\\\\'n; rm /usr/local/bin/.temp.ligo.before-atomic-move; \ elif test -L /usr/local/bin/ligo; then printf "/usr/local/bin/ligo already exists and is a symbolic link, cancelling installation"'\\\\'n; rm /usr/local/bin/.temp.ligo.before-atomic-move; \ else mv -i /usr/local/bin/.temp.ligo.before-atomic-move /usr/local/bin/ligo; fi \ - ) || rm /usr/local/bin/.temp.ligo.before-atomic-move' + ) || (rm /usr/local/bin/.temp.ligo.before-atomic-move; exit 1)' # Installation finished, try running 'ligo' from your CLI printf \\n'Installation successful, try to run '\''ligo --help'\'' now.'\\n diff --git a/scripts/ligo.sh b/scripts/ligo.sh index c68ed3c34..9e4020b79 100755 --- a/scripts/ligo.sh +++ b/scripts/ligo.sh @@ -1,6 +1,9 @@ -#!/bin/bash -if true; then - set -euET -o pipefail +#!/bin/sh +set -e +if [ test "x$PWD" = "x" ]; then + echo "Cannot detect the current directory, the environment variable PWD is empty." + exit 1 +else docker run -it -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:latest "$@" fi # Do not remove the next line. It is used as an approximate witness that the download of this file was complete. This string should not appear anywhere else in the file. diff --git a/scripts/setup_ligo_opam_repository.sh b/scripts/setup_ligo_opam_repository.sh index 6051930d5..444aee6d5 100755 --- a/scripts/setup_ligo_opam_repository.sh +++ b/scripts/setup_ligo_opam_repository.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set -euET -o pipefail +#!/bin/sh +set -e vendors/opam-repository-tools/rewrite-local-opam-repository.sh opam repo add ligo-opam-repository ./vendors/ligo-opam-repository-local-generated diff --git a/vendors/opam-repository-tools/rewrite-local-opam-repository.sh b/vendors/opam-repository-tools/rewrite-local-opam-repository.sh index 01b196df9..f1ef980fc 100755 --- a/vendors/opam-repository-tools/rewrite-local-opam-repository.sh +++ b/vendors/opam-repository-tools/rewrite-local-opam-repository.sh @@ -1,13 +1,55 @@ -#!/bin/bash -set -euET -o pipefail -main(){ - root_dir="$(pwd | sed -e 's/\\/\\\\/' | sed -e 's/&/\\\&/' | sed -e 's/~/\\~/')" - rm -fr vendors/ligo-opam-repository-local-generated - mkdir vendors/ligo-opam-repository-local-generated - cp -a index.tar.gz packages repo urls.txt vendors/ligo-opam-repository-local-generated - cd vendors/ligo-opam-repository-local-generated - grep -r --null -l src: | grep -z 'opam$' | xargs -0 \ - sed -i -e 's~src: *"https://gitlab.com/ligolang/ligo/-/archive/master/ligo\.tar\.gz"~src: "file://'"$root_dir"'"~' - # TODO: run the update.sh script adequately to regenerate the index.tar.gz etc. in the local repo -} -if main; then exit 0; else exit $?; fi +#!/bin/sh + +# Stop on error. +set -e + +# Defensive checks. We're going to remove an entire folder so this script is somewhat dangerous. Better check in advance what can go wrong in the entire execution of the script. +if test -e index.tar.gz && test -e packages && test -e repo && test -e urls.txt; then + if test -d vendors/; then + if test -d "$PWD"; then + if command -v sed >/dev/null 2>&1 \ + && command -v rm >/dev/null 2>&1 \ + && command -v mkdir >/dev/null 2>&1 \ + && command -v cp >/dev/null 2>&1 \ + && command -v find >/dev/null 2>&1 \ + && command -v xargs >/dev/null 2>&1 \ + && command -v opam >/dev/null 2>&1; then + + # Escape the current directory, to be used as the replacement part of the sed regular expression + escaped_project_root="$(printf %s "$PWD" | sed -e 's/\\/\\\\/' | sed -e 's/&/\\\&/' | sed -e 's/~/\\~/')" + + # Recreate vendors/ligo-opam-repository-local-generated which contains a copy of the files related to the opam repository + rm -fr vendors/ligo-opam-repository-local-generated + mkdir vendors/ligo-opam-repository-local-generated + cp -pR index.tar.gz packages repo urls.txt vendors/ligo-opam-repository-local-generated + + # Rewrite the URLs in the opam repository to point to the project root + ( + cd vendors/ligo-opam-repository-local-generated + find . -type f -name opam -print0 | | xargs -0 sed -i -e 's~src: *"https://gitlab.com/ligolang/ligo/-/archive/master/ligo\.tar\.gz"~src: "file://'"$escaped_project_root"'"~' + ) + + # Regenerate the index.tar.gz etc. in the local repo + ( + cd vendors/ligo-opam-repository-local-generated + opam admin index + opam admin cache + ) + else + echo "One of the following commands is unavailable: sed rm mkdir cp find xargs opam." + exit 1 + fi + else + echo "Unable to access the current directory as indicated by PWD. Was the CWD of the current shell removed?" + exit 1 + fi + + else + echo "Cannot find the directory vendors/ in the current directory" + exit 1 + fi +else + echo "Cannot find some of the following files in the current directory" + echo "index.tar.gz packages repo urls.txt" + exit 1 +fi