mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-05-31 21:12:46 +00:00
Compare commits
11 Commits
feat-shell
...
add-ffprob
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3319dffe94 | ||
|
|
2fe6824472 | ||
|
|
4510a61cf0 | ||
|
|
0da4b5d7cd | ||
|
|
948030b9cb | ||
|
|
faaed1d2ec | ||
|
|
6875648daf | ||
|
|
e8ba56e75f | ||
|
|
1f858bca4d | ||
|
|
f10be58d64 | ||
|
|
79ded46033 |
@@ -853,7 +853,7 @@ fn_envman_init_load_sh() { (
|
||||
touch -a ~/.config/envman/PATH.env
|
||||
touch -a ~/.config/envman/ENV.env
|
||||
touch -a ~/.config/envman/alias.env
|
||||
touch -a ~/.config/envman/function.env
|
||||
touch -a ~/.config/envman/function.sh
|
||||
|
||||
# ENV first because we may use it in PATH
|
||||
test -z "\${ENVMAN_LOAD:-}" && . ~/.config/envman/ENV.env
|
||||
@@ -862,7 +862,7 @@ test -z "\${ENVMAN_LOAD:-}" && . ~/.config/envman/PATH.env
|
||||
export ENVMAN_LOAD='loaded'
|
||||
|
||||
# function first because we may use it in alias
|
||||
test -z "\${g_envman_load_sh:-}" && . ~/.config/envman/function.env
|
||||
test -z "\${g_envman_load_sh:-}" && . ~/.config/envman/function.sh
|
||||
test -z "\${g_envman_load_sh:-}" && . ~/.config/envman/alias.env
|
||||
|
||||
g_envman_load_sh='loaded'
|
||||
@@ -918,14 +918,14 @@ fn_envman_init_load_fish() { (
|
||||
touch -a ~/.config/envman/PATH.env
|
||||
touch -a ~/.config/envman/ENV.env
|
||||
touch -a ~/.config/envman/alias.env
|
||||
touch -a ~/.config/envman/function.env
|
||||
touch -a ~/.config/envman/function.fish
|
||||
|
||||
not set -q ENVMAN_LOAD; and source ~/.config/envman/ENV.env
|
||||
not set -q ENVMAN_LOAD; and source ~/.config/envman/PATH.env
|
||||
|
||||
set -x ENVMAN_LOAD 'loaded'
|
||||
|
||||
not set -q g_envman_load_fish; and source ~/.config/envman/function.env
|
||||
not set -q g_envman_load_fish; and source ~/.config/envman/function.fish
|
||||
not set -q g_envman_load_fish; and source ~/.config/envman/alias.env
|
||||
|
||||
set -g g_envman_load_fish 'loaded'
|
||||
|
||||
45
ffprobe/releases.js
Normal file
45
ffprobe/releases.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var github = require('../_common/github.js');
|
||||
var owner = 'eugeneware';
|
||||
var repo = 'ffmpeg-static';
|
||||
|
||||
module.exports = function (request) {
|
||||
return github(request, owner, repo).then(function (all) {
|
||||
all.releases = all.releases
|
||||
.filter(function (rel) {
|
||||
let isFfmpeg = rel.name.includes('ffmpeg');
|
||||
if (!isFfmpeg) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove README and LICENSE
|
||||
return !['.README', '.LICENSE'].includes(path.extname(rel.name));
|
||||
})
|
||||
.map(function (rel) {
|
||||
rel.version = rel.version.replace(/^b/, '');
|
||||
|
||||
if (/win32/.test(rel.name)) {
|
||||
rel.os = 'windows';
|
||||
rel.ext = 'exe';
|
||||
}
|
||||
if (/ia32/.test(rel.name)) {
|
||||
rel.arch = '386';
|
||||
} else if (/x64/.test(rel.name)) {
|
||||
rel.arch = 'amd64';
|
||||
}
|
||||
|
||||
return rel;
|
||||
});
|
||||
return all;
|
||||
});
|
||||
};
|
||||
|
||||
if (module === require.main) {
|
||||
module.exports(require('@root/request')).then(function (all) {
|
||||
all = require('../_webi/normalize.js')(all);
|
||||
console.info(JSON.stringify(all));
|
||||
});
|
||||
}
|
||||
@@ -118,7 +118,7 @@ fn_polite_sudo() { (
|
||||
# this is user interactive, ask the user,defaulting to yes
|
||||
echo ""
|
||||
#shellcheck disable=SC2005 # echo for newline
|
||||
echo "$(t_attn 'Use sudo for the following? [Y/n])')"
|
||||
echo "$(t_attn 'Use sudo for the following? [Y/n]')"
|
||||
echo "${a_cmds}"
|
||||
read -r b_yes < /dev/tty
|
||||
|
||||
|
||||
338
webi/webi.sh
338
webi/webi.sh
@@ -152,7 +152,7 @@ __webi_main() {
|
||||
my_checksum="$(
|
||||
fn_checksum
|
||||
)"
|
||||
my_version=v1.2.0
|
||||
my_version=v1.2.8
|
||||
printf "\e[35mwebi\e[32m %s\e[0m Copyright 2020+ AJ ONeal\n" "${my_version} (${my_checksum})"
|
||||
printf " \e[36mhttps://webinstall.dev/webi\e[0m\n"
|
||||
}
|
||||
@@ -188,6 +188,8 @@ __webi_main() {
|
||||
echo " Output the version number of webi and exit."
|
||||
echo ""
|
||||
echo " Helper Utilities"
|
||||
echo " --init Register command line completions with shell"
|
||||
echo ""
|
||||
echo " --list Show everything webi has to offer."
|
||||
echo ""
|
||||
echo " --info <package>"
|
||||
@@ -212,71 +214,18 @@ __webi_main() {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if echo "$1" | grep -q -E '^(-l|--list|list)$'; then
|
||||
echo >&2 "[warn] the format of --list output may change"
|
||||
|
||||
# because we don't have sitemap.xml for dev sites yet
|
||||
my_host="https://webinstall.dev"
|
||||
my_len="${#my_host}"
|
||||
|
||||
# 6 because the field will looks like "loc>WEBI_HOST/PKG_NAME"
|
||||
# and the count is 1-indexed
|
||||
my_count="$((my_len + 6))"
|
||||
|
||||
curl -fsS "${my_host}/sitemap.xml" |
|
||||
grep -F "${my_host}" |
|
||||
cut -d'<' -f2 |
|
||||
cut -c "${my_count}"-
|
||||
|
||||
if echo "$1" | grep -q -E '^(--list|list)$'; then
|
||||
webi_list
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if echo "${1}" | grep -q -E '^(--info|info)$'; then
|
||||
if test -z "${2}"; then
|
||||
echo >&2 "Usage: webi --info <package>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo >&2 "[warn] the output of --info is completely half-baked and will change"
|
||||
my_pkg="${2}"
|
||||
# TODO need a way to check that it exists at all (readme, win, lin)
|
||||
echo ""
|
||||
echo " Cheat Sheet: ${WEBI_HOST}/${my_pkg}"
|
||||
echo " POSIX: curl -sS ${WEBI_HOST}/${my_pkg} | sh"
|
||||
echo " Windows: curl.exe -A MS ${WEBI_HOST}/${my_pkg} | powershell"
|
||||
echo "Releases (JSON): ${WEBI_HOST}/api/releases/${my_pkg}.json"
|
||||
echo " Releases (tsv): ${WEBI_HOST}/api/releases/${my_pkg}.tab"
|
||||
echo " (query params): ?channel=stable&limit=10"
|
||||
echo " &os=${my_os}&arch=${my_arch}"
|
||||
echo " Install Script: ${WEBI_HOST}/api/installers/${my_pkg}.sh?formats=tar,zip,xz,git,dmg,pkg"
|
||||
echo " Static Assets: ${WEBI_HOST}/packages/${my_pkg}/README.md"
|
||||
echo ""
|
||||
|
||||
# TODO os=linux,macos,windows (limit to tagged releases)
|
||||
my_releases="$(
|
||||
curl -fsS "${WEBI_HOST}/api/releases/${my_pkg}.json?channel=stable&limit=1&pretty=true"
|
||||
)"
|
||||
|
||||
if printf '%s\n' "${my_releases}" | grep -q "error"; then
|
||||
my_releases_beta="$(
|
||||
curl -fsS "${WEBI_HOST}/api/releases/${my_pkg}.json?&limit=1&pretty=true"
|
||||
)"
|
||||
if printf '%s\n' "${my_releases_beta}" | grep -q "error"; then
|
||||
echo >&2 "'${my_pkg}' is a special case that does not have releases"
|
||||
else
|
||||
echo >&2 "ERROR no stable releases for '${my_pkg}'!"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo >&2 "Stable '${my_pkg}' releases:"
|
||||
if command -v jq > /dev/null; then
|
||||
printf '%s\n' "${my_releases}" |
|
||||
jq
|
||||
else
|
||||
printf '%s\n' "${my_releases}"
|
||||
fi
|
||||
webi_info "$@"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if echo "$1" | grep -q -E '^(--init|init)$'; then
|
||||
webi_shell_init "$@"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -289,4 +238,271 @@ __webi_main() {
|
||||
|
||||
}
|
||||
|
||||
webi_shell_init() { (
|
||||
a_shell="${2:-}"
|
||||
|
||||
fn_shell_integrate_bash ""
|
||||
fn_shell_integrate_zsh ""
|
||||
fn_shell_integrate_fish ""
|
||||
|
||||
# update completions now
|
||||
webi_list > /dev/null
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "${a_shell}" in
|
||||
bash)
|
||||
fn_shell_integrate_bash "force"
|
||||
fn_shell_init_bash
|
||||
;;
|
||||
zsh)
|
||||
fn_shell_integrate_zsh "force"
|
||||
fn_shell_init_zsh
|
||||
;;
|
||||
fish)
|
||||
fn_shell_integrate_fish "force"
|
||||
fn_shell_init_fish
|
||||
;;
|
||||
*)
|
||||
echo >&2 "Unsupported shell: $2"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
) }
|
||||
|
||||
fn_shell_integrate_bash() { (
|
||||
a_force="${1}"
|
||||
if test -z "${a_force}"; then
|
||||
if ! command -v bash > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! test -e ~/.bashrc && ! test -e ~/.bash_history; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
touch -a ~/.bashrc
|
||||
if grep -q 'webi --init' ~/.bashrc; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo >&2 " Edit ~/.bashrc to add 'eval \"\$(webi --init bash)\"'"
|
||||
# shellcheck disable=SC2016
|
||||
{
|
||||
echo ''
|
||||
echo '# Generated by Webi. Do not edit.'
|
||||
echo 'eval "$(webi --init bash)"'
|
||||
} >> ~/.bashrc
|
||||
); }
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
fn_shell_init_bash() { (
|
||||
echo '_webi() {'
|
||||
echo ' COMPREPLY=()'
|
||||
echo ' local cur="${COMP_WORDS[COMP_CWORD]}"'
|
||||
echo ' if [ "$COMP_CWORD" -eq 1 ]; then'
|
||||
echo ' local completions=$(webi --list | cut -d" " -f1)'
|
||||
echo ' COMPREPLY=( $(compgen -W "$completions" -- "$cur") )'
|
||||
echo ' fi'
|
||||
echo '}'
|
||||
echo ''
|
||||
echo 'complete -F _webi webi'
|
||||
); }
|
||||
|
||||
fn_shell_integrate_zsh() { (
|
||||
a_force="${1}"
|
||||
if test -z "${a_force}"; then
|
||||
if ! command -v zsh > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! test -e ~/.zshrc &&
|
||||
! test -e ~/.zsh_sessions &&
|
||||
! test -e ~/.zsh_history; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
touch -a ~/.zshrc
|
||||
if grep -q 'webi --init' ~/.zshrc; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo >&2 " Edit ~/.zshrc to add 'eval \"\$(webi --init zsh)\"'"
|
||||
# shellcheck disable=SC2016
|
||||
{
|
||||
echo ''
|
||||
echo '# Generated by Webi. Do not edit.'
|
||||
echo 'eval "$(webi --init zsh)"'
|
||||
} >> ~/.zshrc
|
||||
); }
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
fn_shell_init_zsh() { (
|
||||
echo '_webi() {'
|
||||
echo ' local -a list completions'
|
||||
echo ' list=$(webi --list | cut -d" " -f1)'
|
||||
echo ' completions=(${(f)list})'
|
||||
echo ' _describe -t commands "command" completions && ret=0'
|
||||
echo '}'
|
||||
echo ''
|
||||
echo 'autoload -Uz compinit && compinit'
|
||||
echo 'compdef _webi webi'
|
||||
); }
|
||||
|
||||
fn_shell_integrate_fish() { (
|
||||
a_force="${1}"
|
||||
if test -z "${a_force}"; then
|
||||
if ! command -v fish > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p ~/.config/fish
|
||||
touch -a ~/.config/fish/config.fish
|
||||
if grep -q 'webi --init' ~/.config/fish/config.fish; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo >&2 " Edit ~/.config/fish/config.fish to add 'webi --init fish | source'"
|
||||
# shellcheck disable=SC2016
|
||||
{
|
||||
echo ''
|
||||
echo '# Generated by Webi. Do not edit.'
|
||||
echo 'webi --init fish | source'
|
||||
} >> ~/.config/fish/config.fish
|
||||
); }
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
fn_shell_init_fish() { (
|
||||
echo 'function __fish_webi_needs_command'
|
||||
echo ' set cmd (commandline -opc)'
|
||||
echo ' if [ (count $cmd) -eq 1 -a $cmd[1] = "webi" ]'
|
||||
echo ' return 0'
|
||||
echo ' end'
|
||||
echo ' return 1'
|
||||
echo 'end'
|
||||
echo ''
|
||||
echo 'set completions (webi --list | cut -d" " -f1)'
|
||||
echo 'complete -f -c webi -n __fish_webi_needs_command -a "$completions"'
|
||||
); }
|
||||
|
||||
webi_list() { (
|
||||
# make sure there's always a cache dir and timestamp file
|
||||
mkdir -p ~/.local/share/webi/var/
|
||||
|
||||
if ! test -r ~/.local/share/webi/var/list.txt; then
|
||||
echo '0' > ~/.local/share/webi/var/last_update
|
||||
elif ! test -r ~/.local/share/webi/var/last_update; then
|
||||
echo '0' > ~/.local/share/webi/var/last_update
|
||||
fi
|
||||
|
||||
# compare the timestamp in the timestamp file to now
|
||||
# (in seconds since unix epoch)
|
||||
my_stale_age=600
|
||||
my_expire_age=900
|
||||
my_now="$(date -u '+%s')"
|
||||
my_then="$(cat ~/.local/share/webi/var/last_update)"
|
||||
my_diff=$((my_now - my_then))
|
||||
|
||||
# show when the cache will update
|
||||
my_stales_in=$((my_stale_age - my_diff))
|
||||
my_expires_in=$((my_expire_age - my_diff))
|
||||
|
||||
# update if it's been longer than the staletime
|
||||
if test "${my_stales_in}" -lt "0"; then
|
||||
if test "${my_expires_in}" -lt "0"; then
|
||||
fn_list_uncached
|
||||
else
|
||||
fn_list_uncached &
|
||||
fi
|
||||
fi
|
||||
|
||||
# give back the list
|
||||
cat ~/.local/share/webi/var/list.txt
|
||||
); }
|
||||
|
||||
fn_list_uncached() { (
|
||||
# because we don't have sitemap.xml for dev sites yet
|
||||
my_host="https://webinstall.dev"
|
||||
|
||||
my_len="${#my_host}"
|
||||
# 6 because the field will looks like "loc>WEBI_HOST/PKG_NAME"
|
||||
# and the count is 1-indexed
|
||||
my_count="$((my_len + 6))"
|
||||
|
||||
my_now="$(date -u '+%s')"
|
||||
echo "${my_now}" > ~/.local/share/webi/var/last_update
|
||||
|
||||
my_tmp="$(mktemp)"
|
||||
{
|
||||
echo "help"
|
||||
echo "--help"
|
||||
echo "version"
|
||||
echo "-V"
|
||||
echo "--version"
|
||||
echo "--init" # <shell>
|
||||
echo "--list"
|
||||
echo "--info" # <package>
|
||||
} > "${my_tmp}"
|
||||
curl -fsS "${my_host}/sitemap.xml" |
|
||||
grep -F "${my_host}" |
|
||||
cut -d'<' -f2 |
|
||||
cut -c "${my_count}"- >> "${my_tmp}"
|
||||
mv "${my_tmp}" ~/.local/share/webi/var/list.txt
|
||||
|
||||
my_now="$(date -u '+%s')"
|
||||
echo "${my_now}" > ~/.local/share/webi/var/last_update
|
||||
); }
|
||||
|
||||
webi_info() { (
|
||||
if test -z "${2}"; then
|
||||
echo >&2 "Usage: webi --info <package>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo >&2 "[warn] the output of --info is completely half-baked and will change"
|
||||
my_pkg="${2}"
|
||||
# TODO need a way to check that it exists at all (readme, win, lin)
|
||||
echo ""
|
||||
echo " Cheat Sheet: ${WEBI_HOST}/${my_pkg}"
|
||||
echo " POSIX: curl -sS ${WEBI_HOST}/${my_pkg} | sh"
|
||||
echo " Windows: curl.exe -A MS ${WEBI_HOST}/${my_pkg} | powershell"
|
||||
echo "Releases (JSON): ${WEBI_HOST}/api/releases/${my_pkg}.json"
|
||||
echo " Releases (tsv): ${WEBI_HOST}/api/releases/${my_pkg}.tab"
|
||||
echo " (query params): ?channel=stable&limit=10"
|
||||
echo " &os=${my_os}&arch=${my_arch}"
|
||||
echo " Install Script: ${WEBI_HOST}/api/installers/${my_pkg}.sh?formats=tar,zip,xz,git,dmg,pkg"
|
||||
echo " Static Assets: ${WEBI_HOST}/packages/${my_pkg}/README.md"
|
||||
echo ""
|
||||
|
||||
# TODO os=linux,macos,windows (limit to tagged releases)
|
||||
my_releases="$(
|
||||
curl -fsS "${WEBI_HOST}/api/releases/${my_pkg}.json?channel=stable&limit=1&pretty=true"
|
||||
)"
|
||||
|
||||
if printf '%s\n' "${my_releases}" | grep -q "error"; then
|
||||
my_releases_beta="$(
|
||||
curl -fsS "${WEBI_HOST}/api/releases/${my_pkg}.json?&limit=1&pretty=true"
|
||||
)"
|
||||
if printf '%s\n' "${my_releases_beta}" | grep -q "error"; then
|
||||
echo >&2 "'${my_pkg}' is a special case that does not have releases"
|
||||
else
|
||||
echo >&2 "ERROR no stable releases for '${my_pkg}'!"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo >&2 "Stable '${my_pkg}' releases:"
|
||||
if command -v jq > /dev/null; then
|
||||
printf '%s\n' "${my_releases}" |
|
||||
jq
|
||||
else
|
||||
printf '%s\n' "${my_releases}"
|
||||
fi
|
||||
); }
|
||||
|
||||
__webi_main "$@"
|
||||
|
||||
Reference in New Issue
Block a user