109.6. croc-11.5.3
One-off file transfer by code phrase, kept on this network
| Version | 11.5.3, release 1 |
| Shelf | transfer — File transfer, synchronisation, backup and BitTorrent |
| Phase | 41_system (System), 981 of 1047 in build order |
| Licence | MIT |
| Homepage | https://github.com/schollz/croc |
| Build time | 0.2 SBU |
| Installed size | 10.5 MiB in 4 files |
| Recipe | ports/core/transfer/croc/kpkgbuild |
About
croc sends a file or a directory from one machine to another, the receiver typing a code phrase the sender shows. On KDOS /usr/bin/croc is a small shell wrapper that runs the real binary with --local, which keeps the transfer to direct connections on the local network. Without it croc looks for the peer on the local network and connects to its public relay on the internet at the same time, and carries the transfer over whichever answers first, without saying which. The unwrapped binary is installed as croc-relay, for a transfer that is meant to go through the relay.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/transfer.txt:
The default relay is a host on the internet and croc falls back to it SILENTLY, so the shipped wrapper is
croc --local.
Sources
croc-11.5.3.tar.gz(3.2 MiB)
sha256194ec2494f1801d7baa597d30ab6571f4a25f645cf0527aa7a4b66cd5b7a6fa8
upstream: https://github.com/schollz/croc/archive/refs/tags/v11.5.3.tar.gz
archive copy: sources-4/transfer--croc-11.5.3.tar.gzcroc-vendor-11.5.3.tar.xz(5.6 MiB)
sha25640ece0dedbd2dacafd047e011b5d13fca6f0309978c6f2dcc0b36ce4771c023a
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-4/transfer--croc-vendor-11.5.3.tar.xz
Dependencies
Depends on: go.
Required by (1): kdos-tools.
Patches
build.sh applies these; kpkg applies nothing by itself.
disable-update-check.patch— drop the release check from send and receive, and own /usr/bin/croc-relaysend() and receive() start a background request to api.github.com for the latest release, which --local does not stop and --quiet only hides; without the two calls a transfer makes no connection but the transfer's own. `croc update` stays, and asks only when it is run.
The KDOS package installs the binary as /usr/bin/croc-relay behind a /usr/bin/croc wrapper. Naming that path beside /usr/bin/croc makes `croc update` answer, without a network request, that the system package manager updates it, instead of pointing at the upstream installer.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install croc'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/transfer/croc.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/transfer/croc
echo '194ec2494f1801d7baa597d30ab6571f4a25f645cf0527aa7a4b66cd5b7a6fa8 croc-11.5.3.tar.gz' | sha256sum -c -
echo '40ece0dedbd2dacafd047e011b5d13fca6f0309978c6f2dcc0b36ce4771c023a croc-vendor-11.5.3.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/croc
SRC=$SRC_ROOT/croc-11.5.3
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf croc-11.5.3.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i "$PORT_SRC/disable-update-check.patch"
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export CGO_ENABLED=0
go build -mod=vendor \
-tags croc_no_tailcat,ts_omit_webclient,ts_omit_debugeventbus \
-ldflags "-s -w -X main.Version=$version" -o croc.bin
install -Dm755 croc.bin $PKG/usr/bin/croc-relay
install -Dm644 packaging/croc.1 -t "$PKG/usr/share/man/man1"
install -Dm755 /dev/stdin $PKG/usr/bin/croc <<'SH'
#!/bin/sh
# --local keeps the transfer on this network. `croc-relay` is the same binary
# with upstream's default, for when reaching the public relay is the intent.
exec /usr/bin/croc-relay --local "$@"
SH
The switches, and why each is set:
-tags croc_no_tailcat— croc’s relay-only build. It leaves out the Tailcat transport, a WireGuard path that falls back to Tailscale’s DERP relay servers, andcroc ssh, which is built on it and has no--localof its own; with them goes most of the vendored Tailscale code they pull in.croc sshthen answers that it is not supported in this build.ts_omit_webclient,ts_omit_debugeventbus— Tailscale’s own feature tags, in the same-tagslist. They leave out Tailscale’s web client and its event-bus debug page, which embed web assets that arrive minified, such ashtmx.min.js.gz. Withcroc_no_tailcatnothing in the build imports either; the tags keep them out even if croc reaches that code by another route.-X main.Version=$version— Names a variable croc’smainpackage does not declare: the versioncroc --versionprints is the constant insrc/version, the source’s own, and the Go linker ignores an-Xthat names no variable.CGO_ENABLED=0— Build without cgo, as upstream’s own makefile does.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/croc, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf croc-11.5.3-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/croc, and runs the triggers its paths call for.
Contents
Installed programs: croc, croc-relay.
Installed directories: /usr/share/licenses/croc.
Short descriptions
croc |
transfer files, directories, and text using a short code |
Notes
The modules come from the vendor bundle, croc-vendor-<version>.tar.xz, made by ports/fetch with go mod vendor and used with -mod=vendor (see Vendoring). The binary is built as croc.bin and installed under its other name; the manual page, croc.1, describes the command as upstream ships it.
A send or a receive makes no request of its own for croc’s latest release: disable-update-check.patch removes the background check upstream starts with each, which --local does not stop. croc update answers, with no request, that the system package manager updates croc, and replaces nothing; croc update --check asks api.github.com when it is run.