From: AJ ONeal Date: Thu, 7 May 2020 04:52:03 +0000 (-0600) Subject: add example dir X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=82ba9cd63386ca17a56044f688306af7716dfb48;p=webi-installers%2F.git add example dir --- diff --git a/_example/README.md b/_example/README.md new file mode 100644 index 0000000..0806904 --- /dev/null +++ b/_example/README.md @@ -0,0 +1,33 @@ +--- +title: Foo Bar +bin: foobar +homepage: https://example.com/foobar +tagline: To err is human, but to foobar... +--- + + + +# Foo Bar + + + +Foo Bar is a community-developed, commercially supported destruction system. + +## Examples + +Really mess something up + +```bash +foobar my-file.txt +``` + +Mess up the entire volume, forcefully and recursively + +```bash +foobar -rf / +``` diff --git a/_example/install.bash b/_example/install.bash new file mode 100644 index 0000000..99fba35 --- /dev/null +++ b/_example/install.bash @@ -0,0 +1,78 @@ +#!/bin/bash + +set -e +set -u + +################### +# Install foobar # +################### + +common_opt="${HOME}/.local/opt/foobar-v${WEBI_VERSION}" +new_opt="${HOME}/.local/opt/foobar-v${WEBI_VERSION}" +new_bin="${HOME}/.local/opt/foobar-v${WEBI_VERSION}/bin/foobar" + +update_installed() { + rm -rf "$common_opt" + ln -s "$new_opt" "$common_opt" + + # TODO get better output from pathman / output the path to add as return to webi bootstrap + webi_path_add "$common_opt/bin" + webi_path_add "$HOME/foobar/bin" +} + +if [ -x "$new_opt/bin/foobar" ]; then + update_installed + exit 0 +fi + +# Test for existing version +set +e +cur_go="$(command -v foobar)" +set -e +if [ -n "$cur_go" ]; then + cur_ver=$(foobar version | cut -d' ' -f3 | sed 's:foobar::') + if [ "$cur_ver" == "$(echo $WEBI_VERSION | sed 's:\.0::g')" ]; then + echo "foobar v$WEBI_VERSION already installed at $cur_go" + exit 0 + elif [ "$cur_go" != "$new_bin" ]; then + echo "WARN: possible conflict with foobar v$WEBI_VERSION at $cur_go" + fi +fi + + +# Note: this file is `source`d by the true installer and hence will have the webi functions + +# because we created releases.js we can use webi_download() +# downloads foobar to ~/Downloads +webi_download + +# because this is tar or zip, we can webi_extract() +# extracts to the WEBI_TMP directory, raw (no --strip-prefix) +webi_extract + +pushd "$WEBI_TMP" 2>&1 >/dev/null + echo Installing foobar v${WEBI_VERSION} as "$new_bin" + + # simpler for single-binary commands + #mv ./example*/bin/example "$HOME/.local/bin" + + # best for packages and toolchains + rm -rf "$new_opt" + if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then + rsync -Krl ./foobar*/ "$new_opt/" 2>/dev/null + else + cp -Hr ./foobar*/* "$new_opt/" 2>/dev/null + cp -Hr ./foobar*/.* "$new_opt/" 2>/dev/null + fi + rm -rf ./foobar* + +popd 2>&1 >/dev/null + +################### +# Update PATH # +################### + +update_installed + +echo "Installed 'foobar'" +echo "" diff --git a/_example/install.bat b/_example/install.bat new file mode 100644 index 0000000..a8c9bad --- /dev/null +++ b/_example/install.bat @@ -0,0 +1 @@ +rem TODO diff --git a/_example/releases.js b/_example/releases.js new file mode 100644 index 0000000..b39b54c --- /dev/null +++ b/_example/releases.js @@ -0,0 +1,41 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'HorseAJ86'; +var repo = 'shmatter'; + +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) + }] + */ + + return { releases: releases }; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + // limit the example output + all.releases = all.releases.slice(0, 5); + console.info(JSON.stringify(all, null, 2)); + }); +}