From 4bb00305efb124464cad4ec402a6ed909f5d4d17 Mon Sep 17 00:00:00 2001 From: Mathis <84033116+mathis-marcotte@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:36:38 +0000 Subject: [PATCH] added conditions in start custom script (#669) * added conditions in start custom script * updated workflow * added missing space * reversed logic and added echo * fixed if statement * update echo message --- .github/workflows/build_push.yaml | 2 +- .../start-custom.sh | 57 ++++++++++++------- output/jupyterlab-cpu/start-custom.sh | 57 ++++++++++++------- output/jupyterlab-pytorch/start-custom.sh | 57 ++++++++++++------- output/jupyterlab-tensorflow/start-custom.sh | 57 ++++++++++++------- output/remote-desktop/start-custom.sh | 57 ++++++++++++------- output/rstudio/start-custom.sh | 57 ++++++++++++------- output/sas/start-custom.sh | 57 ++++++++++++------- resources/common/start-custom.sh | 57 ++++++++++++------- 9 files changed, 305 insertions(+), 153 deletions(-) diff --git a/.github/workflows/build_push.yaml b/.github/workflows/build_push.yaml index 283ffa31f..68a956b76 100644 --- a/.github/workflows/build_push.yaml +++ b/.github/workflows/build_push.yaml @@ -146,8 +146,8 @@ jobs: - name: Push image to local registry (default pushes all tags) run: make push/${{ matrix.notebook }} REPO=${{ env.LOCAL_REPO }} + # Image testing - - name: Set Up Python for Test Suite uses: actions/setup-python@v4 with: diff --git a/output/docker-stacks-datascience-notebook/start-custom.sh b/output/docker-stacks-datascience-notebook/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/docker-stacks-datascience-notebook/start-custom.sh +++ b/output/docker-stacks-datascience-notebook/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/output/jupyterlab-cpu/start-custom.sh b/output/jupyterlab-cpu/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/jupyterlab-cpu/start-custom.sh +++ b/output/jupyterlab-cpu/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/output/jupyterlab-pytorch/start-custom.sh b/output/jupyterlab-pytorch/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/jupyterlab-pytorch/start-custom.sh +++ b/output/jupyterlab-pytorch/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/output/jupyterlab-tensorflow/start-custom.sh b/output/jupyterlab-tensorflow/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/jupyterlab-tensorflow/start-custom.sh +++ b/output/jupyterlab-tensorflow/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/output/remote-desktop/start-custom.sh b/output/remote-desktop/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/remote-desktop/start-custom.sh +++ b/output/remote-desktop/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/output/rstudio/start-custom.sh b/output/rstudio/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/rstudio/start-custom.sh +++ b/output/rstudio/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/output/sas/start-custom.sh b/output/sas/start-custom.sh index 17a172273..a5d942296 100755 --- a/output/sas/start-custom.sh +++ b/output/sas/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL" diff --git a/resources/common/start-custom.sh b/resources/common/start-custom.sh index 17a172273..a5d942296 100755 --- a/resources/common/start-custom.sh +++ b/resources/common/start-custom.sh @@ -14,20 +14,33 @@ else fi # Step up Git Credential Manager -git config --global credential.credentialStore gpg -git config --global credential.helper manager -echo "export GPG_TTY=\$(tty)" >> ~/.bashrc - -# Clone example notebooks (with retries) -RETRIES_NO=5 -RETRY_DELAY=3 -for i in $(seq 1 $RETRIES_NO); do - test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break - echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" - #if it ran all the retries, exit - [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" - sleep ${RETRY_DELAY} -done +# only if it wasn't already setup +if grep -q "export GPG_TTY" ~/.bashrc; then + echo "Git Credential Manager already setup" +else + echo "Setting up Git Credential Manager" + + git config --global credential.credentialStore gpg + git config --global credential.helper manager + echo "export GPG_TTY=\$(tty)" >> ~/.bashrc +fi + +# Clone example notebooks (with retries because it sometimes initially fails) +if [[ ! -d ~/aaw-contrib-jupyter-notebooks ]]; then + echo "Cloning examples notebooks" + + RETRIES_NO=5 + RETRY_DELAY=3 + for i in $(seq 1 $RETRIES_NO); do + test -z "$GIT_EXAMPLE_NOTEBOOKS" || git clone "$GIT_EXAMPLE_NOTEBOOKS" && break + echo "Failed to cloned the example notebooks. Attempt $i of $RETRIES_NO" + #if it ran all the retries, exit + [[ $i -eq $RETRIES_NO ]] && echo "Failed to clone example notebooks after $RETRIES_NO retries" + sleep ${RETRY_DELAY} + done +else + echo "Example notebooks already cloned." +fi if [ ! -e /home/$NB_USER/.Rprofile ]; then cat /tmp/.Rprofile >> /home/$NB_USER/.Rprofile && rm -rf /tmp/.Rprofile @@ -51,11 +64,17 @@ fi # add rm wrapper: # https://jirab.statcan.ca/browse/ZPS-40 -mkdir -p /home/$NB_USER/.local/bin/ -git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git -mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm -rm -rf /home/$NB_USER/.local/bin/rm-git -chmod +x /home/$NB_USER/.local/bin/rm +if [ ! -f /home/$NB_USER/.local/bin/rm ]; then + echo "adding rm wrapper" + + mkdir -p /home/$NB_USER/.local/bin/ + git clone https://gitlab.k8s.cloud.statcan.ca/zone/build-scripts/snippets/415.git /home/$NB_USER/.local/bin/rm-git + mv /home/$NB_USER/.local/bin/rm-git/rm /home/$NB_USER/.local/bin/rm + rm -rf /home/$NB_USER/.local/bin/rm-git + chmod +x /home/$NB_USER/.local/bin/rm +else + echo "rm wrapper already exists" +fi export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL"