From: AJ ONeal Date: Tue, 17 Nov 2020 11:00:54 +0000 (+0000) Subject: add xz X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=713e44b7d96290daac344ce79bfa34736691fbee;p=webi-installers%2F.git add xz --- diff --git a/xz/README.md b/xz/README.md new file mode 100644 index 0000000..ccefcc7 --- /dev/null +++ b/xz/README.md @@ -0,0 +1,53 @@ +--- +title: XZ Utils +homepage: https://tukaani.org/xz/ +tagline: | + XZ Utils is free general-purpose data compression software with a high compression ratio. +--- + +### Updating `xz` + +`webi xz@stable` + +The Windows builds are the official builds. The Mac and Linux builds are from +[github.com/therootcompany/xz-static](https://github.com/therootcompany/xz-static). + +## Cheat Sheet + +`xz` and `unxz` are modern alternatives to `gzip` (and `gunzip`). They use LZMA2 +(de)compression (like 7z), and is supported across many platforms, and by `tar`. + +Here's the shortlist of options we've found most useful: + +```txt +-z, --compress force compression +-d, --decompress force decompression +-l, --list list information about .xz files + +-k, --keep keep (don't delete) input files +-c, --stdout write to standard output and don't delete input files + +-0 ... -9 (de)compression can take up to 4gb RAM at 7-9 (default 6) +-e, --extreme try to improve compression ratio by using more CPU time +-T, --threads=N use up to N threads; set to 0 to match CPU cores (default 1) +``` + +### How to "Unzip" + +```bash +unxz -k example.xz +``` + +```bash +tar xvf example.tar.xz +``` + +### How to "Zip" + +```bash +xz -k ./example +``` + +```bash +tar cvf example.tar.xz ./example +``` diff --git a/xz/install.ps1 b/xz/install.ps1 new file mode 100644 index 0000000..8d893e3 --- /dev/null +++ b/xz/install.ps1 @@ -0,0 +1,55 @@ +#!/usr/bin/env pwsh + +############## +# Install xz # +############## + +# Every package should define these variables +$pkg_cmd_name = "xz" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\xz.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\xz-v$Env:WEBI_VERSION\bin\xz.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\xz-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\xz-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 xz 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 xz" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + 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 + Move-Item -Path ".\bin_x86-64\xz.exe" -Destination "$pkg_src_bin" + Move-Item -Path ".\bin_x86-64\xzdec.exe" -Destination "$pkg_src_bin" + Copy-Item -Path "$pkg_src_bin\xzdec.exe" -Destination "$pkg_src_bin\unxz.exe" + Move-Item -Path ".\bin_x86-64\lzmadec.exe" -Destination "$pkg_src_bin" + Copy-Item -Path "$pkg_src_bin\lzmadec.exe" -Destination "$pkg_src_bin\unlzma.exe" + + # 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/xz/install.sh b/xz/install.sh new file mode 100644 index 0000000..54beb4c --- /dev/null +++ b/xz/install.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +{ + set -e + set -u + + ############## + # Install xz # + ############## + + # Every package should define these 6 variables + pkg_cmd_name="xz" + + pkg_dst_cmd="$HOME/.local/bin/xz" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/xz-v$WEBI_VERSION/bin/xz" + pkg_src_dir="$HOME/.local/opt/xz-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/xz-v5.2.5/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./xz-*/{xz,xzdec} ~/.local/opt/xz-v5.2.5/bin/ + mv ./xz-*/xz* "$(dirname $pkg_src_cmd)" + ln -s xz "$(dirname $pkg_src_cmd)/unxz" + } + + pkg_post_install() { + # supplements webi_link + ln -s xz "$(dirname $pkg_dst_cmd)/unxz" + + webi_post_install + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'xz --version' has output in this format: + # xz (XZ Utils) 5.2.5 + # liblzma 5.2.5 + # This trims it down to just the version number: + # 5.2.5 + echo $(xz --version 2>/dev/null | head -n 1 | cut -d ' ' -f 4) + } +} diff --git a/xz/releases.js b/xz/releases.js new file mode 100644 index 0000000..75717a0 --- /dev/null +++ b/xz/releases.js @@ -0,0 +1,27 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'therootcompany'; +var repo = 'xz-static'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + all.releases.forEach(function (rel) { + if (/windows/.test(rel.download)) { + if (!/(86|64)/.test(rel.arch)) { + rel.arch = 'amd64'; + } + } + }); + 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)); + }); +}