bugfix: invert download check
[webi-installers/.git] / README.md
1 # [webi-installers](https://github.com/webinstall/webi-installers)
2
3 > [webi](https://webinstall.dev) is how developers install their tools
4
5 - no `sudo`
6 - no package manager
7 - no messing with system permissions
8 - in short: no nonsense
9
10 ```bash
11 curl https://webinstall.dev/webi | bash
12 ```
13
14 This repository contains the primary and community-submitted packages for
15 [webinstall.dev](https://webinstall.dev).
16
17 # How webi works
18
19 - Contacts official release APIs for download URLs
20 - Selects the appropriate package version and archive format
21 - Installs to `$HOME/.local/opt` or `$HOME/.local/bin`, as appropriate.
22 - Updates `PATH` via `$HOME/.config/envman/PATH.env`
23 - Symlinks or copies current selected version
24
25 More technically:
26
27 1. `<package>/releases.js` transforms the package's release API into a common
28    format
29    - (i.e. HTML, CSV, TAB, or JSON into a specific JSON format)
30    - common release APIs are in `_common/` (i.e. `_common/github.js`)
31 2. `_webi/bootstrap.sh` is a template that exchanges system information for a
32    correct installer
33    - contructs a user agent with os, cpu, and utility info (i.e. `macos`,
34      `amd64`, can unpack `tar,zip,xz`)
35 3. `_webi/template.sh` is the base installer template with common functions for
36    - checking versions
37    - downloading & unpacking
38    - updating PATH
39    - (re-)linking directories
40 4. `<package>/install.sh` may provide functions to override `_webi/template.sh`
41 5. Recap:
42    - `curl https://webinstall.dev/<pkg>` => `bootstrap-<pkg>.sh`
43    - `bash bootstrap-<pkg>.sh` =>
44      `https://webinstall.dev/api/installers/<pkg>@<ver>.sh?formats=zip,tar`
45    - `bash install-<pkg>.sh` => download, unpack, move, link, update PATH
46
47 # Philosophy (for package authors / maintainers publishing with webi)
48
49 - Should install to `$HOME/.local/opt/<package>-<version>` or `$HOME/.local/bin`
50 - Should not need `sudo` (except perhaps for a one-time `setcap`, etc)
51 - Examples:
52   - Full Packages:
53     - Node.js: <https://github.com/webinstall/packages/tree/master/node>
54     - Golang: <https://github.com/webinstall/packages/tree/master/golang>
55     - PostgreSQL: <https://github.com/webinstall/packages/tree/master/postgres>
56   - Single-Binary Installers:
57     - Caddy: <https://github.com/webinstall/packages/tree/master/caddy>
58     - Ripgrep: <https://github.com/webinstall/packages/tree/master/ripgrep>
59     - Gitea: <https://github.com/webinstall/packages/tree/master/gitea>
60   - Convenience Scripts:
61     - Prettier: <https://github.com/webinstall/packages/tree/master/prettier>
62     - Rust-lang: <https://github.com/webinstall/packages/tree/master/rustlang>
63     - vim-sensible:
64       <https://github.com/webinstall/packages/tree/master/vim-sensible>
65
66 ## Creating an Installer
67
68 An install consists of 5 parts in 4 files:
69
70 ```
71 my-new-package/
72   - README.md (package info in frontmatter)
73   - releases.js
74   - install.sh (bash)
75   - install.ps1 (PowerShell)
76 ```
77
78 1. Create Description
79 2. Fetch Releases
80 3. Version Check (semi-optional)
81 4. Update PATH
82
83 See these **examples**:
84
85 - https://github.com/webinstall/packages/blob/master/rg/
86 - https://github.com/webinstall/packages/blob/master/golang/
87
88 The `webinstall.dev` server uses the list of releases returned by
89 `<your-package>/releases.js` to generate a bash script with most necessary
90 variables and functions pre-defined.
91
92 You just fill in the blanks.
93
94 ### TL;DR
95
96 Just create an empty directory and run the tests until you get a good result.
97
98 ```bash
99 git clone git@github.com:webinstall/packages.git
100 pushd packages
101 npm install
102 ```
103
104 ```bash
105 mkdir -p ./new-package/
106 node _webi/test.js ./new-package/
107 ```
108
109 ### 1. Create Description
110
111 Just copy the format from any of the existing packages. It's like this:
112
113 `README.md`:
114
115 ````md
116 ---
117 title: Node.js
118 homepage: https://nodejs.org
119 tagline: JavaScript V8 runtime
120 description: |
121   Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine
122 ---
123
124 ```bash
125 node -e 'console.log("Hello, World!")'
126 > Hello, World!
127 ```
128 ````
129
130 ### 1. Fetch Releases
131
132 All you're doing in this step is just translating from one form of JSON or CSV
133 or TAB or whatever, to a format understood by `webi`.
134
135 - Using Github releases? See `ripgrep/releases.js` (which uses
136   `_common/github.js`)
137 - Have a special format? See `golang/releases.js` or `node/releases.js`.
138
139 It looks like this:
140
141 `releases.js`:
142
143 ```js
144 module.exports = function (request) {
145   return github(request, owner, repo).then(function (all) {
146     // if you need to do something special, you can do it here
147     // ...
148     return all;
149   });
150 };
151 ```
152
153 ### 2. Bash Installer
154
155 1. Variables _you_ can set
156 2. Functions _you_ must define
157 3. Convenience / Helper Functions
158
159 (optional, if needed) Bash variables that you _may_ define:
160
161 ```bash
162 # Define this if the package name is different from the command name (i.e. golang => go)
163 pkg_cmd_name="foobar"
164
165 # These are used for symlinks, PATH, and test commands
166 pkg_dst="$HOME/.local/opt/foobar"
167 pkg_dst_cmd="$HOME/.local/opt/foobar/bin/foobar"
168 #pkg_dst_bin="$(dirname "$pkg_dst_cmd")"
169
170 # These are the _real_ locations for the above
171 pkg_src="$HOME/.local/opt/foobar-v$WEBI_VERSION"
172 pkg_src_cmd="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin/foobar"
173 #pkg_src_bin="$(dirname "$pkg_src_cmd")"
174 ```
175
176 (required) A version check function that strips all non-version junk
177
178 ```bash
179 pkg_get_current_version() {
180     # foobar-v1.1.7 => 1.1.7
181     echo "$(foobar --version | head -n 1 | sed 's:foobar-v::')"
182 }
183 ```
184
185 For the rest of the functions you can like copy/paste from the examples:
186
187 ```bash
188 pkg_format_cmd_version() {}         # Override, pretty prints version
189
190 pkg_link                            # Override, replaces webi_link()
191
192 pkg_pre_install() {                 # Override, runs any webi_* commands
193     webi_check                          # for $HOME/.local/opt tools
194     webi_download                       # for things that have a releases.js
195     webi_extract                        # for .xz, .tar.*, and .zip files
196 }
197
198 pkg_install() {}                    # Override, usually just needs to rename extracted folder to
199                                     # "$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION"
200
201 pkg_post_install() {                # Override
202     webi_path_add "$pkg_dst_bin"        # should probably update PATH
203 }
204
205 pkg_done_message() {}               # Override, pretty print a success message
206 ```
207
208 ## Script API
209
210 See `webi/template.sh`
211
212 These variables will be set by the server:
213
214 ```bash
215 WEBI_PKG=example@v1
216 WEBI_TAG=v1
217 WEBI_HOST=https://webinstall.dev
218 WEBI_RELEASES=https://webinstall.dev/api/releases/example@v1?os=macos&arch=amd64&pretty=true
219 WEBI_CSV=v1.0.2,
220 WEBI_VERSION=1.0.2
221 WEBI_MAJOR=1
222 WEBI_MINOR=0
223 WEBI_PATCH=2
224 WEBI_LTS=
225 WEBI_CHANNEL=stable
226 WEBI_EXT=tar
227 WEBI_PKG_URL=https://cdn.example.com/example-macos-amd64.tar.gz
228 WEBI_PKG_FILE=example-macos-amd64.tar.gz
229 ```
230
231 ```bash
232 PKG_NAME=example
233 PKG_OSES=macos,linux,windows
234 PKG_ARCHES=amd64,arm64,x86
235 PKG_FORMATS=zip,xz
236 ```
237
238 ```bash
239 WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-foobar.XXXXXXXX)"}
240 WEBI_SINGLE=""
241 ```
242
243 ```bash
244 webi_check              # Checks to see if the selected version is already installed (and re-links if so)
245 webi_download           # Downloads the selected release to $HOME/Downloads/<package-name>.tar.gz
246 webi_extract            # Extracts the download to /tmp/<package-name>-<random>/
247 webi_path_add /new/path # Adds /new/path to PATH for bash, zsh, and fish
248 webi_pre_install        # Runs webi_check, webi_download, and webi_extract
249 webi_install            # Moves extracted files from $WEBI_TMP to $pkg_src
250 webi_link               # replaces any existing symlink with the currently selected version
251 webi_post_install       # Runs `webi_path_add $pkg_dst_bin`
252 ```
253
254 # Roadmap
255
256 - Wrap release APIs to unify and expose
257 - [ ] Support more Windows packages
258 - [ ] Support arbitrary git urls (i.e. `@github.com/node/node`)
259   - (maybe `ghi node/node` for github specifically)
260 - [ ] Support git as an archive format
261
262 <!--
263
264 # Windows Notes
265
266 ```bat
267 set WEBI_HOST=https://webinstall.dev
268 ```
269
270 Windows 10 has curl too!?
271
272 ```bat
273 curl.exe -sL -A "MS" https://webinstall.dev/node | powershell
274 ```
275
276 And it's easy enough to ignore the execution policy
277
278 ```bat
279 powershell -ExecutionPolicy Bypass install.ps1
280 ```
281
282 And if we want something that looks as complicated as we expect Windows to be,
283 historically, we have options:
284
285 ```bat
286 powershell "Invoke-Expression ( Invoke-WebRequest -UseBasicParsing https://webinstall.dev/node ).Contents"
287 ```
288
289 ```bat
290 powershell ( Invoke-WebRequest -UseBasicParsing https://webinstall.dev/node ).Contents | powershell
291 ```
292
293 -->