From: AJ ONeal Date: Tue, 16 Jun 2020 18:30:35 +0000 (+0000) Subject: better error handling when vailable formats mismatch X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=ef49c0287cc890f1394ddbbb192e9a98c0a53759;p=webi-installers%2F.git better error handling when vailable formats mismatch --- diff --git a/_webi/bootstrap.sh b/_webi/bootstrap.sh index 4a65519..9e12dba 100644 --- a/_webi/bootstrap.sh +++ b/_webi/bootstrap.sh @@ -46,6 +46,8 @@ if [ -n "\$(command -v unxz)" ]; then fi if [ -n "\$(command -v unzip)" ]; then my_ext="zip,\$my_ext" +else + echo "WARN: 'unzip' not found" fi if [ -n "\$(command -v tar)" ]; then my_ext="tar,\$my_ext" diff --git a/_webi/normalize.js b/_webi/normalize.js index dac0902..16c60b8 100644 --- a/_webi/normalize.js +++ b/_webi/normalize.js @@ -1,7 +1,7 @@ 'use strict'; // this may need customizations between packages -const osMap = { +var osMap = { macos: /(\b|_)(apple|mac|darwin|iPhone|iOS|iPad)/i, linux: /(\b|_)(linux)/i, freebsd: /(\b|_)(freebsd)/i, @@ -10,6 +10,12 @@ const osMap = { aix: /(\b|_)(aix)/i }; +var formats = ['zip', 'xz', 'tar', 'pkg', 'msi', 'git', 'exe', 'dmg']; +var formatsMap = {}; +formats.forEach(function (ext) { + formatsMap[ext] = true; +}); + // evaluation order matters // (i.e. otherwise x86 and x64 can cross match) var archArr = [ @@ -34,7 +40,10 @@ var archMap = { }; function normalize(all) { + var supportedFormats = {}; + all.releases.forEach(function (rel) { + supportedFormats[rel.ext] = true; rel.version = rel.version.replace(/^v/i, ''); if (!rel.name) { rel.name = rel.download.replace(/.*\//, ''); @@ -85,7 +94,16 @@ function normalize(all) { rel.download = all.download.replace(/{{ download }}/, rel.download); } }); + + all.formats = Object.keys(supportedFormats).filter(function (ext) { + return formatsMap[ext]; + }); + return all; } module.exports = normalize; +// NOT in order of priority (which would be tar, xz, zip, ...) +module.exports.formats = formats; +module.exports.arches = archArr; +module.exports.formatsMap = formatsMap; diff --git a/_webi/releases.js b/_webi/releases.js index f7f5eff..92c6a8c 100644 --- a/_webi/releases.js +++ b/_webi/releases.js @@ -18,6 +18,12 @@ Releases.renderBash = function ( rel, { baseurl, pkg, tag, ver, os, arch, formats } ) { + if (!Array.isArray(formats)) { + formats = []; + } + if (!tag) { + tag = ''; + } return fs.promises .readFile(path.join(pkgdir, 'install.sh'), 'utf8') .then(function (installTxt) { @@ -40,7 +46,7 @@ Releases.renderBash = function ( .replace(/^#?WEBI_HOST=.*/m, "WEBI_HOST='" + baseurl + "'") .replace(/^#?WEBI_OS=.*/m, "WEBI_OS='" + (os || '') + "'") .replace(/^#?WEBI_ARCH=.*/m, "WEBI_ARCH='" + (arch || '') + "'") - .replace(/^#?WEBI_TAG=.*/m, "WEBI_TAG='" + (tag || '') + "'") + .replace(/^#?WEBI_TAG=.*/m, "WEBI_TAG='" + tag + "'") .replace( /^#?WEBI_RELEASES=.*/m, "WEBI_RELEASES='" + @@ -53,6 +59,8 @@ Releases.renderBash = function ( rel.os + '&arch=' + rel.arch + + '&formats=' + + formats.join(',') + '&pretty=true' + "'" ) @@ -90,6 +98,10 @@ Releases.renderBash = function ( /^#?WEBI_EXT=.*/m, 'WEBI_EXT=' + rel.ext.replace(/tar.*/, 'tar') ) + .replace( + /^#?WEBI_FORMATS=.*/m, + "WEBI_FORMATS='" + formats.join(',') + "'" + ) .replace( /^#?WEBI_PKG_URL=.*/m, "WEBI_PKG_URL='" + rel.download + "'" diff --git a/_webi/template.sh b/_webi/template.sh index 1b302a2..7a16ae2 100644 --- a/_webi/template.sh +++ b/_webi/template.sh @@ -22,6 +22,7 @@ set -u #WEBI_LTS= #WEBI_CHANNEL= #WEBI_EXT= +#WEBI_FORMATS= #WEBI_PKG_URL= #WEBI_PKG_FILE= WEBI_UA="$(uname -a)" @@ -128,6 +129,12 @@ webi_download() { # TODO pass back requested OS / Arch / Version echo "Error: no '$WEBI_NAME' release found for the given OS and architecture by that tag or version" echo " (check that the package name and version are correct)" + echo "See $WEBI_RELEASES" + echo " WEBI_PKG=$WEBI_PKG" + echo " WEBI_NAME=$WEBI_NAME" + echo " WEBI_VERSION=$WEBI_VERSION" + echo " WEBI_EXT=$WEBI_EXT" + echo " WEBI_FORMATS=$WEBI_FORMATS" exit 1 fi my_url="$WEBI_PKG_URL"