From a6cf02c5d73523b26e0e106ac7ca26307659fac5 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Sat, 14 Dec 2019 23:42:02 +0100 Subject: [PATCH] polish install scripts --- Makefile | 60 +++++++++++++++++++++------------------ scripts/install_helper.sh | 11 ++++++- scripts/rawinstall.sh | 26 ++++++++++++++--- 3 files changed, 65 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index cc67099..788fb1a 100644 --- a/Makefile +++ b/Makefile @@ -63,49 +63,54 @@ clean: install: build submodules/bash-preexec/bash-preexec.sh scripts/shellrc.sh conf/config.toml scripts/uuid.sh \ | $(HOME)/.resh $(HOME)/.resh/bin $(HOME)/.config $(HOME)/.resh/bash_completion.d $(HOME)/.resh/zsh_completion.d - # Copying files to resh directory ... - cp -f submodules/bash-preexec/bash-preexec.sh ~/.bash-preexec.sh - cp -f submodules/bash-zsh-compat-widgets/bindfunc.sh ~/.resh/bindfunc.sh + # Copying files ... + @cp -f submodules/bash-preexec/bash-preexec.sh ~/.bash-preexec.sh + @cp -f submodules/bash-zsh-compat-widgets/bindfunc.sh ~/.resh/bindfunc.sh - cp -f conf/config.toml ~/.config/resh.toml + @cp -f conf/config.toml ~/.config/resh.toml - cp -f scripts/shellrc.sh ~/.resh/shellrc - cp -f scripts/reshctl.sh scripts/widgets.sh scripts/hooks.sh scripts/util.sh ~/.resh/ + @cp -f scripts/shellrc.sh ~/.resh/shellrc + @cp -f scripts/reshctl.sh scripts/widgets.sh scripts/hooks.sh scripts/util.sh ~/.resh/ - bin/resh-control completion bash > ~/.resh/bash_completion.d/_reshctl - bin/resh-control completion zsh > ~/.resh/zsh_completion.d/_reshctl + # Generating completions for reshctl ... + @bin/resh-control completion bash > ~/.resh/bash_completion.d/_reshctl + @bin/resh-control completion zsh > ~/.resh/zsh_completion.d/_reshctl - cp -f scripts/uuid.sh ~/.resh/bin/resh-uuid - cp -f bin/* ~/.resh/bin/ - cp -f scripts/resh-evaluate-plot.py ~/.resh/bin/ - cp -fr data/sanitizer ~/.resh/sanitizer_data - # backward compatibility: We have a new location for resh history file - [ ! -f ~/.resh/history.json ] || mv ~/.resh/history.json ~/.resh_history.json + # Copying more files ... + @cp -f scripts/uuid.sh ~/.resh/bin/resh-uuid + @cp -f bin/* ~/.resh/bin/ + @cp -f scripts/resh-evaluate-plot.py ~/.resh/bin/ + @cp -fr data/sanitizer ~/.resh/sanitizer_data + + @# backward compatibility: We have a new location for resh history file + @[ ! -f ~/.resh/history.json ] || mv ~/.resh/history.json ~/.resh_history.json # Adding resh shellrc to .bashrc ... - grep '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\ + @grep -q '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\ echo -e '\n[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' >> ~/.bashrc # Adding bash-preexec to .bashrc ... - grep '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' ~/.bashrc ||\ + @grep -q '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' ~/.bashrc ||\ echo -e '\n[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc # Adding resh shellrc to .zshrc ... - grep '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\ + @grep -q '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\ echo -e '\n[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' >> ~/.zshrc @# Deleting zsh completion cache - for future use @# [ ! -e ~/.zcompdump ] || rm ~/.zcompdump + + @# Final touch + @touch ~/.resh_history.json + # Restarting resh daemon ... - -if [ -f ~/.resh/resh.pid ]; then\ + @-if [ -f ~/.resh/resh.pid ]; then\ kill -SIGTERM $$(cat ~/.resh/resh.pid);\ rm ~/.resh/resh.pid;\ fi - nohup resh-daemon &>/dev/null & disown - # Reloading rc files - . ~/.resh/shellrc - # Generating resh-uuid - [ -e "$(HOME)/.resh/resh-uuid" ] \ + @nohup resh-daemon &>/dev/null & disown + @# Generating resh-uuid ... + @[ -e "$(HOME)/.resh/resh-uuid" ] \ || cat /proc/sys/kernel/random/uuid > "$(HOME)/.resh/resh-uuid" 2>/dev/null \ || ./uuid.sh > "$(HOME)/.resh/resh-uuid" 2>/dev/null - # Final touch - touch ~/.resh_history.json + # Reloading rc files ... + @. ~/.resh/shellrc # # # @@ -117,15 +122,16 @@ install: build submodules/bash-preexec/bash-preexec.sh scripts/shellrc.sh conf/c # # # WHAT'S NEXT - # Please RESTART ALL OPEN TERMINAL WINDOWS (or reload your rc files) + # It's recommended to RESTART ALL OPEN TERMINAL WINDOWS (or reload your rc files) # Your resh history is located in `~/.resh_history.json` # You can look at it using e.g. `tail -f ~/.resh_history.json | jq` + # # # # ISSUES # If anything looks broken create an issue: https://github.com/curusarn/resh/issues # You can uninstall this at any time by running `rm -rf ~/.resh/` - # You won't lose any collected history by removing `~/.resh` directory + # You won't lose any collected history by removing `~/.resh/` directory # # # Please give me some contact info using this form: https://forms.gle/227SoyJ5c2iteKt98 diff --git a/scripts/install_helper.sh b/scripts/install_helper.sh index a0303fe..4ded1be 100755 --- a/scripts/install_helper.sh +++ b/scripts/install_helper.sh @@ -1,10 +1,13 @@ #!/usr/bin/env bash +resh_git_dir=~/.resh_git + if ! go version &>/dev/null; then echo echo "===========================================================================" echo - echo "Please INSTALL GOLANG and run this again" + echo "Please INSTALL GOLANG" + echo "after that rerun this script: \`cd $resh_git_dir && make autoinstall\`" echo if [ "$(uname)" = "Darwin" ]; then echo 'You can probably use `brew install go`.' @@ -53,6 +56,8 @@ else echo "===========================================================================" echo "Your Golang version is older than 1.11 - we can't use go modules for build!" echo "It's RECOMMENDED to update your Golang! (press Ctrl+C and update Golang manually)" + echo "after that rerun this script: \`cd $resh_git_dir && make autoinstall\`" + echo if [ "$(uname)" = "Linux" ]; then . /etc/os-release @@ -64,6 +69,7 @@ else echo echo "I will try to build the project using dep. (I will let you review each step.)" echo "Continue? (Any key to continue / Ctrl+C to cancel)" + # shellcheck disable=2162 disable=2034 read x take_care_of_gopath=0 @@ -73,6 +79,7 @@ else echo "GOPATH env variable is unset!" echo "I will take care of GOPATH. (I will create tmp GOPATH.)" echo "Continue? (Any key to continue / Ctrl+C to cancel)" + # shellcheck disable=2162 disable=2034 read x GOPATH=$(mktemp -d /tmp/gopath-XXX) \ @@ -91,6 +98,7 @@ else echo "It appears that you don't have dep installed!" echo "I will install dep. (I will install it from GitHub.)" echo "Continue? (Any key to continue / Ctrl+C to cancel)" + # shellcheck disable=2162 disable=2034 read x curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh @@ -106,6 +114,7 @@ else echo "It seems that current directory is not in the GOPATH!" echo "I will copy the project to appropriate GOPATH directory." echo "Continue? (Any key to continue / Ctrl+C to cancel)" + # shellcheck disable=2162 disable=2034 read x fi cp -rf ./* .git* "$project_path" && echo "Copied files to $project_path" diff --git a/scripts/rawinstall.sh b/scripts/rawinstall.sh index 358b481..76e93cb 100755 --- a/scripts/rawinstall.sh +++ b/scripts/rawinstall.sh @@ -2,8 +2,26 @@ set -euo pipefail -tmpdir="$(mktemp -d /tmp/resh-XXX)" -cd "$tmpdir" -git clone https://github.com/curusarn/resh.git -cd resh +while ! git --version &>/dev/null; do + echo "Please install git." + echo "Check again? (Any key to check again / Ctrl+C to exit)" + # shellcheck disable=2162 disable=2034 + read x + echo +done + +resh_git_dir=~/.resh_git +if [ ! -d "$resh_git_dir" ]; then + git clone https://github.com/curusarn/resh.git "$resh_git_dir" + echo "Cloned https://github.com/curusarn/resh.git to $resh_git_dir" + echo +fi + +echo "Pulling the latest version of RESH ..." +cd "$resh_git_dir" +git checkout master +git pull +echo "Successfully pulled the latest version!" + make autoinstall +