From e360f7db9c645d84a4f89051e230c40434aa1640 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Thu, 28 Mar 2019 16:54:34 +0000 Subject: [PATCH 1/9] testing? --- .travis.yml | 17 +++++++++++++++++ install.sh | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0dc4608 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: python +python: + - "2.7" + - "3.7" + +os: + - linux + - osx +sudo: required + + +install: + - chmod +x install.sh + +script: + - ./install.sh y "$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")" username uhppc00 y "$HOME" y "me@me.com" firstname lastname y $HOME y + - python ~/.jupyter/jupyter_notebook_config.py diff --git a/install.sh b/install.sh index b4f217c..9ccd55f 100644 --- a/install.sh +++ b/install.sh @@ -1,7 +1,23 @@ #!/bin/bash - set -e +install_conda="$1"; shift +version="$1"; shift +username="$1"; shift +pcname="$1"; shift +do_jupyter="$1"; shift +notebook_dir="$1"; shift +personal_git="$1"; shift +git_email="$1"; shift +firstname="$1"; shift +lastname="$1"; shift +code_review="$1"; shift +review_dir="$1"; shift +keys="$1"; shift + +email="$git_email" + + SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" cd "$SCRIPTPATH" @@ -15,7 +31,7 @@ touch "$HOME/.bashrc" touch "$HOME/.tcshrc" if [ ! -d "$HOME/.bash-git-prompt/" ]; then - git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1 + git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1 || echo already installed cp "$SCRIPTPATH/Single_line_Minimalist_notime.bgptheme" ~/.bash-git-prompt/ fi @@ -31,12 +47,12 @@ else # read install_conda # else echo -n "Install miniconda for personal use (you can choose where later)? [y/n]" - read -r install_conda - # fi + if [ -z ${install_conda+x} ]; then read -r install_conda; else echo "$install_conda"; fi + if [[ $install_conda = 'y' ]]; then echo -n "Which python should I use as your default? 2 or 3:" - read -r version + if [ -z ${version+x} ]; then read -r version; else echo "$version"; fi unameOut="$(uname -s)" case "${unameOut}" in Linux*) @@ -93,11 +109,11 @@ fi herts_string="source $SCRIPTPATH/herts.sh" echo -n "What is your work username?" -read -r username +if [ -z ${username+x} ]; then read -r username; else echo "$username"; fi echo "setenv UHUSERNAME $username" >> ~/.tcshrc echo "export UHUSERNAME=$username" >> ~/.bashrc echo -n "What is your work pc name (something like uhppc60)?" -read -r pcname +if [ -z ${pcname+x} ]; then read -r pcname; else echo "$pcname"; fi echo "setenv UHPCNAME $pcname" >> ~/.tcshrc echo "export UHPCNAME=$pcname" >> ~/.bashrc @@ -133,7 +149,7 @@ if jupyter --version; then hostname="$(echo "$HOSTNAME" || cat /proc/sys/kernel/hostname || echo '')" if [[ "$hostname" == *"uhppc"* ]]; then echo -n "You are on a university machine, shall I setup jupyter remote access?[y/n]" - read -r do_jupyter + if [ -z ${do_jupyter+x} ]; then read -r do_jupyter; else echo "$do_jupyter"; fi if [[ $do_jupyter = 'y' ]]; then mkdir "$HOME/certficates" || echo "certficates folder exists, skipping" mkdir "$HOME/certficates/jupyter" || echo "certficates folder exists, skipping" @@ -144,7 +160,7 @@ if jupyter --version; then echo "c.NotebookApp.open_browser = False" >> "$HOME/.jupyter/jupyter_notebook_config.py" echo "c.NotebookApp.port = 9999" >> "$HOME/.jupyter/jupyter_notebook_config.py" echo -n "In what absolute directory shall Jupyter start its notebooks?" - read -r notebook_dir + if [ -z ${notebook_dir+x} ]; then read -r notebook_dir; else echo "$notebook_dir"; fi echo "c.NotebookApp.notebook_dir = $notebook_dir" >> "$HOME/.jupyter/jupyter_notebook_config.py" chmod +x jupyter_autostart.sh echo "bash $SCRIPTPATH/jupyter_autostart.sh" >> "$HOME/.login" @@ -157,7 +173,7 @@ else fi echo -n "Shall I personalise git to your github username?[y/n] " -read -r personal_git +if [ -z ${personal_git+x} ]; then read -r personal_git; else echo "$personal_git"; fi if [[ $personal_git == 'y' ]]; then echo -n "Github email: " read -r git_email @@ -173,10 +189,10 @@ fi if [[ ! -f "$HOME/.ssh/id_rsa.pub" ]]; then echo -n "Shall I add a new ssh key for passwordless ssh?[y/n] " - read -r keys + if [ -z ${keys+x} ]; then read -r keys; else echo "$keys"; fi if [[ -n $keys ]]; then echo -n "What is your email? (this should be the same one you used with github) " - read -r email + if [ -z ${email+x} ]; then read -r email; else echo "$email"; fi ssh-keygen -t rsa -b 4096 -C "$email" -f "$HOME/.ssh/id_rsa.pub" eval "$(ssh-agent -s)" || echo agent already started ssh-add "$HOME/.ssh/id_rsa" @@ -190,13 +206,13 @@ if [[ ! -f "$HOME/.ssh/id_rsa.pub" ]]; then fi echo -n "Shall I install code-review.sh?[y/n] " -read -r code_review +if [ -z ${code_review+x} ]; then read -r code_review; else echo "$code_review"; fi if [[ $code_review == 'y' ]]; then git clone https://github.com/herts-astrostudents/code-review.sh "$HOME/code-review.sh" || echo "already installed" chmod +x "$HOME/code-review.sh/code-review.sh" "$HOME/code-review.sh/code-review.sh" install echo -n "Where shall I put the code-review repository where you will fill in tasks? " - read -r review_dir + if [ -z ${review_dir+x} ]; then read -r review_dir; else echo "$review_dir"; fi git clone https://github.com/herts-astrostudents/code-review "$review_dir/code-review" || echo "already installed" fi From 303f7fc0c5ec7ec795cd723605a28586355b3cb1 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Thu, 28 Mar 2019 17:03:58 +0000 Subject: [PATCH 2/9] test.sh --- .travis.yml | 4 ++-- README.md | 2 ++ test.sh | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test.sh diff --git a/.travis.yml b/.travis.yml index 0dc4608..f531853 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ sudo: required install: - chmod +x install.sh + - chmod +x test.sh script: - - ./install.sh y "$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")" username uhppc00 y "$HOME" y "me@me.com" firstname lastname y $HOME y - - python ~/.jupyter/jupyter_notebook_config.py + - ./test.sh \ No newline at end of file diff --git a/README.md b/README.md index 0e7b8c8..b860d5a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.com/herts-astrostudents/bash-scripts.svg?branch=master)](https://travis-ci.com/herts-astrostudents/bash-scripts) + # bash-scripts Useful scripts: install with: `git clone https://github.com/herts-astrostudents/bash-scripts.git ~/.bash-scripts && cd ~/.bash-scripts && bash ./install.sh` diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..95aaee5 --- /dev/null +++ b/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e + +./install.sh y "$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")" username uhppc00 y "$HOME" y "me@me.com" firstname lastname y $HOME y +python ~/.jupyter/jupyter_notebook_config.py +source ~/.bashrc From 871823dd60a367df12750577cd59f288f8566338 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 10:24:07 +0000 Subject: [PATCH 3/9] python version should be 2/3 --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 9ccd55f..79854d4 100644 --- a/install.sh +++ b/install.sh @@ -53,6 +53,7 @@ else if [[ $install_conda = 'y' ]]; then echo -n "Which python should I use as your default? 2 or 3:" if [ -z ${version+x} ]; then read -r version; else echo "$version"; fi + version="$(echo $version | head -c 1)" unameOut="$(uname -s)" case "${unameOut}" in Linux*) From 4c72176733d9d260016a1fbad58aa60ee1d0cd6e Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 10:31:25 +0000 Subject: [PATCH 4/9] auto install conda --- install.sh | 9 ++++++--- test.sh | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 79854d4..764b369 100644 --- a/install.sh +++ b/install.sh @@ -48,9 +48,8 @@ else # else echo -n "Install miniconda for personal use (you can choose where later)? [y/n]" if [ -z ${install_conda+x} ]; then read -r install_conda; else echo "$install_conda"; fi - - if [[ $install_conda = 'y' ]]; then + if [[ $install_conda = *"y"* ]]; then echo -n "Which python should I use as your default? 2 or 3:" if [ -z ${version+x} ]; then read -r version; else echo "$version"; fi version="$(echo $version | head -c 1)" @@ -80,7 +79,11 @@ else fi wget "https://repo.continuum.io/miniconda/$fname" chmod +x "$fname" - sh "$fname" + if [[ "$install_conda" = "yes-silent" ]]; then + bash "$fname" -b -p "$HOME/miniconda" + else + sh "$fname" + fi eval "$(register-python-argcomplete conda)" conda install jupyter conda_dir="$(dirname $(dirname $(which conda)))" diff --git a/test.sh b/test.sh index 95aaee5..c171fff 100644 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -./install.sh y "$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")" username uhppc00 y "$HOME" y "me@me.com" firstname lastname y $HOME y +./install.sh yes-silent "$(python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")" username uhppc00 y "$HOME" y "me@me.com" firstname lastname y $HOME y python ~/.jupyter/jupyter_notebook_config.py source ~/.bashrc From 56d959a991af49bbeb17b979b1ae093b14119109 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 11:10:23 +0000 Subject: [PATCH 5/9] source conda --- install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.sh b/install.sh index 764b369..86a0347 100644 --- a/install.sh +++ b/install.sh @@ -81,6 +81,8 @@ else chmod +x "$fname" if [[ "$install_conda" = "yes-silent" ]]; then bash "$fname" -b -p "$HOME/miniconda" + echo 'export PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bashrc + source ~/.bashrc else sh "$fname" fi From 1a0689200e97051bd8190ba3ce4c304e5679f9e3 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 11:16:00 +0000 Subject: [PATCH 6/9] echo path --- install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 86a0347..c1d94a2 100644 --- a/install.sh +++ b/install.sh @@ -80,8 +80,11 @@ else wget "https://repo.continuum.io/miniconda/$fname" chmod +x "$fname" if [[ "$install_conda" = "yes-silent" ]]; then - bash "$fname" -b -p "$HOME/miniconda" - echo 'export PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bashrc + prefix="$HOME/miniconda" + bash "$fname" -b -p $prefix + echo export PATH='$HOME'"$prefix/bin:"'$PATH' >> ~/.bashrc + ls -alt $prefix + echo $PATH source ~/.bashrc else sh "$fname" From 8fbca1062ebd8303b2941bdae28b6d8d933b9f9b Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 11:50:04 +0000 Subject: [PATCH 7/9] testing --- install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index c1d94a2..ff9fe3a 100644 --- a/install.sh +++ b/install.sh @@ -83,9 +83,9 @@ else prefix="$HOME/miniconda" bash "$fname" -b -p $prefix echo export PATH='$HOME'"$prefix/bin:"'$PATH' >> ~/.bashrc - ls -alt $prefix - echo $PATH source ~/.bashrc + ls -alt $prefix/bin + echo $PATH else sh "$fname" fi @@ -93,10 +93,10 @@ else conda install jupyter conda_dir="$(dirname $(dirname $(which conda)))" echo "source $conda_dir/etc/profile.d/conda.csh" >> ~/.tcshrc - echo "conda activate" >> ~/.bashrc - echo "conda activate" >> ~/.tcshrc echo "unsetenv PYTHONPATH" >> ~/.tcshrc echo "unset PYTHONPATH" >> ~/.bashrc + echo "conda activate" >> ~/.bashrc + echo "conda activate" >> ~/.tcshrc echo "Conda has been installed and the base environment activated by default" echo "You will need to source your tcshrc/bashrc files to make these changes now" echo From 57428a2d2c4bee1e2e00e11cef61b66c15d3ad05 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 11:54:26 +0000 Subject: [PATCH 8/9] reorder --- install.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index ff9fe3a..6f8d23f 100644 --- a/install.sh +++ b/install.sh @@ -83,20 +83,24 @@ else prefix="$HOME/miniconda" bash "$fname" -b -p $prefix echo export PATH='$HOME'"$prefix/bin:"'$PATH' >> ~/.bashrc - source ~/.bashrc - ls -alt $prefix/bin - echo $PATH else sh "$fname" fi - eval "$(register-python-argcomplete conda)" - conda install jupyter conda_dir="$(dirname $(dirname $(which conda)))" echo "source $conda_dir/etc/profile.d/conda.csh" >> ~/.tcshrc echo "unsetenv PYTHONPATH" >> ~/.tcshrc echo "unset PYTHONPATH" >> ~/.bashrc echo "conda activate" >> ~/.bashrc echo "conda activate" >> ~/.tcshrc + + source ~/.bashrc + ls -alt $prefix/bin + echo $PATH + pip install argcomplete + activate-global-python-argcomplete + eval "$(register-python-argcomplete conda)" + conda install jupyter + echo "Conda has been installed and the base environment activated by default" echo "You will need to source your tcshrc/bashrc files to make these changes now" echo From 34455e3c27fd89e63de6f4afab382f32e3e1d975 Mon Sep 17 00:00:00 2001 From: Shaun C Read Date: Fri, 29 Mar 2019 11:56:53 +0000 Subject: [PATCH 9/9] source again --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 6f8d23f..56f0eec 100644 --- a/install.sh +++ b/install.sh @@ -86,6 +86,7 @@ else else sh "$fname" fi + source ~/.bashrc conda_dir="$(dirname $(dirname $(which conda)))" echo "source $conda_dir/etc/profile.d/conda.csh" >> ~/.tcshrc echo "unsetenv PYTHONPATH" >> ~/.tcshrc