diff --git a/Makefile b/Makefile index fa7ff30..5442900 100644 --- a/Makefile +++ b/Makefile @@ -15,21 +15,22 @@ create_tarball: ## Create a tarball from local repository . .PHONY: install_from_respository -install_from_respository: create_tarball ## Install a local dotfiles CLI from this repository +install_from_respository: create_tarball ## Install a local git-deps-syncer from this repository @LOCAL_ARCHIVE_FILEPATH=$(CURDIR)/git-deps-syncer.tar.gz ./install.sh @rm -rf $(CURDIR)/git-deps-syncer.tar.gz .PHONY: uninstall -uninstall: ## Uninstall a local dotfiles CLI +uninstall: ## Uninstall a local git-deps-syncer @./uninstall.sh .PHONY: release_version_create -release_version_create: ## Create release tag in GitHub with version from resources/version.txt +release_version_create: create_tarball ## Create release tag in GitHub with version from resources/version.txt @sh -c "'$(CURDIR)/external/shell_scripts_lib/github/release.sh' \ 'action: create' \ 'version_file_path: ./resources/version.txt' \ - 'artifact_file_path: git-deps-syncer.sh' \ + 'artifact_file_path: git-deps-syncer.tar.gz' \ 'debug'" + @rm -rf $(CURDIR)/git-deps-syncer.tar.gz .PHONY: release_version_delete release_version_delete: ## Enter a tag to delete its attached release tag from GitHub @@ -48,16 +49,16 @@ calculate_sha_by_tag: ## Enter a tag to get its SHA hash @sh -c "'$(CURDIR)/external/shell_scripts_lib/github/sha_calculator.sh' \ 'sha_source: tag' \ 'repository_url: https://github.com/ZachiNachshon/git-deps-syncer' \ - 'asset_name: git-deps-syncer.sh'" + 'asset_name: git-deps-syncer.tar.gz'" # http://localhost:9001/git-deps-syncer/ .PHONY: serve_docs_site -serve_docs_site: ## Run a local site +serve_docs_site: ## Run a local docs site @cd docs-site && npm run docs-serve # http://192.168.x.xx:9001/ .PHONY: serve_docs_site_lan -serve_docs_site_lan: ## Run a local site (open for LAN) +serve_docs_site_lan: ## Run a local docs site (open for LAN) @cd docs-site && npm run docs-serve-lan .PHONY: test diff --git a/docs-site/site/content/docs/latest/about/support.md b/docs-site/site/content/docs/latest/about/support.md index 1122aa3..ae1badc 100644 --- a/docs-site/site/content/docs/latest/about/support.md +++ b/docs-site/site/content/docs/latest/about/support.md @@ -12,10 +12,57 @@ aliases: `git-deps-syncer` is an open source project that is currently self maintained in addition to my day job, you are welcome to show your appreciation by sending me cups of coffee using the the following link as it is a known fact that it is the fuel that drives software engineering ☕ + + + + + +
-Buy Me A Coffee + ## Get Involved -Get involved with `git-deps-syncer` development by [opening an issue]({{< param repo >}}/issues/new) or submitting a pull request. Read the [contribute](/docs/{{< param docs_version >}}/getting-started/contribute/) section for additional information. +Get involved with `git-deps-syncer` development by [opening an issue]({{< param repo >}}/issues/new?assignees=&labels=&template=bug_report.md&title=) or submitting a pull request. Read the [contribute](/docs/{{< param docs_version >}}/getting-started/contribute/) section for additional information. + + diff --git a/docs-site/site/content/docs/latest/configuration/dependencies.md b/docs-site/site/content/docs/latest/configuration/dependencies.md index dcd0d9d..f113591 100644 --- a/docs-site/site/content/docs/latest/configuration/dependencies.md +++ b/docs-site/site/content/docs/latest/configuration/dependencies.md @@ -46,8 +46,8 @@ This file contains the synced git dependencies information such as url / branch {{< /bs-table >}} {{< callout info >}} -By default the following files/folders are being excluded from the sync action of all git repositories:
-`.git` `.idea` `.git-deps` `external` `.gitignore` `.DS_Store` +By default the following files / folders are being excluded from the sync action of all git repositories:
+`.git`, `.idea`, `.git-deps`, `external`, `.gitignore`, `.DS_Store` {{< /callout >}} ### Dev dependencies diff --git a/docs-site/site/content/docs/latest/configuration/locations.md b/docs-site/site/content/docs/latest/configuration/locations.md index f3ec205..14cd28e 100644 --- a/docs-site/site/content/docs/latest/configuration/locations.md +++ b/docs-site/site/content/docs/latest/configuration/locations.md @@ -21,9 +21,5 @@ aliases: "/docs/latest/configuration/" {{< /bs-table >}} {{< callout info >}} -Type `git-deps-syncer locations` to get a list of commonly used paths. +Type `git-deps-syncer config` to get a list of commonly used paths. {{< /callout >}} - -
- -
\ No newline at end of file diff --git a/docs-site/site/content/docs/latest/getting-started/contribute.md b/docs-site/site/content/docs/latest/getting-started/contribute.md index a61d505..4c93dbb 100644 --- a/docs-site/site/content/docs/latest/getting-started/contribute.md +++ b/docs-site/site/content/docs/latest/getting-started/contribute.md @@ -38,10 +38,16 @@ The `makefile` within this repository contains numerous tasks used for project d {{< bs-table >}} | Task | Description | | --- | --- | -| `release` | Create release tag in GitHub with version from resources/version.txt | -| `delete-release` | Enter a tag to delete its attached release tag from GitHub | -| `commit-to-sha-hash` | Enter a commit to get its SHA hash | -| `tag-to-sha-hash` | Enter a tag to get its SHA hash | +| `install_from_respository` | Install a local git-deps-syncer from this repository | +| `uninstall` | Uninstall a local git-deps-syncer | +| `release_version_create` | Create release tag in GitHub with version from resources/version.txt | +| `release_version_delete` | Enter a tag to delete its attached release tag from GitHub | +| `calculate_sha_by_commit_hash` | Enter a commit to get its SHA hash | +| `calculate_sha_by_tag` | Enter a tag to get its SHA hash | +| `serve_docs_site` | Run a local docs site | +| `serve_docs_site_lan` | Run a local docs site (open for LAN) | +| `test` | Run tests suite | +| `fmt` | Format shell scripts using shfmt bash style (https://github.com/mvdan/sh) | {{< /bs-table >}} {{< callout warning >}} @@ -69,6 +75,10 @@ The `/docs-site/package.json` includes numerous tasks for developing the documen | `npm run docs-serve-lan` | Builds and runs the documentation locally, make it available on home network
(for testing views on mobile phones) | {{< /bs-table >}} +{{< callout warning >}} +When running the docs site with LAN access, make sure to update the IP address of the `docs-serve-lan` script on the `pacakge.json` file. +{{< /callout >}} + ## Local documentation Running our documentation locally requires the use of Hugo, which gets installed via the `hugo-bin` npm package. Hugo is a blazingly fast and quite extensible static site generator. Here’s how to get it started: @@ -76,10 +86,6 @@ Running our documentation locally requires the use of Hugo, which gets installed - Run through the [tooling setup](#tooling-setup) above to install all dependencies - Navigate to `/docs-site` directory and run `npm install` to install local dependencies listed in `package.json` - From `/docs-site` directory, run `npm run docs-serve` in the command line -- Open [http://localhost:9001/](http://localhost:9001/) in your browser +- Open [http://localhost:9001/git-deps-syncer](http://localhost:9001/git-deps-syncer) in your browser Learn more about using Hugo by reading its [documentation](https://gohugo.io/documentation/). - -## Troubleshooting - -In case you encounter problems with missing dependencies, run `make align-deps`. diff --git a/docs-site/site/content/docs/latest/getting-started/download.md b/docs-site/site/content/docs/latest/getting-started/download.md index 6b0d058..f94f9a8 100644 --- a/docs-site/site/content/docs/latest/getting-started/download.md +++ b/docs-site/site/content/docs/latest/getting-started/download.md @@ -34,46 +34,28 @@ Alternatively, tap into the formula to have brew search capabilities on that tap ## Released Version -1. Download and install `git-deps-syncer` executable (copy & paste into a terminal): +Download and install `git-deps-syncer` executable (copy & paste into a terminal): ```bash -bash <<'EOF' - -# Change Version accordingly -VERSION=0.1.0 - -# Create a temporary folder -download_temp_path=$(mktemp -d ${TMPDIR:-/tmp}/git-deps-syncer-temp.XXXXXX) -cwd=$(pwd) -cd ${download_temp_path} - -# Download & extract -echo -e "\nDownloading git-deps-syncer to temp directory...\n" -curl -SL "https://github.com/ZachiNachshon/git-deps-syncer/releases/download/v${VERSION}/git-deps-syncer.sh" - -# Create a dest directory and move the binary -echo -e "\nMoving executable to ~/.local/bin" -mkdir -p ${HOME}/.local/bin; mv git-deps-syncer.sh ${HOME}/.local/bin - -# Create a dest directory and move the binary -echo "Elevating exec permissions (might prompt for password)" -chmod +x ${HOME}/.local/bin/git-deps-syncer.sh - -# Add this line to your *rc file (zshrc, bashrc etc..) to make git-deps-syncer available on new sessions -echo "Exporting ~/.local/bin (make sure to have it available on PATH)" -export PATH="${PATH}:${HOME}/.local/bin" - -cd ${cwd} +curl -sfLS https://raw.githubusercontent.com/ZachiNachshon/git-deps-syncer/master/install.sh | bash - +``` -# Cleanup -if [[ ! -z ${download_temp_path} && -d ${download_temp_path} && ${download_temp_path} == *"git-deps-syncer-temp"* ]]; then - echo "Deleting temp directory" - rm -rf ${download_temp_path} -fi +Available installation flags: +{{< bs-table >}} +| Flag | Description | +| --- | --- | +| `VERSION` | Specify the released version to install | +| `DRY_RUN` | Run all commands in dry-run mode without file system changes | +{{< /bs-table >}} -echo -e "\nDone (type 'git-deps-syncer' for help)\n" +Example: -EOF +```bash +curl -sfLS \ + https://raw.githubusercontent.com/ZachiNachshon/git-deps-syncer/master/install.sh | \ + DRY_RUN=True \ + VERSION=0.6.0 \ + bash - ``` Alternatively, you can download a release directy from GitHub @@ -93,3 +75,35 @@ Clone `git-deps-syncer` repository into a directory of your choice: ```bash git clone https://github.com/ZachiNachshon/git-deps-syncer.git; cd git-deps-syncer ``` + +## Uninstall + +Instruction to uninstall `git-deps-syncer` based on installation method. + +**Homebrew** + +```bash +brew remove git-deps-syncer +``` + +**Released Version** + +```bash +curl -sfLS https://raw.githubusercontent.com/ZachiNachshon/git-deps-syncer/master/uninstall.sh | bash - +``` + +Available flags: +{{< bs-table >}} +| Flag | Description | +| --- | --- | +| `DRY_RUN` | Run all commands in dry-run mode without file system changes | +{{< /bs-table >}} + +Example: + +```bash +curl -sfLS \ + https://raw.githubusercontent.com/ZachiNachshon/git-deps-syncer/master/uninstall.sh | \ + DRY_RUN=True \ + bash - +``` \ No newline at end of file diff --git a/docs-site/site/content/docs/latest/getting-started/examples.md b/docs-site/site/content/docs/latest/getting-started/examples.md index c61205d..2a055a6 100644 --- a/docs-site/site/content/docs/latest/getting-started/examples.md +++ b/docs-site/site/content/docs/latest/getting-started/examples.md @@ -11,4 +11,5 @@ toc: true Repositories that are using `git-deps-syncer` for managing their git dependencies as 3rd parties: - anchor +- dotfiles-cli - git-deps-syncer (dogfooding) diff --git a/docs-site/site/content/docs/latest/usage/commands.md b/docs-site/site/content/docs/latest/usage/commands.md index 1f9299b..d4c246a 100644 --- a/docs-site/site/content/docs/latest/usage/commands.md +++ b/docs-site/site/content/docs/latest/usage/commands.md @@ -18,9 +18,8 @@ The `sync` / `sync-all` commands prompts for user approval before execution, to | `show` | Print the external git dependencies from the JSON config file | | `clear-all` | Remove all symlinks from external folder | | `clear [name]` | Remove a specific symlink from external folder | -| `locations` | Print locations used for config/repositories/symlinks/clone-path | +| `config` | Print config / paths / symlinks / clone-path | | `init` | Create an empty **.git-deps** folder with a **config.json** template file | -| `update` | Update client to latest version | | `version` | Print deps-syncer client versions | {{< /bs-table >}} @@ -31,18 +30,11 @@ Available flags to control commands execution. {{< bs-table >}} | Task | Description | | --- | --- | +| `--save-dev` | Sync **devDependencies** local symlinks as declared on **config.json** | +| `--open-github-pr` | Open a GitHub PR for git changes after running **sync-all** | +| `--dry-run` | Run all commands in dry-run mode **without file system changes** +| `-y` | Do not prompt for approval and accept everything | | `-h (--help)` | Show available actions and their description | | `-v (--verbose)` | Output debug logs for deps-syncer client commands executions | | `-s (--silent)` | Do not output logs for deps-syncer client commands executions | -| `-y` | Do not prompt for approval and accept everything | -| `--save-dev` | Sync **devDependencies** local symlinks as declared on **config.json** | -| `--open-github-pr` | Open a GitHub PR for git changes after running **sync-all** | {{< /bs-table >}} - -
- -Example of a user prompt message upon `sync-all`: - -
- -
\ No newline at end of file diff --git a/docs-site/site/layouts/partials/footer.html b/docs-site/site/layouts/partials/footer.html index bffb3f3..e361772 100644 --- a/docs-site/site/layouts/partials/footer.html +++ b/docs-site/site/layouts/partials/footer.html @@ -38,8 +38,8 @@
Projects
Community
diff --git a/docs-site/site/layouts/partials/home/masthead-followup.html b/docs-site/site/layouts/partials/home/masthead-followup.html index 44b5bd9..97e5cd4 100644 --- a/docs-site/site/layouts/partials/home/masthead-followup.html +++ b/docs-site/site/layouts/partials/home/masthead-followup.html @@ -35,7 +35,7 @@

Syncing a remote git dependency

{{ highlight (printf (`git-deps-syncer sync shell_scripts_lib`)) "sh" "" }}

- For addintional information check the configuration section. + For additional information check the configuration section.

@@ -49,7 +49,7 @@

Define git repository as a 3rd part git-deps-syncer uses a configuration file to keep track of existing git dependencies and manage their versioned sources.

- + Learn more about configuration options diff --git a/docs-site/site/static/docs/latest/assets/img/config-locations.svg b/docs-site/site/static/docs/latest/assets/img/config-locations.svg deleted file mode 100644 index 4cbb3c6..0000000 --- a/docs-site/site/static/docs/latest/assets/img/config-locations.svg +++ /dev/null @@ -1,17 +0,0 @@ -
\ No newline at end of file diff --git a/docs-site/site/static/docs/latest/assets/img/paypal-blue.svg b/docs-site/site/static/docs/latest/assets/img/paypal-blue.svg new file mode 100644 index 0000000..5d46bb4 --- /dev/null +++ b/docs-site/site/static/docs/latest/assets/img/paypal-blue.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs-site/site/static/docs/latest/assets/img/sync-all-prompt-message.svg b/docs-site/site/static/docs/latest/assets/img/sync-all-prompt-message.svg deleted file mode 100644 index 2df5eb7..0000000 --- a/docs-site/site/static/docs/latest/assets/img/sync-all-prompt-message.svg +++ /dev/null @@ -1,17 +0,0 @@ -
\ No newline at end of file diff --git a/formula.rb b/formula.rb new file mode 100644 index 0000000..22329ad --- /dev/null +++ b/formula.rb @@ -0,0 +1,27 @@ +# typed: false +# frozen_string_literal: true + +class GitDepsSyncer < Formula + desc "Sync git repositories as external source dependencies" + homepage "https://ZachiNachshon.github.io/git-deps-syncer/" + version "0.6.0" + url "https://github.com/ZachiNachshon/git-deps-syncer/releases/download/v0.6.0/git-deps-syncer.tar.gz" + sha256 "f4b5839ba9b048219951b2a3d97549bfb1cc238fe7a4905f6d40854a13403e5b" + license "MIT" + + depends_on "git" + depends_on "jq" + depends_on "gh" => :optional + + def install + # Add extracted files to the Homebrew install directory + libexec.install Dir["*"] + libexec.install Dir[".git-deps"] + # Add a relative symlink from Homebrew libexec to bin folder + bin.install_symlink libexec/"git-deps-syncer.sh" => "git-deps-syncer" + end + + test do + system "#{bin}/git-deps-syncer version" + end +end diff --git a/git-deps-syncer.sh b/git-deps-syncer.sh index e91fc58..61ac2d0 100755 --- a/git-deps-syncer.sh +++ b/git-deps-syncer.sh @@ -181,7 +181,7 @@ print_help_menu_and_exit() { echo -e "${COLOR_WHITE}FLAGS${COLOR_NONE}" echo -e " ${COLOR_LIGHT_CYAN}--save-dev${COLOR_NONE} Sync ${COLOR_GREEN}devDependencies${COLOR_NONE} local symlinks as declared on ${COLOR_GREEN}${GIT_DEPS_CONFIG_FILENAME}${COLOR_NONE}" echo -e " ${COLOR_LIGHT_CYAN}--open-github-pr${COLOR_NONE} Open a GitHub PR for git changes after running ${COLOR_GREEN}sync-all${COLOR_NONE}" - echo -e " ${COLOR_LIGHT_CYAN}--dry-run${COLOR_NONE} Run all commands in dry-run mode without file system changes" + echo -e " ${COLOR_LIGHT_CYAN}--dry-run${COLOR_NONE} Run all commands in dry-run mode ${COLOR_GREEN}without file system changes${COLOR_NONE}" echo -e " ${COLOR_LIGHT_CYAN}-y${COLOR_NONE} Do not prompt for approval and accept everything" echo -e " ${COLOR_LIGHT_CYAN}-h${COLOR_NONE} (--help) Show available actions and their description" echo -e " ${COLOR_LIGHT_CYAN}-v${COLOR_NONE} (--verbose) Output debug logs for deps-syncer client commands executions" @@ -338,10 +338,10 @@ parse_program_arguments() { verify_program_arguments() { if check_invalid_sync_dep_value; then - # Verify proper command args ordering: dotfiles sync --dry-run -v + # Verify proper command args ordering: git-deps-syncer sync --dry-run -v log_fatal "Missing/invalid argument value. usage: sync [dep-name]" elif check_invalid_clear_dep_value; then - # Verify proper command args ordering: dotfiles clear --dry-run -v + # Verify proper command args ordering: git-deps-syncer clear --dry-run -v log_fatal "Missing/invalid argument value. usage: clear [dep-name]" fi } diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..3ba5563 --- /dev/null +++ b/install.sh @@ -0,0 +1,246 @@ +#!/bin/bash + +# Installation commands: +# Basic: +# curl -sfLS https://raw.githubusercontent.com/ZachiNachshon/git-deps-syncer/master/install.sh | bash - +# Options: +# curl -sfLS https://raw.githubusercontent.com/ZachiNachshon/git-deps-syncer/master/install.sh | DRY_RUN=True VERSION=0.3.0 bash - +# DRY_RUN=True LOCAL_ARCHIVE_FILEPATH=/Users/zachin/codebase/github/git-deps-syncer/git-deps-syncer.tar.gz ./install.sh + +# When releasing a new version, the install script must be updated as well to latest +VERSION=${VERSION="0.6.0"} + +# Run the install script in dry-run mode, no file system changes +DRY_RUN=${DRY_RUN=""} + +# Use to install from a local git-deps-syncer archive instead of downloading from remote +LOCAL_ARCHIVE_FILEPATH=${LOCAL_ARCHIVE_FILEPATH=""} + +GIT_DEPS_SYNCER_REPOSITORY_URL="https://github.com/ZachiNachshon/git-deps-syncer" +GIT_DEPS_SYNCER_ARCHIVE_NAME="git-deps-syncer.tar.gz" +GIT_DEPS_SYNCER_INSTALL_PATH="${HOME}/.config/git-deps-syncer" +GIT_DEPS_SYNCER_EXECUTABLE_NAME=git-deps-syncer + +DARWIN_BIN_DIR="$HOME/.local/bin" +LINUX_BIN_DIR="$HOME/.local/bin" + +COLOR_RED='\033[0;31m' +COLOR_GREEN='\033[0;32m' +COLOR_YELLOW="\033[0;33m" +COLOR_NONE='\033[0m' + +is_dry_run() { + [[ -n ${DRY_RUN} ]] +} + +exit_on_error() { + exit_code=$1 + message=$2 + if [ $exit_code -ne 0 ]; then + # >&2 echo "\"${message}\" command failed with exit code ${exit_code}." + # >&2 echo "\"${message}\"" + exit $exit_code + fi +} + +new_line() { + echo -e "" >&2 +} + +_log_base() { + prefix=$1 + shift + echo -e "${prefix}$*" >&2 +} + +log_info() { + local info_level_txt="INFO" + if is_dry_run; then + info_level_txt+=" (Dry Run)" + fi + + _log_base "${COLOR_GREEN}${info_level_txt}${COLOR_NONE}: " "$@" +} + +log_warning() { + local warn_level_txt="WARNING" + if is_dry_run; then + warn_level_txt+=" (Dry Run)" + fi + + _log_base "${COLOR_YELLOW}${warn_level_txt}${COLOR_NONE}: " "$@" +} + +log_error() { + local error_level_txt="ERROR" + if is_dry_run; then + error_level_txt+=" (Dry Run)" + fi + _log_base "${COLOR_RED}${error_level_txt}${COLOR_NONE}: " "$@" +} + +log_fatal() { + local fatal_level_txt="ERROR" + if is_dry_run; then + fatal_level_txt+=" (Dry Run)" + fi + _log_base "${COLOR_RED}${fatal_level_txt}${COLOR_NONE}: " "$@" + message="$@" + exit_on_error 1 "${message}" +} + +cmd_run() { + local cmd_string=$1 + if ! is_dry_run; then + eval "${cmd_string}" + else + echo """ + ${cmd_string} + """ + fi +} + +is_install_from_local_archive() { + [[ -n "${LOCAL_ARCHIVE_FILEPATH}" ]] +} + +is_symlink() { + local abs_path=$1 + [[ -L "${abs_path}" ]] +} + +is_file_exist() { + local path=$1 + [[ -f "${path}" || $(is_symlink "${path}") ]] +} + +is_directory_exist() { + local path=$1 + [[ -d "${path}" ]] +} + +get_git_deps_syncer_archive_filepath() { + echo "${GIT_DEPS_SYNCER_INSTALL_PATH}/${GIT_DEPS_SYNCER_ARCHIVE_NAME}" +} + +read_os_type() { + if [[ "${OSTYPE}" == "linux"* ]]; then + echo "linux" + elif [[ "${OSTYPE}" == "darwin"* ]]; then + echo "darwin" + else + log_fatal "OS type is not supported. os: ${OSTYPE}" + fi +} + +calculate_git_deps_syncer_exec_symlink_path() { + local os_type=$(read_os_type) + if [[ "${os_type}" == "linux" ]]; then + # $HOME/.local/bin/git-deps-syncer + echo "${LINUX_BIN_DIR}/${GIT_DEPS_SYNCER_EXECUTABLE_NAME}" + elif [[ "${os_type}" == "darwin" ]]; then + # $HOME/.local/bin/git-deps-syncer + echo "${DARWIN_BIN_DIR}/${GIT_DEPS_SYNCER_EXECUTABLE_NAME}" + else + echo "" + fi +} + +adjust_global_executable_symlink() { + local git_deps_syncer_exec_bin_path=$1 + local git_deps_syncer_script_path="${GIT_DEPS_SYNCER_INSTALL_PATH}/git-deps-syncer.sh" + + log_info "Elevating executable permission. path: ${git_deps_syncer_script_path}" + cmd_run "chmod +x ${git_deps_syncer_script_path}" + + # macOS: ~/.local/bin/git-deps-syncer --> ~/.config/git-deps-syncer/git-deps-syncer.sh + # Linux: ~/.local/bin/git-deps-syncer --> ~/.config/git-deps-syncer/git-deps-syncer.sh + log_info "Linking executable to bin directory. symlink: ${git_deps_syncer_exec_bin_path}" + cmd_run "ln -sf ${git_deps_syncer_script_path} ${git_deps_syncer_exec_bin_path}" +} + +copy_local_archive_to_config_path() { + if ! is_file_exist "${LOCAL_ARCHIVE_FILEPATH}"; then + log_fatal "Local archive file does not exist. path: ${LOCAL_ARCHIVE_FILEPATH}" + fi + + clear_previous_installation + log_info "Installing git-deps-syncer CLI from local artifact. path: ${LOCAL_ARCHIVE_FILEPATH}" + log_info "Copying archive to config path" + local copy_path="${GIT_DEPS_SYNCER_INSTALL_PATH}" + cmd_run "rsync ${LOCAL_ARCHIVE_FILEPATH} ${copy_path}" +} + +download_latest_archive_to_config_path() { + log_info "Installing git-deps-syncer CLI from GitHub releases" + local filename="${GIT_DEPS_SYNCER_ARCHIVE_NAME}" + local download_path="${GIT_DEPS_SYNCER_INSTALL_PATH}" + local url="${GIT_DEPS_SYNCER_REPOSITORY_URL}/releases/download/v${VERSION}/${filename}" + + clear_previous_installation + + cwd=$(pwd) + if is_directory_exist "${download_path}"; then + cd "${download_path}" || exit + fi + log_info "Downloading git-deps-syncer from GitHub releases. version: ${VERSION}" + cmd_run "curl --fail -s ${url} -L -o ${filename}" + cd "${cwd}" || exit + + if ! is_dry_run && ! is_file_exist "${download_path}/${filename}"; then + log_fatal "Failed to download git-deps-syncer from GitHub releases. version: ${VERSION}" + fi +} + +extract_git_deps_syncer_archive() { + # ${HOME}/.config/git-deps-syncer/git-deps-syncer.tar.gz + local archive_file_path=$(get_git_deps_syncer_archive_filepath) + # ${HOME}/.config/git-deps-syncer + local archive_folder_path="${GIT_DEPS_SYNCER_INSTALL_PATH}" + + log_info "Extracting archive. destination: ${archive_folder_path}" + cmd_run "tar -xzf ${archive_file_path} -C ${archive_folder_path}" + + if is_file_exist "${archive_file_path}"; then + log_info "Removing archive file" + cmd_run "rm -rf ${archive_file_path}" + fi +} + +clear_previous_installation() { + log_info "Creating a fresh installation folder" + local git_deps_syncer_install_path="${GIT_DEPS_SYNCER_INSTALL_PATH}" + + if is_directory_exist "${git_deps_syncer_install_path}"; then + cmd_run "rm -rf ${git_deps_syncer_install_path}" + fi + cmd_run "mkdir -p ${git_deps_syncer_install_path}" +} + +main() { + local git_deps_syncer_exec_bin_path=$(calculate_git_deps_syncer_exec_symlink_path) + + if is_install_from_local_archive; then + copy_local_archive_to_config_path + else + download_latest_archive_to_config_path + fi + + extract_git_deps_syncer_archive + adjust_global_executable_symlink "${git_deps_syncer_exec_bin_path}" + + new_line + log_warning """Manual installation requires a specific PATH to become available on shell session: + + export PATH=\${HOME}/.local/bin:\${PATH} +""" + log_warning """To make the 'git-deps-syncer' command available, please choose one method: + + • Run the above command + • Add the above command to the RC file (zshrc/bashrc/bash_profile) and open a new shell session + """ + log_info "Type 'git-deps-syncer' to print the help menu" + new_line +} + +main "$@" diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..a812c79 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,170 @@ +#!/bin/bash + +# Installation commands: +# Basic: +# curl -sfL https://github.com/ZachiNachshon/git-deps-syncer/uninstall.sh | bash - +# Options: +# curl -sfL https://github.com/ZachiNachshon/git-deps-syncer/uninstall.sh | DRY_RUN=true - +# DRY_RUN=true ./uninstall.sh + +# Run the install script in dry-run mode, no file system changes +DRY_RUN=${DRY_RUN=""} + +GIT_DEPS_SYNCER_INSTALL_PATH="${HOME}/.config/git-deps-syncer" +GIT_DEPS_SYNCER_EXECUTABLE_NAME=git-deps-syncer + +DARWIN_BIN_DIR="$HOME/.local/bin" +LINUX_BIN_DIR="$HOME/.local/bin" + +COLOR_RED='\033[0;31m' +COLOR_GREEN='\033[0;32m' +COLOR_YELLOW="\033[0;33m" +COLOR_NONE='\033[0m' + +is_dry_run() { + [[ -n ${DRY_RUN} ]] +} + +exit_on_error() { + exit_code=$1 + message=$2 + if [ $exit_code -ne 0 ]; then + # >&2 echo "\"${message}\" command failed with exit code ${exit_code}." + # >&2 echo "\"${message}\"" + exit $exit_code + fi +} + +new_line() { + echo -e "" >&2 +} + +_log_base() { + prefix=$1 + shift + echo -e "${prefix}$*" >&2 +} + +log_info() { + local info_level_txt="INFO" + if is_dry_run; then + info_level_txt+=" (Dry Run)" + fi + + _log_base "${COLOR_GREEN}${info_level_txt}${COLOR_NONE}: " "$@" +} + +log_warning() { + local warn_level_txt="WARNING" + if is_dry_run; then + warn_level_txt+=" (Dry Run)" + fi + + _log_base "${COLOR_YELLOW}${warn_level_txt}${COLOR_NONE}: " "$@" +} + +log_error() { + local error_level_txt="ERROR" + if is_dry_run; then + error_level_txt+=" (Dry Run)" + fi + _log_base "${COLOR_RED}${error_level_txt}${COLOR_NONE}: " "$@" +} + +log_fatal() { + local fatal_level_txt="ERROR" + if is_dry_run; then + fatal_level_txt+=" (Dry Run)" + fi + _log_base "${COLOR_RED}${fatal_level_txt}${COLOR_NONE}: " "$@" + message="$@" + exit_on_error 1 "${message}" +} + +cmd_run() { + local cmd_string=$1 + if ! is_dry_run; then + eval "${cmd_string}" + else + echo """ + ${cmd_string} + """ + fi +} + +is_tool_exist() { + local name=$1 + [[ $(command -v "${name}") ]] +} + +is_install_from_local_archive() { + [[ -n "${LOCAL_ARCHIVE_FILEPATH}" ]] +} + +is_symlink() { + local abs_path=$1 + [[ -L "${abs_path}" ]] +} + +is_file_exist() { + local path=$1 + [[ -f "${path}" || $(is_symlink "${path}") ]] +} + +is_file_contain() { + local filepath=$1 + local text=$2 + grep -q -w "${text}" "${filepath}" +} + +is_directory_exist() { + local path=$1 + [[ -d "${path}" ]] +} + +read_os_type() { + if [[ "${OSTYPE}" == "linux"* ]]; then + echo "linux" + elif [[ "${OSTYPE}" == "darwin"* ]]; then + echo "darwin" + else + log_fatal "OS type is not supported. os: ${OSTYPE}" + fi +} + +calculate_git_deps_syncer_exec_symlink_path() { + local os_type=$(read_os_type) + if [[ "${os_type}" == "linux" ]]; then + # $HOME/.local/bin/git-deps-syncer + echo "${LINUX_BIN_DIR}/${GIT_DEPS_SYNCER_EXECUTABLE_NAME}" + elif [[ "${os_type}" == "darwin" ]]; then + # $HOME/.local/bin/git-deps-syncer + echo "${DARWIN_BIN_DIR}/${GIT_DEPS_SYNCER_EXECUTABLE_NAME}" + else + echo "" + fi +} + +clear_previous_installation() { + local git_deps_syncer_unpack_path="${GIT_DEPS_SYNCER_INSTALL_PATH}" + log_info "Removing installation folder. path: ${git_deps_syncer_unpack_path}" + + if is_directory_exist "${git_deps_syncer_unpack_path}"; then + cmd_run "rm -rf ${git_deps_syncer_unpack_path}" + fi +} + +main() { + local git_deps_syncer_exec_bin_path=$(calculate_git_deps_syncer_exec_symlink_path) + + log_info "Unlinking exec bin. path: ${git_deps_syncer_exec_bin_path}" + if is_file_exist "${git_deps_syncer_exec_bin_path}"; then + cmd_run "unlink ${git_deps_syncer_exec_bin_path}" + else + log_warning "Cannot unlink file, 'git-deps-syncer' is not symlinked. path: ${git_deps_syncer_exec_bin_path}" + fi + + clear_previous_installation +} + +main "$@"