From e6d532747fc717941ca7fd1b6408b0195724dd84 Mon Sep 17 00:00:00 2001 From: casjay Date: Tue, 5 May 2026 14:00:10 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20self-contained=20copy=20and?= =?UTF-8?q?=20symlink=20helper=20scripts=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add `dockerfs/usr/local/bin/copy` for copying files/dirs with progress output - Add `dockerfs/usr/local/bin/symlink` as a wrapper around `ln -sf` with logging - Both scripts include color output, NO_COLOR support, and unlink-before-write safety - Provides standardized helpers for use inside Alpine Docker images dockerfs/usr/local/bin/copy dockerfs/usr/local/bin/symlink --- dockerfs/usr/local/bin/copy | 75 ++++++++++++++++++++++++++++++++++ dockerfs/usr/local/bin/symlink | 64 +++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100755 dockerfs/usr/local/bin/copy create mode 100755 dockerfs/usr/local/bin/symlink diff --git a/dockerfs/usr/local/bin/copy b/dockerfs/usr/local/bin/copy new file mode 100755 index 0000000..b0b53d8 --- /dev/null +++ b/dockerfs/usr/local/bin/copy @@ -0,0 +1,75 @@ +#!/usr/bin/env sh +# shellcheck shell=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202605051306-git +# @@Author : Jason Hempstead +# @@Contact : jason@casjaysdev.pro +# @@License : WTFPL +# @@ReadME : copy --help +# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments +# @@Created : Tuesday, May 05, 2026 13:06 EDT +# @@File : copy +# @@Description : copies a file and shows progress +# @@Changelog : Refactored for self-contained operation +# @@TODO : Better documentation +# @@Other : +# @@Resource : +# @@Terminal App : no +# @@sudo/root : no +# @@Template : shell/sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - +APPNAME="$(basename -- "$0" 2>/dev/null)" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# colorization +if [ -n "$NO_COLOR" ]; then + __printf_color() { printf '%b' "$1\n" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; } +else + __printf_color() { { [ -z "$2" ] || DEFAULT_COLOR=$2; } && printf "%b" "$(tput setaf "$DEFAULT_COLOR" 2>/dev/null)" "$1\n" "$(tput sgr0 2>/dev/null)"; } +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +__unlink() { [ -L "$1" ] && rm -f -- "$1" >/dev/null; } +# - - - - - - - - - - - - - - - - - - - - - - - - - +# custom functions +__copy() { + exitCode=0 + if [ -d "$1" ]; then + __printf_color "Copying $1/* to $2/" + __unlink "$2" + mkdir -p "$2" + cp -Rf "$1"/. "$2"/ + exitCode=$? + elif [ -f "$1" ]; then + __printf_color "Copying $1 to $2" + __unlink "$2" + cp -Rf "$1" "$2" + exitCode=$? + fi + return $exitCode +} +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Define variables +DEFAULT_COLOR="254" +COPY_EXIT_STATUS=0 +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Main application +if [ $# -ne 2 ]; then + __printf_color "USAGE: $APPNAME to from" "1" >&2 + COPY_EXIT_STATUS=1 +elif [ ! -e "$1" ]; then + __printf_color "$1 does not exist" >&2 + COPY_EXIT_STATUS=2 +else + __printf_color "Copying $1 to $2" "4" + __copy "$1" "$2" >/dev/null + COPY_EXIT_STATUS=$? +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +# End application +# - - - - - - - - - - - - - - - - - - - - - - - - - +# lets exit with code +# - - - - - - - - - - - - - - - - - - - - - - - - - +exit $COPY_EXIT_STATUS +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh diff --git a/dockerfs/usr/local/bin/symlink b/dockerfs/usr/local/bin/symlink new file mode 100755 index 0000000..5ec9f0c --- /dev/null +++ b/dockerfs/usr/local/bin/symlink @@ -0,0 +1,64 @@ +#!/usr/bin/env sh +# shellcheck shell=sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202605051306-git +# @@Author : Jason Hempstead +# @@Contact : jason@casjaysdev.pro +# @@License : WTFPL +# @@ReadME : symlink --help +# @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments +# @@Created : Tuesday, May 05, 2026 13:06 EDT +# @@File : symlink +# @@Description : +# @@Changelog : New script +# @@TODO : Better documentation +# @@Other : +# @@Resource : +# @@Terminal App : no +# @@sudo/root : no +# @@Template : shell/sh +# - - - - - - - - - - - - - - - - - - - - - - - - - +# shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 +# - - - - - - - - - - - - - - - - - - - - - - - - - +APPNAME="$(basename -- "$0" 2>/dev/null)" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# colorization +if [ -n "$NO_COLOR" ]; then + __printf_color() { printf '%b' "$1\n" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; } +else + __printf_color() { { [ -z "$2" ] || DEFAULT_COLOR=$2; } && printf "%b" "$(tput setaf "$DEFAULT_COLOR" 2>/dev/null)" "$1\n" "$(tput sgr0 2>/dev/null)"; } +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +__unlink() { [ -L "$1" ] && rm -f -- "$1" >/dev/null; } +# - - - - - - - - - - - - - - - - - - - - - - - - - +# custom functions +__ln_sf() { + __printf_color "symlinking $2 to $1" "4" + __unlink "$2" + ln -sf "$1" "$2" + return $? +} +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Define variables +DEFAULT_COLOR="254" +SYMLINK_EXIT_STATUS=0 +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Main application +if [ $# -ne 2 ]; then + __printf_color "USAGE: $APPNAME from to" "2" >&2 + SYMLINK_EXIT_STATUS=1 +elif [ ! -e "$1" ]; then + __printf_color "$1 does not exist" >&2 + SYMLINK_EXIT_STATUS=2 +else + __ln_sf "$1" "$2" >/dev/null + SYMLINK_EXIT_STATUS=$? +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - +# End application +# - - - - - - - - - - - - - - - - - - - - - - - - - +# lets exit with code +# - - - - - - - - - - - - - - - - - - - - - - - - - +exit $SYMLINK_EXIT_STATUS +# - - - - - - - - - - - - - - - - - - - - - - - - - +# ex: ts=2 sw=2 et filetype=sh