generalize, a lot
[webi-installers/.git] / README.md
1 # packages
2
3 Primary and community-submitted packages for
4 [webinstall.dev](https://webinstall.dev)
5
6 # Guidelines
7
8 - Should install to `./local/opt/<package>-<version>`
9 - Should not need `sudo` (except perhaps for a one-time `setcap`, etc)
10 - Follow the example of
11   <https://github.com/webinstall/packages/tree/master/ripgrep>,
12   <https://github.com/webinstall/packages/tree/master/node>, or
13   <https://github.com/webinstall/packages/tree/master/golang>
14
15 ## Creating an Installer
16
17 An install consists of 5 parts in 4 files:
18
19 ```
20 my-new-package/
21   - package.yash
22   - releases.js
23   - install.sh
24   - install.bat
25 ```
26
27 1. Create Description
28 2. Fetch Releases
29 3. Version Check (semi-optional)
30 4. Update PATH
31
32 See these **examples**:
33
34 - https://github.com/webinstall/packages/blob/master/rg/
35 - https://github.com/webinstall/packages/blob/master/golang/
36
37 The `webinstall.dev` server uses the list of releases returned by
38 `<your-package>/releases.js` to generate a bash script with most necessary
39 variables and functions pre-defined.
40
41 You just fill in the blanks.
42
43 ### TL;DR
44
45 Just create an empty directory and run the tests until you get a good result.
46
47 ```bash
48 mkdir -p new-package
49 node _webi/test.js ./new-package/
50 ```
51
52 ### 1. Create Description
53
54 Just copy the format from any of the existing packages. It's like this:
55
56 `package.yash`:
57
58 ````
59 # title: Node.js
60 # homepage: https://nodejs.org
61 # tagline: JavaScript V8 runtime
62 # description: |
63 #   Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine
64 # examples: |
65 #   ```bash
66 #   node -e 'console.log("Hello, World!")'
67 #   > Hello, World!
68 #   ```
69
70 END
71 ````
72
73 This is a dumb format. We know. Historical accident (originally these were in
74 bash comments).
75
76 It's in the TODOs to replace this with either YAML or Markdown.
77
78 ### 1. Fetch Releases
79
80 All you're doing in this step is just translating from one form of JSON or CSV
81 or TAB or whatever, to a format understood by `webi`.
82
83 - Using Github releases? See `ripgrep/releases.js` (which uses
84   `_common/github.js`)
85 - Have a special format? See `golang/releases.js` or `node/releases.js`.
86
87 It looks like this:
88
89 `releases.js`:
90
91 ```js
92 module.exports = function (request) {
93   return github(request, owner, repo).then(function (all) {
94     // if you need to do something special, you can do it here
95     // ...
96     return all;
97   });
98 };
99 ```
100
101 ### 2. Bash Installer
102
103 1. Variables _you_ can set
104 2. Functions _you_ must define
105 3. Convenience / Helper Functions
106
107 (optional, if needed) Bash variables that you _may_ define:
108
109 ```bash
110 # Define this if the package name is different from the command name (i.e. golang => go)
111 pkg_cmd_name="foobar"
112
113 # These are used for symlinks, PATH, and test commands
114 pkg_dst="$HOME/.local/opt/foobar"
115 pkg_dst_bin="$HOME/.local/opt/foobar/bin"
116 pkg_dst_cmd="$HOME/.local/opt/foobar/bin/foobar"
117
118 # These are the _real_ locations for the above
119 pkg_src="$HOME/.local/opt/foobar-v$WEBI_VERSION"
120 pkg_src_bin="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin"
121 pkg_src_cmd="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin/foobar"
122 ```
123
124 (required) A version check function that strips all non-version junk
125
126 ```bash
127 pkg_get_current_version() {
128     # foobar-v1.1.7 => 1.1.7
129     echo "$(foobar --version | head -n 1 | sed 's:foobar-v::')"
130 }
131 ```
132
133 For the rest of the functions you can like copy/paste from the examples:
134
135 ```bash
136 pkg_format_cmd_version() {}         # Override, pretty prints version
137
138 pkg_link                            # Override, replaces webi_link()
139
140 pkg_pre_install() {                 # Override, runs any webi_* commands
141     webi_check                          # for $HOME/.local/opt tools
142     webi_download                       # for things that have a releases.js
143     webi_extract                        # for .xz, .tar.*, and .zip files
144 }
145
146 pkg_install() {}                    # Override, usually just needs to rename extracted folder to
147                                     # "$HOME/.local/opt/$pkg_cmd_name-v$WEBI_VERSION"
148
149 pkg_post_install() {                # Override
150     webi_path_add "$pkg_dst_bin"        # should probably update PATH
151 }
152
153 pkg_done_message() {}               # Override, pretty print a success message
154 ```
155
156 ## Script API
157
158 See `webi/template.bash`
159
160 These variables will be set by the server:
161
162 ```
163 WEBI_PKG=example@v1
164 WEBI_NAME=example
165 WEBI_TAG=v1
166 WEBI_HOST=https://webinstall.dev
167 WEBI_RELEASES=https://webinstall.dev/api/releases/example@v1?os=macos&arch=amd64&pretty=true
168 WEBI_CSV=v1.0.2,
169 WEBI_VERSION=1.0.2
170 WEBI_MAJOR=1
171 WEBI_MINOR=0
172 WEBI_PATCH=2
173 WEBI_LTS=
174 WEBI_CHANNEL=stable
175 WEBI_EXT=tar
176 WEBI_PKG_URL=https://cdn.example.com/example-macos-amd64.tar.gz
177 WEBI_PKG_FILE=example-macos-amd64.tar.gz
178 ```
179
180 ```bash
181 WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-foobar.XXXXXXXX)"}
182 WEBI_SINGLE=""
183 ```
184
185 ```bash
186 webi_check              # Checks to see if the selected version is already installed (and re-links if so)
187 webi_download           # Downloads the selected release to $HOME/Downloads/<package-name>.tar.gz
188 webi_extract            # Extracts the download to /tmp/<package-name>-<random>/
189 webi_path_add /new/path # Adds /new/path to PATH for bash, zsh, and fish
190 webi_pre_install        # Runs webi_check, webi_download, and webi_extract
191 webi_install            # Moves extracted files from $WEBI_TMP to $pkg_src
192 webi_link               # replaces any existing symlink with the currently selected version
193 webi_post_install       # Runs `webi_add_path $pkg_dst_bin`
194 ```
195
196 # Roadmap
197
198 - Wrap release APIs to unify and expose
199   - [x] Golang <https://golang.org/dl/?mode=json>
200   - [x] Node <https://nodejs.org/dist/index.tab>
201   - [x] Flutter
202         <https://storage.googleapis.com/flutter_infra/releases/releases_linux.json> -
203         Started at
204         <https://github.com/webinstall/packages/blob/master/flutter/versions.js>
205   - [ ] git
206     - Note: do all platforms expose tar/zip releases with the same URLs?
207   - [ ] npm
208   - [x] github (see ripgrep)
209   - [x] gitea (see serviceman)
210 - [ ] Support git urls (i.e. `@github.com/node/node`)
211   - (maybe `ghi node/node` for github specifically)