From: AJ ONeal Date: Sat, 22 Aug 2020 20:21:01 +0000 (+0000) Subject: make _example current, add rg for Windows X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=1c97e1c661fd9739d71079b60e90ab2419d4531c;p=webi-installers%2F.git make _example current, add rg for Windows --- diff --git a/_example/README.md b/_example/README.md index 0806904..779fe7b 100644 --- a/_example/README.md +++ b/_example/README.md @@ -1,33 +1,38 @@ --- title: Foo Bar -bin: foobar -homepage: https://example.com/foobar -tagline: To err is human, but to foobar... +homepage: https://github.com/webinstall/foobar +tagline: | + foobar: An example that doesn't exist. --- -# Foo Bar +### Updating `foo` - +`webi foo@stable` -Foo Bar is a community-developed, commercially supported destruction system. +Use the `@beta` tag for pre-releases. -## Examples +## Cheat Sheet -Really mess something up +> `foo` doesn't exist and this text should have been replaced. It doesn't do +> anything, but what it does is useful because it is; everybody knows it. + +To run foo: ```bash -foobar my-file.txt +foo ``` -Mess up the entire volume, forcefully and recursively +### Add Baz Highlighting + +To run foo with both bar and baz highlighting turned on: ```bash -foobar -rf / +foo --bar=baz ``` diff --git a/_example/install.ps1 b/_example/install.ps1 new file mode 100644 index 0000000..ad1376e --- /dev/null +++ b/_example/install.ps1 @@ -0,0 +1,62 @@ +#!/usr/bin/env pwsh + +################## +# Install foobar # +################## + +# Every package should define these variables +$pkg_cmd_name = "foo" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\foo.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\foobar-v$Env:WEBI_VERSION\bin\foo.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\foobar-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\foobar-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading foobar from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing foobar" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\foobar-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\foo.exe" -Recurse -ErrorAction Ignore + + # NOTE: DELETE THIS COMMENT IF NOT USED + # Move single binary into root of temporary folder + #& move "$pkg_download" "foo.exe" + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + & dir + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory + Move-Item -Path ".\foobar-*\foo.exe" -Destination "$pkg_src_bin" + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/_example/install.sh b/_example/install.sh index 91a8cf5..6ae2b2e 100644 --- a/_example/install.sh +++ b/_example/install.sh @@ -1,79 +1,39 @@ #!/bin/bash -set -e -set -u +{ + set -e + set -u + + ################## + # Install foobar # + ################## + + # Every package should define these 6 variables + pkg_cmd_name="foo" + + pkg_dst_cmd="$HOME/.local/bin/foo" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/foobar-v$WEBI_VERSION/bin/foo" + pkg_src_dir="$HOME/.local/opt/foobar-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/foobar-v0.99.9/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./foobar-*/foo ~/.local/opt/foobar-v0.99.9/bin/foo + mv ./foobar-*/foo "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'foo --version' has output in this format: + # foobar 0.99.9 (rev abcdef0123) + # This trims it down to just the version number: + # 0.99.9 + echo $(foo --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2) + } -## The defaults can be assumed if these are not set - -## The command name may be different from the package name -## (i.e. golang => go, rustlang => cargo, ripgrep => rg) -## Note: $HOME may contain special characters and should alway be quoted - -pkg_cmd_name="xmpl" - -## Some of these directories may be the same, in some cases -#pkg_dst="$HOME/.local/opt/xmpl" -#pkg_dst_bin="$HOME/.local/opt/xmpl/bin" -#pkg_dst_cmd="$HOME/.local/opt/xmpl/bin/xmpl" - -#pkg_src="$HOME/.local/opt/xmpl-v$WEBI_VERSION" -#pkg_src_bin="$HOME/.local/opt/xmpl-v$WEBI_VERSION/bin" -#pkg_src_cmd="$HOME/.local/opt/xmpl-v$WEBI_VERSION/bin/xmpl" - -# Different packages represent the version in different ways -# ex: node v12.8.0 (leading 'v') -# ex: go1.14 (no space, nor trailing '.0's) -# ex: flutter 1.17.2 (plain) -pkg_format_cmd_version() { - my_version=$1 - echo "$pkg_cmd_name v$my_version" -} - -# The version info should be reduced to a sortable version, without any leading characters -# (i.e. v12.8.0 => 12.8.0, go1.14 => 1.14, 1.12.13+hotfix => 1.12.13+hotfix) -pkg_get_current_version() { - echo "$(xmpl --version 2>/dev/null | head -n 1 | cut -d' ' -f2)" -} - -# For (re-)linking to the desired installed version -# (for example: 'go' is special and needs both $HOME/go and $HOME/.local/opt/go) -# (others like 'rg', 'hugo', and 'caddy' are single files that just get replaced) -pkg_link() { - rm -rf "$pkg_dst" - ln -s "$pkg_src" "$pkg_dst" -} - -pkg_pre_install() { - # web_* are defined in _webi/template.sh at https://github.com/webinstall/packages - - # if selected version is installed, re-link it and quit - webi_check - - # will save to ~/Downloads/$WEBI_PKG_FILE by default - webi_download - - # supported formats (.xz, .tar.*, .zip) will be extracted to $WEBI_TMP - webi_extract -} - -# For installing from the extracted package tmp directory -pkg_install() { - # remove the versioned folder, just in case it's there with junk - rm -rf "$pkg_src" - - # rename the entire extracted folder to the new location - # (this will be "$HOME/.local/opt/xmpl-v$WEBI_VERSION" by default) - mv ./"$pkg_cmd_name"* "$pkg_src" -} - -# For updating PATHs and installing companion tools -pkg_post_install() { - pkg_link - - # web_path_add is defined in _webi/template.sh at https://github.com/webinstall/packages - webi_path_add "$pkg_dst_bin" -} - -pkg_done_message() { - echo "Installed 'example' as 'xmpl' at $pkg_dst_cmd" } diff --git a/_example/install_safe_copy.sh b/_example/install_safe_copy.sh deleted file mode 100644 index c52b018..0000000 --- a/_example/install_safe_copy.sh +++ /dev/null @@ -1,14 +0,0 @@ -# For installing from the extracted package tmp directory -pkg_install() { - pushd "$WEBI_TMP" 2>&1 >/dev/null - - if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then - rsync -Krl ./xmpl*/ "$pkg_src/" 2>/dev/null - else - cp -Hr ./xmpl*/* "$pkg_src/" 2>/dev/null - cp -Hr ./xmpl*/.* "$pkg_src/" 2>/dev/null - fi - rm -rf ./xmpl* - - popd 2>&1 >/dev/null -} diff --git a/_example/releases.js b/_example/releases.js index 9812559..c1502d7 100644 --- a/_example/releases.js +++ b/_example/releases.js @@ -1,42 +1,28 @@ 'use strict'; var github = require('../_common/github.js'); -var owner = 'HorseAJ86'; -var repo = 'shmatter'; +var owner = 'BurntSushi'; +var repo = 'ripgrep'; -module.exports = function (request) { - // 1. fetch the list of releases - // 2. translate into the style of object that webinstall needs - // 3. missing / guessable pieces will be filled automatically by filename and such - // (in this example the github releases module does 100% of the work) - - return github(request, owner, repo).then(function (data) { - var releases = data.releases; - - /* - // Example: - var releases = [{ - "name": "shmatter-darwin-x64-1.0.0.tgz", - "version": "v1.0.0", - "lts": false, // long-term support release - "channel": "stable", // stable|rc|beta|dev - "date": "2020-05-07", - "download": "https://github.com/HorseAJ86/shmatter/releases/download/v1.0.0/shmatter-darwin-x64-1.0.0.tgz", - "os": "", // will be guessed as macos (darwin -> macos) - "arch": "", // will be guessed as amd64 (x64 -> amd64) - "ext": "" // will be guessed as tar (tgz -> tar.gz -> tar) - }] - */ +/******************************************************************************/ +/** Note: Delete this Comment! **/ +/** **/ +/** Need a an example that filters out miscellaneous release files? **/ +/** See `deno`, `gitea`, or `caddy` **/ +/** **/ +/******************************************************************************/ - return { releases: releases }; +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + return all; }); }; if (module === require.main) { module.exports(require('@root/request')).then(function (all) { - // limit the example output - all.releases = all.releases.slice(0, 5); all = require('../_webi/normalize.js')(all); + // just select the first 5 for demonstration + all.releases = all.releases.slice(0, 5); console.info(JSON.stringify(all, null, 2)); }); } diff --git a/_webi/example_install_safe_copy.sh b/_webi/example_install_safe_copy.sh new file mode 100644 index 0000000..c52b018 --- /dev/null +++ b/_webi/example_install_safe_copy.sh @@ -0,0 +1,14 @@ +# For installing from the extracted package tmp directory +pkg_install() { + pushd "$WEBI_TMP" 2>&1 >/dev/null + + if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then + rsync -Krl ./xmpl*/ "$pkg_src/" 2>/dev/null + else + cp -Hr ./xmpl*/* "$pkg_src/" 2>/dev/null + cp -Hr ./xmpl*/.* "$pkg_src/" 2>/dev/null + fi + rm -rf ./xmpl* + + popd 2>&1 >/dev/null +} diff --git a/_webi/normalize.js b/_webi/normalize.js index 06c1cee..0e06bcb 100644 --- a/_webi/normalize.js +++ b/_webi/normalize.js @@ -84,6 +84,7 @@ function normalize(all) { } supported.arches[rel.arch] = true; + var tarExt; if (!rel.ext) { // pkg-v1.0.tar.gz => ['gz', 'tar', '0', 'pkg-v1'] // pkg-v1.0.tar => ['tar', '0' ,'pkg-v1'] @@ -96,8 +97,10 @@ function normalize(all) { exts = exts.reverse().slice(0, 2); if ('tar' === exts[1]) { rel.ext = exts.reverse().join('.'); + tarExt = 'tar'; } else if ('tgz' == exts[0]) { rel.ext = 'tar.gz'; + tarExt = 'tar'; } else { rel.ext = exts[0]; } @@ -106,7 +109,7 @@ function normalize(all) { rel.ext = 'exe'; } } - supported.formats[rel.ext] = true; + supported.formats[tarExt || rel.ext] = true; if (all.download) { rel.download = all.download.replace(/{{ download }}/, rel.download); diff --git a/rg/install.ps1 b/rg/install.ps1 new file mode 100644 index 0000000..2c161a0 --- /dev/null +++ b/rg/install.ps1 @@ -0,0 +1,58 @@ +#!/usr/bin/env pwsh + +################### +# Install ripgrep # +################### + +# Every package should define these variables +$pkg_cmd_name = "rg" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\rg.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\ripgrep-v$Env:WEBI_VERSION\bin\rg.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\ripgrep-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\ripgrep-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading ripgrep from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing ripgrep" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\ripgrep-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\rg.exe" -Recurse -ErrorAction Ignore + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + & dir + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory + Move-Item -Path ".\ripgrep-*\rg.exe" -Destination "$pkg_src_bin" + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/rg/releases.js b/rg/releases.js index 2ebc97d..64ed376 100644 --- a/rg/releases.js +++ b/rg/releases.js @@ -13,7 +13,8 @@ module.exports = function (request) { if (module === require.main) { module.exports(require('@root/request')).then(function (all) { all = require('../_webi/normalize.js')(all); - console.info(JSON.stringify(all)); - //console.info(JSON.stringify(all, null, 2)); + // just select the first 5 for demonstration + all.releases = all.releases.slice(0, 5); + console.info(JSON.stringify(all, null, 2)); }); }