├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── automerge.yml │ ├── lint.yml │ └── pre-release.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .secrets.baseline ├── LICENSE ├── README.md ├── gvm ├── install.sh └── version /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @benjivesterby -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | labels: 8 | - "go" 9 | - "deps" 10 | groups: 11 | production-dependencies: 12 | dependency-type: "production" 13 | development-dependencies: 14 | dependency-type: "development" 15 | 16 | - package-ecosystem: "github-actions" 17 | directory: "/" 18 | schedule: 19 | interval: "daily" 20 | labels: 21 | - "github-actions" 22 | - "deps" 23 | groups: 24 | production-dependencies: 25 | dependency-type: "production" 26 | development-dependencies: 27 | dependency-type: "development" 28 | 29 | - package-ecosystem: "docker-compose" 30 | directory: "/" 31 | schedule: 32 | interval: "daily" 33 | labels: 34 | - "docker-compose" 35 | - "deps" 36 | groups: 37 | production-dependencies: 38 | dependency-type: "production" 39 | development-dependencies: 40 | dependency-type: "development" 41 | 42 | - package-ecosystem: "docker" 43 | directory: "/" 44 | schedule: 45 | interval: "daily" 46 | labels: 47 | - "docker" 48 | - "deps" 49 | groups: 50 | production-dependencies: 51 | dependency-type: "production" 52 | development-dependencies: 53 | dependency-type: "development" 54 | 55 | - package-ecosystem: "npm" 56 | directory: "/" 57 | schedule: 58 | interval: "daily" 59 | labels: 60 | - "npm" 61 | - "deps" 62 | groups: 63 | production-dependencies: 64 | dependency-type: "production" 65 | development-dependencies: 66 | dependency-type: "development" 67 | 68 | - package-ecosystem: "pip" 69 | directory: "/" 70 | schedule: 71 | interval: "daily" 72 | labels: 73 | - "python" 74 | - "deps" 75 | groups: 76 | production-dependencies: 77 | dependency-type: "production" 78 | development-dependencies: 79 | dependency-type: "development" 80 | 81 | - package-ecosystem: "cargo" 82 | directory: "/" 83 | schedule: 84 | interval: "daily" 85 | labels: 86 | - "rust" 87 | - "deps" 88 | groups: 89 | production-dependencies: 90 | dependency-type: "production" 91 | development-dependencies: 92 | dependency-type: "development" 93 | 94 | - package-ecosystem: "terraform" 95 | directory: "/" 96 | schedule: 97 | interval: "daily" 98 | labels: 99 | - "terraform" 100 | - "deps" 101 | groups: 102 | production-dependencies: 103 | dependency-type: "production" 104 | development-dependencies: 105 | dependency-type: "development" 106 | 107 | - package-ecosystem: "gitsubmodule" 108 | directory: "/" 109 | schedule: 110 | interval: "daily" 111 | labels: 112 | - "git" 113 | - "submodule" 114 | - "deps" 115 | groups: 116 | production-dependencies: 117 | dependency-type: "production" 118 | development-dependencies: 119 | dependency-type: "development" 120 | 121 | -------------------------------------------------------------------------------- /.github/workflows/automerge.yml: -------------------------------------------------------------------------------- 1 | name: automerge 2 | on: 3 | pull_request: 4 | types: 5 | - labeled 6 | jobs: 7 | automerge: 8 | runs-on: nixos 9 | permissions: 10 | contents: write 11 | pull-requests: write 12 | steps: 13 | - id: automerge 14 | name: automerge 15 | uses: "pascalgn/automerge-action@v0.16.4" 16 | env: 17 | GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 18 | MERGE_METHOD: squash 19 | MERGE_LABELS: automerge 20 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: 'ShellCheck lint' 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | shellcheck: 7 | name: Shellcheck 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Run ShellCheck 12 | uses: ludeeus/action-shellcheck@master -------------------------------------------------------------------------------- /.github/workflows/pre-release.yml: -------------------------------------------------------------------------------- 1 | name: "pre-release" 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" 7 | 8 | jobs: 9 | pre-release: 10 | name: "Pre Release" 11 | runs-on: "ubuntu-latest" 12 | 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v4 16 | - name: Create Sum 17 | run: | 18 | ./version dev 19 | cat ./gvm | shasum -a 256 > gvm.sum 20 | - name: Create Pre-Release 21 | uses: "marvinpinto/action-automatic-releases@latest" 22 | with: 23 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 24 | automatic_release_tag: "dev" 25 | prerelease: true 26 | title: "Development Build" 27 | files: | 28 | LICENSE 29 | gvm 30 | gvm.sum -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | .DS_Store 3 | ~ 4 | gvm.sum 5 | *.tmp -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: '^$' 2 | fail_fast: true 3 | repos: 4 | - repo: https://github.com/Yelp/detect-secrets 5 | rev: v1.5.0 6 | hooks: 7 | - id: detect-secrets 8 | name: Detect secrets 9 | language: python 10 | entry: detect-secrets-hook 11 | args: [ 12 | '--baseline', 13 | '.secrets.baseline', 14 | '--exclude-files', 15 | '(_test\.go$|/testdata/|gomod2nix.toml)', 16 | ] 17 | - repo: https://github.com/mrtazz/checkmake.git 18 | rev: 0.2.2 19 | hooks: 20 | - id: checkmake 21 | - repo: https://github.com/pre-commit/pre-commit-hooks 22 | rev: v5.0.0 23 | hooks: 24 | - id: check-json 25 | - id: check-merge-conflict 26 | - id: check-yaml 27 | - id: end-of-file-fixer 28 | - id: check-symlinks 29 | - repo: https://github.com/markdownlint/markdownlint 30 | rev: v0.12.0 31 | hooks: 32 | - id: markdownlint 33 | - repo: https://github.com/commitizen-tools/commitizen 34 | rev: v3.31.0 35 | hooks: 36 | - id: commitizen 37 | - id: commitizen-branch 38 | stages: [push] 39 | - repo: local 40 | hooks: 41 | - id: makefile 42 | name: Run Makefile Lint 43 | entry: make 44 | args: [pre-commit] 45 | language: system 46 | pass_filenames: false 47 | -------------------------------------------------------------------------------- /.secrets.baseline: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.2", 3 | "plugins_used": [ 4 | { 5 | "name": "ArtifactoryDetector" 6 | }, 7 | { 8 | "name": "AWSKeyDetector" 9 | }, 10 | { 11 | "name": "AzureStorageKeyDetector" 12 | }, 13 | { 14 | "name": "Base64HighEntropyString", 15 | "limit": 4.5 16 | }, 17 | { 18 | "name": "BasicAuthDetector" 19 | }, 20 | { 21 | "name": "CloudantDetector" 22 | }, 23 | { 24 | "name": "GitHubTokenDetector" 25 | }, 26 | { 27 | "name": "HexHighEntropyString", 28 | "limit": 3.0 29 | }, 30 | { 31 | "name": "IbmCloudIamDetector" 32 | }, 33 | { 34 | "name": "IbmCosHmacDetector" 35 | }, 36 | { 37 | "name": "JwtTokenDetector" 38 | }, 39 | { 40 | "name": "KeywordDetector", 41 | "keyword_exclude": "" 42 | }, 43 | { 44 | "name": "MailchimpDetector" 45 | }, 46 | { 47 | "name": "NpmDetector" 48 | }, 49 | { 50 | "name": "PrivateKeyDetector" 51 | }, 52 | { 53 | "name": "SendGridDetector" 54 | }, 55 | { 56 | "name": "SlackDetector" 57 | }, 58 | { 59 | "name": "SoftlayerDetector" 60 | }, 61 | { 62 | "name": "SquareOAuthDetector" 63 | }, 64 | { 65 | "name": "StripeDetector" 66 | }, 67 | { 68 | "name": "TwilioKeyDetector" 69 | } 70 | ], 71 | "filters_used": [ 72 | { 73 | "path": "detect_secrets.filters.allowlist.is_line_allowlisted" 74 | }, 75 | { 76 | "path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", 77 | "min_level": 2 78 | }, 79 | { 80 | "path": "detect_secrets.filters.heuristic.is_indirect_reference" 81 | }, 82 | { 83 | "path": "detect_secrets.filters.heuristic.is_lock_file" 84 | }, 85 | { 86 | "path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string" 87 | }, 88 | { 89 | "path": "detect_secrets.filters.heuristic.is_potential_uuid" 90 | }, 91 | { 92 | "path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign" 93 | }, 94 | { 95 | "path": "detect_secrets.filters.heuristic.is_sequential_string" 96 | }, 97 | { 98 | "path": "detect_secrets.filters.heuristic.is_swagger_file" 99 | }, 100 | { 101 | "path": "detect_secrets.filters.heuristic.is_templated_secret" 102 | } 103 | ], 104 | "results": {}, 105 | "generated_at": "2021-12-19T17:07:45Z" 106 | } 107 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gvm 2 | 3 | Go Version Manager 4 | 5 | [![ShellCheck lint](https://github.com/devnw/gvm/actions/workflows/lint.yml/badge.svg)](https://github.com/devnw/gvm/actions/workflows/lint.yml) 6 | [![License: Apache 2.0](https://img.shields.io/badge/license-Apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) 7 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) 8 | 9 | ## Install 10 | 11 | ```bash 12 | curl -o- https://raw.githubusercontent.com/devnw/gvm/main/install.sh | bash 13 | ``` 14 | ```bash 15 | wget -qO- https://raw.githubusercontent.com/devnw/gvm/main/install.sh | bash 16 | ``` 17 | 18 | ## Updating gvm 19 | 20 | `gvm` will automatically detect if there is a newer version available for the 21 | installed `gvm` tag and give the user the option to update (**NOTE** This does 22 | NOT work for semver tags). If the user chooses to update, the `gvm` command will 23 | be updated to the latest version and re-run the updated script instead. 24 | 25 | ## Usage 26 | 27 | `gvm [arguments]` 28 | 29 | ### Available Commands 30 | 31 | `` Install or Change Specific Go Version 32 | 33 | * `-s` Silent Mode (No Prompts) 34 | 35 | * `-r` Remove Go Version 36 | 37 | `ls` List Installed Go Versions 38 | 39 | `clean` Remove inactive Go Versions 40 | 41 | `-h` | `--help` | `help` Print this help text 42 | 43 | ## Installation Example 44 | 45 | To install a released version of `Go` use the following command. 46 | 47 | ```bash 48 | gvm 1.17.5 49 | ``` 50 | 51 | If this version of Go has been previously installed, the 52 | link will be updated activating that version. If the version 53 | is not installed however `gvm` will install it, then link it. 54 | 55 | To remove a version 56 | 57 | ```bash 58 | gvm 1.17.5 -r 59 | ``` 60 | 61 | ### Development Version 62 | 63 | `gvm` supports installing the current development version of `Go` 64 | 65 | To install the current development version of `Go` use the following command. 66 | 67 | ```bash 68 | gvm next 69 | ``` 70 | 71 | **NOTE:** If you have previously installed the development version of `Go` you 72 | **must** pass the `--update` flag if you want to build the latest development 73 | version, otherwise it will keep using the previously compiled development 74 | version. 75 | 76 | ## How it works 77 | 78 | `gvm` creates a directory at `$HOME/.gvm` and stores all of the Go versions in 79 | it. It then creates a symlink to the currently active version at `$HOME/.gvm/go` 80 | which is then added to the beginning of the PATH. 81 | 82 | ## Supported OSes and Architectures 83 | 84 | * Linux (ARM64 / AMD64) 85 | * Mac OS X (ARM64 / AMD64) 86 | * FreeBSD (ARM64 / AMD64) 87 | -------------------------------------------------------------------------------- /gvm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ############################################################################### 4 | # GENERATED VERSION! DO NOT CHANGE! # 5 | SCRIPTVERSION="local-dev" 6 | ############################################################################### 7 | 8 | # Static variable definintions 9 | wd=$(pwd) 10 | gvmroot="$HOME/.gvm" 11 | gvmbin="$gvmroot/go/bin" 12 | gvmexe="$gvmbin/go" 13 | srcd="$gvmroot/next" 14 | version="$1" 15 | versionroot="$gvmroot/$version" 16 | golanggit="https://go.googlesource.com/go" 17 | dlroot="https://go.dev/dl/" 18 | update=$2 19 | branch="master" 20 | remove=false 21 | 22 | # Persistent Configuration Values 23 | alwaysUpdate=false 24 | 25 | # Determine active symlink version 26 | active=$(readlink -f "$gvmroot"/go) 27 | active=${active%*/go} 28 | active=${active##*/} 29 | 30 | bold=$(tput bold) 31 | normal=$(tput sgr0) 32 | 33 | loadConfig() { 34 | cfg="$gvmroot/.config" 35 | 36 | if [[ -f "$cfg" ]] 37 | then 38 | # shellcheck disable=SC1090 39 | source "$cfg" 40 | fi 41 | } 42 | 43 | loadConfig 44 | 45 | # Print the help text for gvm 46 | help() { 47 | printf " 48 | Go Version Manager [${bold}%s${normal}] \n 49 | Usage:\n 50 | ${bold}gvm [arguments]${normal} 51 | 52 | The commands are: 53 | ${bold}${normal} Install or Change Specific Go Version 54 | ${bold}-s${normal} Silent Mode (No Prompts) 55 | ${bold}-r${normal} Remove Go Version 56 | 57 | ${bold}ls${normal} List Installed Go Versions 58 | 59 | ${bold}clean${normal} Remove inactive Go Versions 60 | 61 | ${bold}-h | --help | help${normal} Print this help text 62 | 63 | ${bold}Examples:${normal} 64 | To install or activate a released version 65 | ${bold}gvm 1.17.5${normal} 66 | 67 | To remove a version 68 | ${bold}gvm 1.17.5 -r${normal} 69 | 70 | ${bold}DEVELOPMENT VERSION:${normal} 71 | To install or activate the development version 72 | ${bold}gvm next${normal} 73 | 74 | To update and activate an existing development version 75 | ${bold}gvm next --update${normal}\n" "$SCRIPTVERSION" 76 | } 77 | 78 | installed() { 79 | echo "${bold}Installed Go Versions" 80 | echo "---------------------${normal}" 81 | 82 | for dir in "$gvmroot"/* 83 | do 84 | dir=${dir%*/} 85 | trimmed=${dir##*/} 86 | 87 | if [[ $trimmed != "go" ]] 88 | then 89 | printf "%s" "$trimmed" 90 | 91 | if [[ "$active" == "$trimmed" ]] 92 | then 93 | printf "%s*%s" "${bold}" "${normal}" 94 | fi 95 | 96 | printf "\n" 97 | fi 98 | done 99 | } 100 | 101 | clean() { 102 | for dir in "$gvmroot"/* 103 | do 104 | dir=${dir%*/} 105 | trimmed=${dir##*/} 106 | 107 | # Ignore the symlink dir 108 | if [[ $trimmed != "go" ]] 109 | then 110 | # Remove the non active versions 111 | if [[ "$active" != "$trimmed" ]] 112 | then 113 | rm -rf "$dir" 114 | fi 115 | fi 116 | done 117 | } 118 | 119 | for flag in "$@" 120 | do 121 | case $flag in 122 | -s) 123 | alwaysUpdate=true 124 | ;; 125 | help) 126 | help 127 | exit 0 128 | ;; 129 | --help) 130 | help 131 | exit 0 132 | ;; 133 | -h) 134 | help 135 | exit 0 136 | ;; 137 | ls) 138 | installed 139 | exit 0 140 | ;; 141 | -r) 142 | remove=true 143 | ;; 144 | clean) 145 | clean 146 | exit 0 147 | ;; 148 | *);; 149 | esac 150 | done 151 | 152 | 153 | if [[ $1 == "" ]] 154 | then 155 | echo "No command specified" 156 | help 157 | exit 1 158 | fi 159 | 160 | alwaysUpdateQ() { 161 | printf "Would you like to always update? " 162 | 163 | read -rp "[Yes: Y or y | No: Enter]? " yn 164 | if [[ "$yn" == "Y" || "$yn" == "y" ]] 165 | then 166 | # set the auto update variable to true 167 | grep "alwaysUpdate=true"&> /dev/null < "$gvmroot/.config" 168 | if [[ $? == 1 ]] 169 | then 170 | printf "alwaysUpdate=true\n" >> "$gvmroot/.config" 171 | fi 172 | fi 173 | } 174 | 175 | upgrade() { 176 | curl -sL "$GVMURL" > .gvm.tmp 177 | 178 | # shellcheck disable=SC2002 179 | 180 | # Gitbash/Windows certutil with explit sha256 can be used 181 | if [[ "$OSTYPE" == "msys"* ]] 182 | then 183 | DOWNLOADEDSUM=$(certutil -hashfile .gvm.tmp sha256 | tail -n2 | head -n1) 184 | else 185 | DOWNLOADEDSUM=$(cat .gvm.tmp | shasum -a 256) 186 | fi 187 | 188 | if [[ $DOWNLOADEDSUM != "$EXPECTEDSUM" ]] 189 | then 190 | printf "Checksum does not match new version of GVM [%s]\n" "$SCRIPTVERSION" 191 | printf "Expected: %s\n" "$EXPECTEDSUM" 192 | printf "Actual: %s\n" "$DOWNLOADEDSUM" 193 | exit 1 194 | fi 195 | 196 | if ! cat .gvm.tmp > "$0" 197 | then 198 | rm .gvm.tmp 199 | printf "Failed to move new version of GVM [%s]\n" "$SCRIPTVERSION" 200 | exit 1 201 | fi 202 | rm .gvm.tmp 203 | 204 | printf "GVM [%s] has been updated\n" "$SCRIPTVERSION" 205 | printf "%s\n" "$@" 206 | if ! exec $0 "$@" 207 | then 208 | printf "Failed to execute new version of GVM [%s]\n" "$SCRIPTVERSION" 209 | exit 1 210 | fi 211 | 212 | printf "Successful update and execution" 213 | exit 0 214 | } 215 | 216 | # fail accepts a string argument, prints it and exits with a non-zero exit code 217 | function fail() { 218 | printf "%s\n" "$1" 219 | exit 1 220 | } 221 | 222 | # Update checks the published version of this script based on the SCRIPTVERSION 223 | # variable. If the version is different, it will give the user the option to 224 | # update the script. If the user chooses to update, it will download the new 225 | # version and replace the old one. It will then re-run the script using the new 226 | # version. 227 | update() { 228 | 229 | if [[ $SCRIPTVERSION != "local-dev" ]] 230 | then 231 | GVMURL=$(printf "https://github.com/devnw/gvm/releases/download/%s/gvm" "$SCRIPTVERSION") 232 | SUMPATH=$(printf "%s.sum" "$GVMURL") 233 | EXPECTEDSUM=$(curl -sL "$SUMPATH") 234 | 235 | # shellcheck disable=SC2086 236 | 237 | if [[ "$OSTYPE" == "msys"* ]] 238 | then 239 | FILESUM=$(certutil -hashfile $0 sha256 | tail -n2 | head -n1) 240 | EXPECTEDSUM=$(curl -sL "$SUMPATH" | sed 's/ -//') # ⚠️ additional 2xspace + dash may also need to be addressed on unix installs 241 | else 242 | FILESUM=$(cat $0 | shasum -a 256) 243 | EXPECTEDSUM=$(curl -sL "$SUMPATH") 244 | fi 245 | 246 | 247 | 248 | if [[ "$EXPECTEDSUM" != "Not Found" ]] 249 | then 250 | if [[ "$EXPECTEDSUM" != "" && $FILESUM != "$EXPECTEDSUM" ]] 251 | then 252 | if [[ $alwaysUpdate == true ]] 253 | then 254 | upgrade "$@" 255 | else 256 | printf "New Version of GVM [%s] Available would you like to update? " "$SCRIPTVERSION" 257 | 258 | read -rp "[Yes: Y or y | No: Enter]? " yn 259 | 260 | # Only trigger on `Y` or `y` 261 | if [[ "$yn" == "Y" || "$yn" == "y" ]] 262 | then 263 | alwaysUpdateQ 264 | upgrade "$@" 265 | fi 266 | fi 267 | fi 268 | fi 269 | fi 270 | } 271 | 272 | # Determine if the script is out of date and offer to update 273 | update "$@" 274 | 275 | if [[ ! $1 =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\.?|[1-9][0-9]*)(((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?$ ]] 276 | then 277 | if [[ "$1" != "next" ]] 278 | then 279 | printf "%s is not a valid Go version\n" "$1" 280 | 281 | help 282 | 283 | exit 1 284 | fi 285 | fi 286 | 287 | if [[ "$active" == "$1" ]] 288 | then 289 | if [[ $remove == true ]] 290 | then 291 | printf "Unabled to remove active version %s\n" "$active" 292 | exit 1 293 | fi 294 | 295 | printf "Go version ${bold}%s${normal} is already active\n" "$1" 296 | exit 0 297 | fi 298 | 299 | if [[ $remove == true ]] 300 | then 301 | if [[ ! -d "$gvmroot/$1" ]] 302 | then 303 | printf "Go version %s does not exist\n" "$1" 304 | exit 1 305 | fi 306 | 307 | printf "Removing Go version %s\n" "$1" 308 | rm -rf "${gvmroot:?}/$1" 309 | 310 | exit 0 311 | fi 312 | 313 | arch="amd64" 314 | extention=".tar.gz" 315 | if uname -a | grep "arm64"&> /dev/null 316 | then 317 | arch="arm64" 318 | printf "Configuring for %s Architecture\n" "$arch" 319 | fi 320 | 321 | if [[ "$OSTYPE" == "darwin"* ]] 322 | then 323 | os="darwin" 324 | elif [[ "$OSTYPE" == "linux"* ]] 325 | then 326 | os="linux" 327 | elif [[ "$OSTYPE" == "msys"* ]] 328 | then 329 | os="windows" 330 | arch="amd64" 331 | extention=".zip" 332 | elif [[ "$OSTYPE" == "freebsd"* ]] 333 | then 334 | os="freebsd" 335 | else 336 | printf "Unsupported OS\n" 337 | exit 1 338 | fi 339 | 340 | if [[ ! -d "$gvmroot" ]] 341 | then 342 | printf "Adding ~/.gvm directory for go installs\n" 343 | if ! mkdir "$gvmroot" 344 | then 345 | fail "$(printf "Error creating %s\n" "$gvmroot")" 346 | fi 347 | fi 348 | 349 | if [[ "$version" == "next" ]] 350 | then 351 | printf "Installing Go %s\n" "$version" 352 | if ! which go 353 | then 354 | fail "$(printf "Installing go from %s requires an existing go installation\n" "$golanggit")" 355 | fi 356 | 357 | if [[ ! -d "$srcd" ]] 358 | then 359 | mkdir "$srcd" 360 | fi 361 | 362 | srcd="$srcd/go" 363 | 364 | if [[ ! -d "$srcd" ]] 365 | then 366 | printf "Cloning go source\n" 367 | if ! git clone "$golanggit" "$srcd" 368 | then 369 | fail "$("Error cloning %s\n" "$golanggit")" 370 | fi 371 | 372 | # Add update flag since source repo 373 | # did not already exist 374 | update="--update" 375 | fi 376 | 377 | if [[ "$update" == "--update" ]] 378 | then 379 | cd "$srcd" || exit 1 380 | 381 | if ! git checkout "$branch" 382 | then 383 | fail "$(printf "Checkout of %s failed\n" "$branch")" 384 | fi 385 | 386 | if ! git pull 387 | then 388 | fail "$(printf "git pull failed for %s\n" "$branch")" 389 | fi 390 | 391 | if ! cd "$srcd/src/" 392 | then 393 | fail "$(printf "Unable to move to %s\n" "$srcd/src/")" 394 | fi 395 | 396 | if ! GOROOT_BOOTSTRAP="$(which go)" ./all.bash 397 | then 398 | 399 | # Only fail if the go binary wasn't properly built 400 | if ! ../bin/go version 401 | then 402 | cd "$wd" || exit 1 403 | fail "$(printf "Failure installing go from %s\n" "$branch")" 404 | fi 405 | fi 406 | 407 | cd "$wd" || exit 1 408 | fi 409 | else 410 | if [[ ! -d "$versionroot" ]] 411 | then 412 | 413 | pkg="go$version.$os-$arch$extention" 414 | url="$dlroot$pkg" 415 | pkgDir="$gvmroot/$pkg" 416 | 417 | if ! curl -fsL --head "$url"&> /dev/null 418 | then 419 | fail "$(printf "Go Version Download %s does not exist" "$version")" 420 | fi 421 | 422 | printf "Downloading %s\n" "$url" 423 | if ! curl -fsL "$url" > "$pkgDir" 424 | then 425 | fail "$(printf "Unable to curl %s\n" "$url")" 426 | fi 427 | 428 | printf "Creating %s\n" "$versionroot" 429 | if ! mkdir -p "$versionroot" 430 | then 431 | fail "$(printf "Unable to create %s\n" "$versionroot")" 432 | fi 433 | 434 | if [[ "$extention" == ".zip" ]] 435 | then 436 | if ! unzip -qd "$versionroot" "$pkgDir" 437 | then 438 | fail "$(printf "Unable to zip extract %s\n" "$pkgDir" rm -rf "$versionroot")" 439 | fi 440 | else 441 | if ! tar -C "$versionroot" -xzf "$pkgDir" 442 | then 443 | fail "$(printf "Unable to tar extract %s\n" "$pkgDir" rm -rf "$versionroot")" 444 | fi 445 | fi 446 | 447 | rm "$pkgDir" 448 | fi 449 | fi 450 | 451 | # Set correct path for symlink re-map 452 | lnsrc="$versionroot/go" 453 | 454 | printf "Updating symlink %s => %s\n" "$lnsrc" "$gvmroot" 455 | 456 | #Windows + Gitbash require an explicit delete of the previously linked folder 457 | if [[ "$os" == "windows" ]] 458 | then 459 | printf "Removing %s/go if the directory exists\n" "$gvmroot" 460 | rm -rf "$gvmroot/go" 461 | fi 462 | 463 | if ! ln -sf "$lnsrc" "$gvmroot" 464 | then 465 | fail "$(printf "Unable to symlink directory %s\n" "$lnsrc")" 466 | fi 467 | 468 | if ! printf "%s" "$PATH" | grep -q "$gvmbin" 469 | then 470 | printf "Adding %s to PATH\n" "$gvmbin" 471 | 472 | path=$(printf "export PATH=\"%s:\$PATH\"" "$gvmbin") 473 | 474 | if [[ "$SHELL" == *"zsh" ]] 475 | then 476 | printf "%s" "$path" >> "$HOME/.zshrc" 477 | exec zsh 478 | else 479 | printf "%s" "$path" >> "$HOME/.bashrc" 480 | 481 | # shellcheck disable=SC1091 482 | source "$HOME"/.bashrc 483 | 484 | if uname -a | grep Ubuntu&> /dev/null 485 | then 486 | printf "For ubuntu you must run [source ~/.bashrc] or logout/login to complete path installation\n" 487 | fi 488 | fi 489 | fi 490 | 491 | if which go&> /dev/null 492 | then 493 | pathgo=$(which go) 494 | if [[ "$pathgo" != "$gvmexe" ]] 495 | then 496 | printf "GVM is shadowed by %s in your PATH. Please update your PATH to use %s first\n" \ 497 | "$pathgo" \ 498 | "$gvmbin" 499 | 500 | exit 1 501 | fi 502 | 503 | printf "Go %s Active\n" "$version" 504 | fi 505 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Create the bin directory in the user's home if it doesn't exist 4 | mkdir -p $HOME/bin 5 | 6 | # Check if $HOME/bin already exists in the PATH in ~/.profile 7 | grep -q "$HOME/bin" $HOME/.profile 8 | 9 | # $? is a special variable that holds the exit status of the last command executed 10 | # grep will return 0 if the line is found, and 1 otherwise 11 | 12 | if [ $? -ne 0 ]; then 13 | # Append the export statement to ~/.profile if it doesn't exist 14 | echo "export PATH=$HOME/bin:$PATH" >> $HOME/.profile 15 | echo "PATH updated in ~/.profile." 16 | else 17 | echo "PATH already updated in ~/.profile." 18 | fi 19 | 20 | # Source ~/.profile to reflect changes immediately in the current shell 21 | source $HOME/.profile 22 | echo "Current shell PATH updated." 23 | 24 | curl -L https://github.com/devnw/gvm/releases/download/latest/gvm \ 25 | > $HOME/bin/gvm && chmod +x $HOME/bin/gvm 26 | 27 | source $HOME/.profile 28 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version=$(git describe --tags --always) 4 | if [[ $1 != "" ]] 5 | then 6 | version=$1 7 | fi 8 | 9 | # shellcheck disable=SC2209 10 | SED=sed 11 | if [[ "$OSTYPE" == "darwin"* ]] 12 | then 13 | if ! which gsed&> /dev/null 14 | then 15 | printf "gsed is required for MacOS\n" 16 | exit 1 17 | fi 18 | SED=gsed 19 | fi 20 | 21 | # shellcheck disable=SC2016 22 | searchstring=$(printf 'SCRIPTVERSION="local-dev"') 23 | replstring=$(printf 'SCRIPTVERSION="%s"' "$version") 24 | sedcmd=$(printf "s/%s/%s/" "$searchstring" "$replstring") 25 | $SED -i "$sedcmd" ./gvm --------------------------------------------------------------------------------