From b36f497f851a3da91a139e50ff4f73b29100fd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Fri, 7 Jun 2019 11:56:03 +0200 Subject: [PATCH 01/15] add odoc to Ci --- .gitlab-ci.yml | 37 +++++++++++++++++++++++++- scripts/install_native_dependencies.sh | 3 ++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f6e6b62ed..eb2dc2253 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,13 +12,48 @@ stages: stage: build_and_deploy_website image: node:8 before_script: + - scripts/install_native_dependencies.sh + # TODO: these things are moved to scripts in other branches. + - wget https://github.com/ocaml/opam/releases/download/2.0.1/opam-2.0.1-x86_64-linux -O opam-2.0.1-x86_64-linux + - cp opam-2.0.1-x86_64-linux /usr/local/bin/opam + - chmod +x /usr/local/bin/opam + - export PATH="/usr/local/bin${PATH:+:}${PATH:-}" + + # Initialise opam + - printf '' | opam init --bare + - eval $(opam config env) + + # Create switch + - printf '' | opam switch create toto ocaml-base-compiler.4.06.1 + - eval $(opam config env) + + # Show versions and current switch + - echo "$PATH" + - opam --version + - printf '' | ocaml + - opam switch + + # install deps for internal documentation + - opam install odoc + - vendors/opam-repository-tools/rewrite-local-opam-repository.sh + - opam repository add localrepo "file://$PWD/vendors/ligo-opam-repository-local-generated/" + - opam install -y --build-test --deps-only ./src/ + - dune build -p ligo + # TODO: also try instead from time to time: + #- (cd ./src/; dune build -p ligo) + + # build with odoc + - dune build @doc + - mv build/default/_doc/_html/ gitlab-pages/website/build/ligo/internal + + # npm - cd gitlab-pages/website - npm install script: - npm run version next - npm run build after_script: - - cp -r gitlab-pages/website/build/ligo public + - cp -r gitlab-pages/website/build/ligo public artifacts: paths: - public diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh index 04d4ce17f..0b1dafcd3 100755 --- a/scripts/install_native_dependencies.sh +++ b/scripts/install_native_dependencies.sh @@ -1,7 +1,8 @@ +apt-get update -qq apt-get -y install \ libev-dev \ perl \ pkg-config \ libgmp-dev \ libhidapi-dev \ - m4 \ No newline at end of file + m4 From ef243fb2033a419d24cf9b07c99708e005ba0947 Mon Sep 17 00:00:00 2001 From: Matej Sima Date: Fri, 7 Jun 2019 12:13:08 +0200 Subject: [PATCH 02/15] Add navbar link for odoc --- gitlab-pages/website/siteConfig.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitlab-pages/website/siteConfig.js b/gitlab-pages/website/siteConfig.js index ce411a67c..4f38d7ce9 100644 --- a/gitlab-pages/website/siteConfig.js +++ b/gitlab-pages/website/siteConfig.js @@ -101,7 +101,8 @@ const siteConfig = { {doc: 'api-cli-commands', label: 'CLI'}, {doc: 'tutorials/first-smart-contract', label: 'Tutorials'}, { blog: true, label: 'Blog' }, - {doc: 'contributors/origin', label: 'Contribute'}, + { href: "/odoc", label: "Api" }, + {doc: 'contributors/origin', label: 'Contribute'} ], // If you have users set above, you add it here: From 8d86f4ba5c8f372121058f84802f3a29dbe13dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Fri, 7 Jun 2019 12:24:16 +0200 Subject: [PATCH 03/15] temporarily build docs on feature/#3-add-odoc-to-website branch --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eb2dc2253..56df80ed6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -161,4 +161,4 @@ pages: only: - master - dev - + - feature/#3-add-odoc-to-website From 17b413faee2367520b949ca98f9d084c546dcebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 27 May 2019 22:00:09 +0200 Subject: [PATCH 04/15] Security aspects for shell scripts (well, an attempt at that) --- scripts/build_docker_image.sh | 5 +- scripts/install_ligo_with_dependencies.sh | 5 +- scripts/install_native_dependencies.sh | 5 +- scripts/installer.sh | 116 +++++++++++++++++----- scripts/ligo.sh | 7 +- scripts/setup_ligo_opam_repository.sh | 5 +- 6 files changed, 112 insertions(+), 31 deletions(-) diff --git a/scripts/build_docker_image.sh b/scripts/build_docker_image.sh index eb2bdb611..8a84fc2f6 100755 --- a/scripts/build_docker_image.sh +++ b/scripts/build_docker_image.sh @@ -1 +1,4 @@ -docker build -t ligolang/ligo -f docker/Dockerfile . \ No newline at end of file +#!/bin/bash +set -euET -o pipefail + +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 9ad969f3f..0fbbc166b 100755 --- a/scripts/install_ligo_with_dependencies.sh +++ b/scripts/install_ligo_with_dependencies.sh @@ -1 +1,4 @@ -cd src && opam install . --yes \ No newline at end of file +#!/bin/bash +set -euET -o pipefail + +cd src && opam install . --yes diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh index 04d4ce17f..0797f0300 100755 --- a/scripts/install_native_dependencies.sh +++ b/scripts/install_native_dependencies.sh @@ -1,7 +1,10 @@ +#!/bin/bash +set -euET -o pipefail + apt-get -y install \ libev-dev \ perl \ pkg-config \ libgmp-dev \ libhidapi-dev \ - m4 \ No newline at end of file + m4 diff --git a/scripts/installer.sh b/scripts/installer.sh index 7486f5a0f..7da6107c8 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -1,31 +1,95 @@ #!/bin/bash +set -euET -o pipefail + # You can run this installer like this: # curl https://gitlab.com/ligolang/ligo/blob/master/scripts/installer.sh | bash -# Make sure the marigold/ligo image is published at docker hub first -set -euET -o pipefail -version=$1 -printf "\nInstalling LIGO ($version)\n\n" +# Make sure the marigold/ligo image is published at docker hub first -if [ $version = "next" ] - then - # Install the ligo.sh from master - wget https://gitlab.com/ligolang/ligo/raw/dev/scripts/ligo.sh - else - # Install the ligo.sh from master - wget https://gitlab.com/ligolang/ligo/raw/master/scripts/ligo.sh +if test $# -ne 1; then + printf 'Usage: installer.sh VERSION'\\n + printf ' where VERSION can be "next" or a version number'\\n + exit 1 +else + version=$1 + printf \\n'Installing LIGO ($version)'\\n\\n + + if [ $version = "next" ] + then + # Install the ligo.sh from master + url=https://gitlab.com/ligolang/ligo/raw/dev/scripts/ligo.sh + else + # Install the ligo.sh from master + url=https://gitlab.com/ligolang/ligo/raw/master/scripts/ligo.sh + fi + + # Pull the docker image used by ligo.sh + docker pull "ligolang/ligo:$version" + + # Install ligo.sh + # Rationale behind this part of the script: + # * mv is one of the few commands which is atomic + # * therefore we will create a file with the desired contents, and if that works, atomically mv it. + # If something goes wrong it will attempt to remove the temporary file + # (if removing the temporary file fails it's not a big deal due to the fairly explicit file name, + # the fact that it is hidden, and its small size) + # * most utilities (e.g. touch) don't explicitly state that they support umask in their man page + # * therefore we try to set the mode for the temporary file with an umask + do a chmod just to be sure + # * this leaves open a race condition where: + # 0) umask isn't applied by touch (e.g. the file already exists) + # 1) for some reason touch creates an executable file (e.g. the file already exists) + # 2) a user grabs the file while it is executable, and triggers its execution (the process is created but execution of the script doesn't start yet) + # 3) chmod makes it non-executable + # 4) the file is partially written + # 5) the execution actually starts, and executes a prefix of the desired command, and that prefix is usable for adverse effects + # To mitigate this, we wrap the command in the script with + # if true; then the_command; fi + # That way, the shell will raise an error due to a missing "fi" if the script executed while it is partially written + # * This still leaves open the same race condition where a propper prefix of #!/bin/sh\nif can be used to adverse effect, but there's not much we can do about this. + # * after the file is completely written, we make it executable + # * we then check for the cases where `mv` misbehaves + # * we then atomically move it to (hopefully) its destination + # * the main risks here are if /usr/local/bin/ is writable by hostile users on the same machine (then there are bigger problems than what is our concern) + # or if root itself tries to create a race condition (then there are bigger problems than what is our concern) + + # It's hard to place comments inside a sequence of commands, so here are the comments for the following code: + # wget download to stdout + # | sudo become root (sudo) for the rest of the commands + # ( subshell (to clean up temporary file if anything goes wrong) + # remove temporary file in case it already exists + # && create temporary file with (hopefully) the right permissions + # && fix permisisons in case the creation didn't take umask into account + # && redirect the output of the wget download to the temporary file + # ) || clean up temporary file if any command in the previous block failed + + wget "$url" -O - \ + | sudo sh -c ' \ + ( \ + rm -f /usr/local/bin/.temp.ligo.before-atomic-move \ + && (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' + + # sudo become root (sudo) for the rest of the commands + # ( subshell (to clean up temporary file if anything goes wrong) + # && check that the download seems complete (one can't rely on sigpipe & failures to correctly stop the sudo session in case the download fails) + # && overwite LIGO version in the executable + # && now that the temporary file is complete, make it executable + # && if check for some corner cases: destination exists and is a directory + # elif check for some corner cases: destination exists and is symbolic link + # else atomically (hopefully) move temporary file to its destination + # ) || clean up temporary file if any command in the previous block failed + + sudo sh -c ' \ + ( \ + && grep "END OF DOWNLOADED FILE" /usr/local/bin/.temp.ligo.before-atomic-move \ + && sed -i '' "s/latest/$version/g" ligo.sh \ + && chmod 0755 /usr/local/bin/.temp.ligo.before-atomic-move \ + && 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' + + # Installation finished, try running 'ligo' from your CLI + printf \\n'Installation successful, try to run '\''ligo --help'\'' now.'\\n fi - - -# Overwrite LIGO version in the executable -sed -i '' "s/latest/$version/g" ligo.sh - -# Copy the exucutable to the appropriate directory -sudo cp ligo.sh /usr/local/bin/ligo -sudo chmod +x /usr/local/bin/ligo -rm ligo.sh - -# Pull the docker image used by ligo.sh -docker pull "ligolang/ligo:$version" - -# Installation finished, try running 'ligo' from your CLI -printf "\nInstallation successful, try to run 'ligo --help' now.\n" \ No newline at end of file diff --git a/scripts/ligo.sh b/scripts/ligo.sh index 8ccadad8e..c68ed3c34 100755 --- a/scripts/ligo.sh +++ b/scripts/ligo.sh @@ -1,2 +1,7 @@ #!/bin/bash -docker run -it -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:latest "$@" \ No newline at end of file +if true; then + set -euET -o pipefail + 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. +# END OF DOWNLOADED FILE diff --git a/scripts/setup_ligo_opam_repository.sh b/scripts/setup_ligo_opam_repository.sh index e07eac487..6051930d5 100755 --- a/scripts/setup_ligo_opam_repository.sh +++ b/scripts/setup_ligo_opam_repository.sh @@ -1,3 +1,6 @@ +#!/bin/bash +set -euET -o pipefail + vendors/opam-repository-tools/rewrite-local-opam-repository.sh opam repo add ligo-opam-repository ./vendors/ligo-opam-repository-local-generated -opam update ligo-opam-repository \ No newline at end of file +opam update ligo-opam-repository From fae35a1f42722cbb1b5fb1328051712569fa3282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 27 May 2019 22:05:05 +0200 Subject: [PATCH 05/15] sh does not recognize set -euET -o pipefail, only a subset of those options. Use bash for now. --- docker/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5cedfcd58..d4db809d4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -17,15 +17,15 @@ ADD . /ligo WORKDIR /ligo # Setup a custom opam repository where ligo is published -RUN sh scripts/setup_ligo_opam_repository.sh +RUN bash scripts/setup_ligo_opam_repository.sh # Install required native dependencies -RUN sh scripts/install_native_dependencies.sh +RUN bash scripts/install_native_dependencies.sh RUN opam update # Install ligo -RUN sh scripts/install_ligo_with_dependencies.sh +RUN bash scripts/install_ligo_with_dependencies.sh # Use the ligo binary as a default command ENTRYPOINT [ "/home/opam/.opam/4.06/bin/ligo" ] From 47409db7db6ca5438d16ceac0115a7822517acc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Tue, 28 May 2019 20:54:07 +0200 Subject: [PATCH 06/15] =?UTF-8?q?Started=20using=20the=20scripts/=E2=80=A6?= =?UTF-8?q?=20in=20.gitignore,=20started=20a=20Makefile=20for=20one-liners?= =?UTF-8?q?=20to=20be=20used=20by=20the=20devs,=20e.g.=20make=20build-deps?= =?UTF-8?q?,=20make,=20make=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 16 +++++----------- Makefile | 3 +++ scripts/install_native_dependencies.sh | 12 ++++++++---- scripts/install_opam.sh | 10 ++++++++++ 4 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 Makefile create mode 100644 scripts/install_opam.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f6e6b62ed..17372ad7a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,18 +37,13 @@ stages: # Install dependencies # rsync is needed by opam to sync a package installed from a local directory with the copy in ~/.opam - apt-get update -qq - - apt-get -y -qq install rsync libhidapi-dev libcap-dev libev-dev bubblewrap - - wget https://github.com/ocaml/opam/releases/download/2.0.1/opam-2.0.1-x86_64-linux -O opam-2.0.1-x86_64-linux - - cp opam-2.0.1-x86_64-linux /usr/local/bin/opam - - chmod +x /usr/local/bin/opam + - scripts/install_native_dependencies.sh + - scripts/install_opam.sh - export PATH="/usr/local/bin${PATH:+:}${PATH:-}" - # Initialise opam + # Initialise opam, create switch, load opam environment variables - printf '' | opam init --bare - - eval $(opam config env) - - # Create switch - - printf '' | opam switch create toto ocaml-base-compiler.4.06.1 + - printf '' | opam switch create ligo-switch ocaml-base-compiler.4.06.1 - eval $(opam config env) # Show versions and current switch @@ -61,8 +56,7 @@ local-dune-job: <<: *before_script stage: test script: - - vendors/opam-repository-tools/rewrite-local-opam-repository.sh - - opam repository add localrepo "file://$PWD/vendors/ligo-opam-repository-local-generated/" + - scripts/setup_ligo_opam_repository.sh - opam install -y --build-test --deps-only ./src/ - dune build -p ligo # TODO: also try instead from time to time: diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..f70b9412a --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +build-deps: + scripts/install_native_dependencies.sh + scripts/install_opam.sh diff --git a/scripts/install_native_dependencies.sh b/scripts/install_native_dependencies.sh index 0797f0300..6b06f51ad 100755 --- a/scripts/install_native_dependencies.sh +++ b/scripts/install_native_dependencies.sh @@ -1,10 +1,14 @@ -#!/bin/bash -set -euET -o pipefail +#!/bin/sh +set -e -apt-get -y install \ +apt-get update -qq +apt-get -y -qq install \ libev-dev \ perl \ pkg-config \ libgmp-dev \ libhidapi-dev \ - m4 + m4 \ + libcap-dev \ + bubblewrap \ + rsync diff --git a/scripts/install_opam.sh b/scripts/install_opam.sh new file mode 100644 index 000000000..b65cee626 --- /dev/null +++ b/scripts/install_opam.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euET -o pipefail + +# 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. + +wget https://github.com/ocaml/opam/releases/download/2.0.1/opam-2.0.1-x86_64-linux -O temp.opam-2.0.1-x86_64-linux.download-in-progress +cp -i temp.opam-2.0.1-x86_64-linux.download-in-progress /usr/local/bin/opam +chmod +x /usr/local/bin/opam +rm temp.opam-2.0.1-x86_64-linux.download-in-progress 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 07/15] 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 From e6994cd2d9a99ef4f15ca78ee1387ef333878bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Sat, 1 Jun 2019 14:41:17 +0200 Subject: [PATCH 08/15] typo --- vendors/opam-repository-tools/rewrite-local-opam-repository.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendors/opam-repository-tools/rewrite-local-opam-repository.sh b/vendors/opam-repository-tools/rewrite-local-opam-repository.sh index f1ef980fc..8771aa7bd 100755 --- a/vendors/opam-repository-tools/rewrite-local-opam-repository.sh +++ b/vendors/opam-repository-tools/rewrite-local-opam-repository.sh @@ -26,7 +26,7 @@ if test -e index.tar.gz && test -e packages && test -e repo && test -e urls.txt; # 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"'"~' + 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 From 24f52a13a18d30279c29bc5fcf4a48b334a9e489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 5 Jun 2019 20:15:21 +0200 Subject: [PATCH 09/15] missing chmod --- scripts/install_opam.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/install_opam.sh diff --git a/scripts/install_opam.sh b/scripts/install_opam.sh old mode 100644 new mode 100755 From 8019b647a5dc763fc96eee2a5f4788c142e92a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 10 Jun 2019 19:00:49 +0200 Subject: [PATCH 10/15] Typos --- scripts/installer.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/installer.sh b/scripts/installer.sh index 3f38109a7..e772c19e2 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -7,11 +7,12 @@ set -e if test $# -ne 1; then printf 'Usage: installer.sh VERSION'\\n - printf ' where VERSION can be "next" or a version number'\\n + printf \\n + printf ' where VERSION can be "next" or a version number like 1.0.0'\\n exit 1 else version=$1 - printf \\n'Installing LIGO ($version)'\\n\\n + printf \\n'Installing LIGO (%s)'\\n\\n "$version" if [ $version = "next" ] then @@ -62,6 +63,7 @@ else # ) || clean up temporary file if any command in the previous block failed wget "$url" -O - \ + | sed -e "s/latest/$version/g" \ | sudo sh -c ' \ ( \ rm -f /usr/local/bin/.temp.ligo.before-atomic-move \ @@ -82,8 +84,7 @@ else sudo sh -c ' \ ( \ - && grep "END OF DOWNLOADED FILE" /usr/local/bin/.temp.ligo.before-atomic-move \ - && sed -i '' "s/latest/$version/g" ligo.sh \ + grep "END OF DOWNLOADED FILE" /usr/local/bin/.temp.ligo.before-atomic-move \ && chmod 0755 /usr/local/bin/.temp.ligo.before-atomic-move \ && 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; \ From 938fec3e46736e1c4d43a40a119080b017034e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 10 Jun 2019 19:02:49 +0200 Subject: [PATCH 11/15] Use "next" instead of "latest" --- scripts/installer.sh | 2 +- scripts/ligo.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/installer.sh b/scripts/installer.sh index e772c19e2..c8623c6a7 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -63,7 +63,7 @@ else # ) || clean up temporary file if any command in the previous block failed wget "$url" -O - \ - | sed -e "s/latest/$version/g" \ + | sed -e "s/next/$version/g" \ | sudo sh -c ' \ ( \ rm -f /usr/local/bin/.temp.ligo.before-atomic-move \ diff --git a/scripts/ligo.sh b/scripts/ligo.sh index 9e4020b79..d0f9725d1 100755 --- a/scripts/ligo.sh +++ b/scripts/ligo.sh @@ -4,7 +4,7 @@ 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 "$@" + docker run -it -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:next "$@" 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. # END OF DOWNLOADED FILE From b0408fdcd9b2bbfaf5ab2bf232f735c287e71b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 10 Jun 2019 23:09:34 +0200 Subject: [PATCH 12/15] move internal documentation at the end, otherwise npm deletes it it seems. --- .gitlab-ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5aebb11e..3f27b4c86 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,7 +34,7 @@ stages: - opam switch # install deps for internal documentation - - opam install odoc + - opam install -y odoc - vendors/opam-repository-tools/rewrite-local-opam-repository.sh - opam repository add localrepo "file://$PWD/vendors/ligo-opam-repository-local-generated/" - opam install -y --build-test --deps-only ./src/ @@ -44,7 +44,6 @@ stages: # build with odoc - dune build @doc - - mv build/default/_doc/_html/ gitlab-pages/website/build/ligo/internal # npm - cd gitlab-pages/website @@ -52,6 +51,10 @@ stages: script: - npm run version next - npm run build + # move internal odoc documentation to the website folder + - mkdir -p gitlab-pages/website/build/ligo/ + - mv _build/default/_doc/_html/ gitlab-pages/website/build/ligo/internal + - ls gitlab-pages/website/build/ligo/ # for debug after_script: - cp -r gitlab-pages/website/build/ligo public artifacts: From 044e2fac7f6bc4e36fa8e25ba609ca303feba0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 12 Jun 2019 10:26:58 +0200 Subject: [PATCH 13/15] Move odoc to the right folder --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3f27b4c86..eae2fdd13 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -53,7 +53,7 @@ stages: - npm run build # move internal odoc documentation to the website folder - mkdir -p gitlab-pages/website/build/ligo/ - - mv _build/default/_doc/_html/ gitlab-pages/website/build/ligo/internal + - mv _build/default/_doc/_html/ gitlab-pages/website/build/ligo/odoc - ls gitlab-pages/website/build/ligo/ # for debug after_script: - cp -r gitlab-pages/website/build/ligo public From 461b0ff3318e93a87828d8adaa510f647dd27c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 12 Jun 2019 11:09:21 +0200 Subject: [PATCH 14/15] cd folder --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eae2fdd13..a286a0a9c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -53,7 +53,7 @@ stages: - npm run build # move internal odoc documentation to the website folder - mkdir -p gitlab-pages/website/build/ligo/ - - mv _build/default/_doc/_html/ gitlab-pages/website/build/ligo/odoc + - mv ../../_build/default/_doc/_html/ gitlab-pages/website/build/ligo/odoc - ls gitlab-pages/website/build/ligo/ # for debug after_script: - cp -r gitlab-pages/website/build/ligo public From 134f30888952b2fcf87dcd48896f2c09ffe7d645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Thu, 13 Jun 2019 12:01:36 +0200 Subject: [PATCH 15/15] odoc link in footer, not sidebar, for now --- gitlab-pages/website/core/Footer.js | 3 +++ gitlab-pages/website/siteConfig.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gitlab-pages/website/core/Footer.js b/gitlab-pages/website/core/Footer.js index c7c74a108..a65f2bc04 100644 --- a/gitlab-pages/website/core/Footer.js +++ b/gitlab-pages/website/core/Footer.js @@ -37,6 +37,9 @@ class Footer extends React.Component { Contribute + + Api Documentation +
Community
diff --git a/gitlab-pages/website/siteConfig.js b/gitlab-pages/website/siteConfig.js index 4f38d7ce9..c3760db2e 100644 --- a/gitlab-pages/website/siteConfig.js +++ b/gitlab-pages/website/siteConfig.js @@ -101,7 +101,7 @@ const siteConfig = { {doc: 'api-cli-commands', label: 'CLI'}, {doc: 'tutorials/first-smart-contract', label: 'Tutorials'}, { blog: true, label: 'Blog' }, - { href: "/odoc", label: "Api" }, + // TODO: { href: "/odoc", label: "Api" }, {doc: 'contributors/origin', label: 'Contribute'} ],