diff --git a/sing-box/README.md b/sing-box/README.md new file mode 100644 index 000000000..cb5eb6499 --- /dev/null +++ b/sing-box/README.md @@ -0,0 +1,41 @@ +--- +title: sing-box +homepage: https://sing-box.sagernet.org/ +tagline: | + The universal proxy platform. +--- + + + +To update or switch versions, run `webi example@stable` (or `@v2`, `@beta`, +etc). + +### Files + +These are the files / directories that are created and/or modified with this +install: + +```text +~/.config/envman/PATH.env +~/.local/bin/sing-box +~/.local/opt/sing-box +``` + +To run sing-box: + +```sh +sing-box +``` + +### Add Baz Highlighting + +To run sing-box with both bar and baz highlighting turned on: + +```sh +sing-box --bar=baz +``` diff --git a/sing-box/install.ps1 b/sing-box/install.ps1 new file mode 100644 index 000000000..0a6ac5559 --- /dev/null +++ b/sing-box/install.ps1 @@ -0,0 +1,61 @@ +#!/usr/bin/env pwsh + +################## +# Install sing-box # +################## + +# Every package should define these variables +$pkg_cmd_name = "sing-box" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\sing-box.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\sing-box-v$Env:WEBI_VERSION\bin\sing-box.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\sing-box-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\sing-box-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | out-null +$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE")) +{ + echo "Downloading sing-box 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 sing-box" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\sing-box-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\sing-box.exe" -Recurse -ErrorAction Ignore + + # NOTE: DELETE THIS COMMENT IF NOT USED + # Move single binary into root of temporary folder + #& move "$pkg_download" "sing-box.exe" + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force | out-null + Move-Item -Path ".\sing-box-*\sing-box.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 | out-null +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/sing-box/install.sh b/sing-box/install.sh new file mode 100644 index 000000000..0af341014 --- /dev/null +++ b/sing-box/install.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# shellcheck disable=SC2034 +# "'pkg_cmd_name' appears unused. Verify it or export it." + +__init_sing_box() { + set -e + set -u + + ################## + # Install sing-box # + ################## + + # Every package should define these 6 variables + pkg_cmd_name="sing-box" + + pkg_dst_cmd="$HOME/.local/bin/sing-box" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/sing-box-v$WEBI_VERSION/bin/sing-box" + pkg_src_dir="$HOME/.local/opt/sing-box-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/sing-box-v0.99.9/bin + mkdir -p "$(dirname "${pkg_src_cmd}")" + + # mv ./sing-box-*/sing-box ~/.local/opt/sing-box-v0.99.9/bin/sing-box + mv ./sing-box-*/sing-box "${pkg_src_cmd}" + } + + # pkg_get_current_version is recommended, but not required + pkg_get_current_version() { + # 'sing-box --version' has output in this format: + # sing-box 0.99.9 (rev abcdef0123) + # This trims it down to just the version number: + # 0.99.9 + sing-box --version 2> /dev/null | + head -n 1 | + cut -d ' ' -f 2 + } + +} + +__init_sing_box diff --git a/sing-box/releases.js b/sing-box/releases.js new file mode 100644 index 000000000..055ae2387 --- /dev/null +++ b/sing-box/releases.js @@ -0,0 +1,20 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'SagerNet'; +var repo = 'sing-box'; + +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) { + 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/test/install.sh b/test/install.sh index 7e0b4bcb7..32f63814d 100644 --- a/test/install.sh +++ b/test/install.sh @@ -72,6 +72,7 @@ __rmrf_local() { setcap-netbind \ shellcheck \ shfmt \ + sing-box \ sqlpkg \ ssh-pubkey \ ssh-utils \ @@ -168,6 +169,7 @@ __rmrf_local() { setcap-netbind \ shellcheck \ shfmt \ + sing-box \ sqlpkg \ ssh-pubkey \ ssh-utils \ @@ -269,6 +271,7 @@ __test() { setcap-netbind \ shellcheck \ shfmt \ + sing-box \ sqlpkg \ ssh-pubkey \ ssh-utils \