diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index e268ed0..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,17 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:9f3b30d9f8e0d7040f729b82dcbc8f0dead820a133b3147ce355fc451f32d761" - name = "github.com/BurntSushi/toml" - packages = ["."] - pruneopts = "UT" - revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005" - version = "v0.3.1" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = ["github.com/BurntSushi/toml"] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 86dfce6..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,34 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - name = "github.com/BurntSushi/toml" - version = "0.3.1" - -[prune] - go-tests = true - unused-packages = true diff --git a/Makefile b/Makefile index 788fb1a..a8c9c48 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,6 @@ VERSION=$(shell cat VERSION) REVISION=$(shell [ -z "$(git status --untracked-files=no --porcelain)" ] && git rev-parse --short=12 HEAD || echo "no_revision") GOFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Revision=${REVISION}" -autoinstall: - scripts/install_helper.sh - sanitize: # # @@ -109,8 +106,6 @@ install: build submodules/bash-preexec/bash-preexec.sh scripts/shellrc.sh conf/c @[ -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 - # Reloading rc files ... - @. ~/.resh/shellrc # # # diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..f51249b --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,179 @@ +#!/usr/bin/env bash + +set -euo pipefail + +die() { + if [ $# -eq 1 ]; then + echo "$1" + elif [ $# -eq 0 ]; then + echo "ERROR: SomEtHiNg WeNt wRonG - ExItiNg!" + echo "THIS IS NOT SUPPOSED TO HAPPEN!" + fi + echo + echo "Please report any issues you encounter to: https://github.com/curusarn/resh/issues" + echo + echo "You can rerun this installation by executing: (you will skip downloading the files)" + echo "cd $PWD && scripts/install.sh" + exit 1 +} + +echo "Checking your system ..." + +# /usr/bin/zsh -> zsh +login_shell=$(echo "$SHELL" | rev | cut -d'/' -f1 | rev) + +if [ "$login_shell" != bash ] && [ "$login_shell" != zsh ]; then + die "ERROR: Unsupported/unknown login shell: $login_shell" +fi +echo "Login shell: $login_shell - OK" + + +# check like we are not running bash +bash_version=$(bash -c 'echo ${BASH_VERSION}') +bash_version_major=$(bash -c 'echo ${BASH_VERSINFO[0]}') +bash_version_minor=$(bash -c 'echo ${BASH_VERSINFO[1]}') +bash_too_old="" +if [ "$bash_version_major" -lt 3 ]; then + bash_too_old=true +elif [ "$bash_version_major" -eq 4 ] && [ "$bash_version_minor" -lt 3 ]; then + bash_too_old=true +fi + +if [ "$bash_too_old" = true ]; then + echo "Bash version: $bash_version - UNSUPPORTED!" + if [ "$login_shell" = bash ]; then + echo " > Your bash version is old." + echo " > Bash is also your login shell." + echo " > Updating to bash 4.3+ is strongly RECOMMENDED!" + else + echo " > Your bash version is old" + echo " > Bash is not your login shell so it should not be an issue." + echo " > Updating to bash 4.3+ is recommended." + fi +else + echo "Bash version: $bash_version - OK" +fi + + +if ! zsh --version &>/dev/null; then + echo "Zsh version: ? - not installed!" +else + zsh_version=$(zsh -c 'echo ${ZSH_VERSION}') + zsh_version_major=$(echo "$zsh_version" | cut -d'.' -f1) + if [ "$zsh_version_major" -lt 5 ]; then + echo "Zsh version: $zsh_version - UNSUPPORTED!" + if [ "$login_shell" = zsh ]; then + echo " > Your zsh version is old." + echo " > Zsh is also your login shell." + echo " > Updating to Zsh 5.0+ is strongly RECOMMENDED!" + else + echo " > Your zsh version is old" + echo " > Zsh is not your login shell so it should not be an issue." + echo " > Updating to zsh 5.0+ is recommended." + fi + else + echo "Zsh version: $zsh_version - OK" + fi +fi + +echo +echo "INSTALLATION" +exit 0 +# INSTALLATION + +mkdir_if_not_exists() { + if [ ! -d "$1" ]; then + mkdir "$1" + fi +} + +mkdir_if_not_exists ~/.resh +mkdir_if_not_exists ~/.resh/bin +mkdir_if_not_exists ~/.resh/bash_completion.d +mkdir_if_not_exists ~/.resh/zsh_completion.d +mkdir_if_not_exists ~/.config + +echo "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 scripts/shellrc.sh ~/.resh/shellrc +cp -f scripts/reshctl.sh scripts/widgets.sh scripts/hooks.sh scripts/util.sh ~/.resh/ + +echo "Generating completions for reshctl ..." +bin/resh-control completion bash > ~/.resh/bash_completion.d/_reshctl +bin/resh-control completion zsh > ~/.resh/zsh_completion.d/_reshctl + +echo "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 -q '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\ + echo -e '\n[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' >> ~/.bashrc +# Adding bash-preexec to .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 -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 + kill -SIGTERM "$(cat ~/.resh/resh.pid)" + rm ~/.resh/resh.pid +else + pkill -SIGTERM "resh-daemon" || true +fi +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 + +echo "\ + +########################################################## +# # +# SUCCESS - thank you for trying out this project! # +# # +########################################################## + + WARNING + It's recommended to RESTART ALL OPEN TERMINAL WINDOWS (or reload your rc files) + + HISTORY + Your resh history will be recorded to '~/.resh_history.json' + You can look at it using e.g. 'tail -f ~/.resh_history.json | jq' (you might need to install jq) + + SANITIZATION + History can be sanitized by running '... to be included' + This will create sanitized version of your history + + GRAPHS + You can get some graphs of your history by running '... to be included' + + ISSUES + Please report issues to: https://github.com/curusarn/resh/issues + + UNINSTALL + You can uninstall this at any time by running 'rm -rf ~/.resh/' + You won't lose any collected history by removing '~/.resh/' directory + + Please give me some contact info using this form: https://forms.gle/227SoyJ5c2iteKt98 + +" \ No newline at end of file diff --git a/scripts/install_helper.sh b/scripts/install_helper.sh deleted file mode 100755 index 2115c54..0000000 --- a/scripts/install_helper.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash - -set -o pipefail - -resh_git_dir=~/.resh_git - -if ! go version &>/dev/null; then - echo - echo "===========================================================================" - echo - 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`.' - echo - echo "===========================================================================" - echo - exit 1 - elif [ "$(uname)" = "Linux" ]; then - . /etc/os-release - if [ "${ID}" = "ubuntu" ]; then - echo 'You can probably use `sudo snap install go --classic` (gets latest golang - RECOMMENDED)' - echo 'OR `sudo apt install golang` (this might give you old golang)' - echo - echo "===========================================================================" - echo - exit 1 - elif [ "${ID_LIKE}" = "debian" ]; then - echo 'You can probably use `sudo apt install go`' - echo - echo "===========================================================================" - echo - exit 1 - fi - fi - echo "It's recomended to use your favourite package manager." - echo - echo "===========================================================================" - echo - exit 1 -fi - -go_version=$(go version | cut -d' ' -f3) -go_version_major=$(echo "${go_version:2}" | cut -d'.' -f1) -go_version_minor=$(echo "${go_version:2}" | cut -d'.' -f2) - -if [ "$go_version_major" -gt 1 ]; then - # good to go - future proof ;) - echo "Building & installing ..." - make install -elif [ "$go_version_major" -eq 1 ] && [ "$go_version_minor" -ge 11 ]; then - # good to go - we have go modules - echo "Building & installing ..." - make install -else - echo - 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 - if [ "${ID}" = "ubuntu" ]; then - echo 'You can probably use `sudo snap install go --classic` to get latest Golang.' - echo 'It may also be necessary to run `sudo apt remove golang; sudo apt autoremove`.' - fi - fi - 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 - if [ -z "${GOPATH+x}" ]; then - echo - echo "===========================================================================" - 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) \ - && mkdir "$GOPATH/bin" \ - && echo "Created tmp GOPATH: $GOPATH" - export GOPATH - take_care_of_gopath=1 - fi - - echo "GOPATH=$GOPATH" - PATH=$GOPATH/bin:$PATH - - if ! dep version &>/dev/null; then - echo - echo "===========================================================================" - 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 - if [ $? -eq 0 ]; then - echo "Installed dep." - else - echo "Installing dep failed - exiting!" - exit - fi - - fi - - project_path=$GOPATH/src/github.com/curusarn/resh - mkdir -p "$project_path" &>/dev/null - if [ "$project_path" != "$PWD" ]; then - if [ "$take_care_of_gopath" -eq 0 ]; then - echo - echo "===========================================================================" - 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" - cd "$project_path" - fi - - echo "Running \`dep ensure\` ..." - if ! dep ensure; then - echo "Unexpected ERROR while running \`dep ensure\`!" - exit 2 - fi - echo - echo "===========================================================================" - echo "Building & installing ..." - make install -fi diff --git a/scripts/rawinstall.sh b/scripts/rawinstall.sh index 76e93cb..d930531 100755 --- a/scripts/rawinstall.sh +++ b/scripts/rawinstall.sh @@ -2,26 +2,105 @@ set -euo pipefail -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 +echo "Please report any issues you encounter to: https://github.com/curusarn/resh/issues" +echo -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 +echo "Looking for the latest release ..." +json=$(curl --silent "https://api.github.com/repos/curusarn/resh/releases/latest") + +# not very robust but we don't want any dependencies to parse to JSON +tag=$(echo "$json" | grep '"tag_name":' | cut -d':' -f2 | tr -d ',' | cut -d'"' -f2) + +if [ ${#tag} -lt 2 ]; then + echo "ERROR: Couldn't determine the latest release! (extracted git tag is too short \"${tag}\")" + exit 1 +fi +if [ "${tag:0:1}" != v ]; then + echo "ERROR: Couldn't determine the latest release! (extracted git tag doesn't start with 'v' \"${tag}\")" + exit 1 +fi +version="${tag:1}" +# TODO: check if version is numeric + +echo +echo "Latest version: $version (git tag: $tag)" + +if [ "$(uname)" = "Darwin" ]; then + OS=darwin +elif [ "$(uname)" = "Linux" ]; then + OS=linux +else + OS=unknown fi -echo "Pulling the latest version of RESH ..." -cd "$resh_git_dir" -git checkout master -git pull -echo "Successfully pulled the latest version!" +if [ "$(uname -m)" = "x86_64" ]; then + ARCH=amd64 +elif [ "$(uname -m)" = "i386" ]; then + ARCH=386 +else + ARCH=unknown +fi + + +if [ "$OS" = unknown ] || [ "$ARCH" = unknown ]; then + echo "Couldn't detect your OS and architecture - exiting!" + echo "Expected Linux or macOS on x86_64 or i386" + exit 1 +fi + +dl_base="https://github.com/curusarn/resh/releases/download/${tag}" + +fname_checksums="resh_${version}_checksums.txt" +dl_checksums="$dl_base/$fname_checksums" + +fname_binaries="resh_${version}_${OS}_${ARCH}.tar.gz" +dl_binaries="$dl_base/$fname_binaries" -make autoinstall +tmpdir="$(mktemp -d /tmp/resh-rawinstall-XXX)" +echo "Changing to $tmpdir ..." +cd "$tmpdir" + +echo "Downloading files ..." + +curl_opt="--location --remote-name --progress-bar" + +echo "$dl_checksums" +# shellcheck disable=2086 +curl $curl_opt "$dl_checksums" + +echo "$dl_binaries" +# shellcheck disable=2086 +curl $curl_opt "$dl_binaries" + +# TODO: check if we downloaded anything +# Github serves you a "Not found" page so the curl doesn't error out + +echo +echo "Checking integrity ..." +if [ "$(sha256sum "$fname_binaries")" != "$(grep "$fname_binaries" "$fname_checksums")" ]; then + echo "Error integrity check failed - exiting!" + exit 1 +fi +echo "OK" + +echo +echo "Extracting downloaded files ..." + +tar -xzf "$fname_binaries" +tree +echo "DONE" +echo + +if ! scripts/install.sh; then + echo + echo "INSTALLATION FAILED!" + echo "I'm sorry for the inconvenience." + echo + echo "Please create an issue: https://github.com/curusarn/resh/issues" + echo + echo "You can rerun the installation by executing: (this will skip downloading the files)" + echo + echo "cd $PWD && scripts/install.sh" + exit 1 +fi \ No newline at end of file