mrrl-logincaps

MRRL version of logincaps
git clone https://ccx.te2000.cz/git/mrrl-logincaps
Log | Files | Refs

commit fb1c6ccbfcfe00747941ca8bddd2c8b22a9bada2
parent c7740ea2debf35723b5728ebbd78d2cab0296cdf
Author: ccx <ccx@te2000.cz>
Date:   Sat, 13 Apr 2024 19:23:04 +0000

Use safe-link for hardlinking between containers

Diffstat:
Mbin/link-to-container-inbox | 27+++++++++++++--------------
Abin/link-to-container-inbox.old | 26++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/bin/link-to-container-inbox b/bin/link-to-container-inbox @@ -1,26 +1,25 @@ -#!/bin/zsh - +#!/bin/sh # usage: src_container dst_container path/to/file [path/to/another ...] +usage() { + printf '%s\n' "usage: link-to-container-inbox src_container dst_container path/to/file [path/to/another ...]" +} -setopt no_unset no_chase_links +if test $# -lt 3 || test -z "$1" || test -z "$2"; then + usage + exit 100 +fi -(( $# >= 3 )) || exit 100 src_container=$1 dst_container=$2 shift 2 || exit 100 -[[ -z $src_container || $src_container == */* ]] && exit 100 -[[ -z $dst_container || $dst_container == */* ]] && exit 100 - containers_dir=/run/containers +safe_link_executable=safe-link + +case $src_container in (*/*) usage; exit 100;; esac +case $dst_container in (*/*) usage; exit 100;; esac for f in "$@"; do src=$containers_dir/$src_container/${f#/} - [[ $src == ${src:a} ]] || exit 100 # check for non-canonical path (eg. containing ../) dst=$containers_dir/$dst_container/run/inbox/$src_container/$f - mkdir -p ${dst:h} || exit $? - if [[ -d $dst ]]; then - rm -rf $dst || exit $? - fi - cd -s ${src:h} || exit $? # should fail if there is a symlink in the path - ln -f ./${src:t} $dst || exit $? + "$safe_link_executable" "$src" "$dst" done diff --git a/bin/link-to-container-inbox.old b/bin/link-to-container-inbox.old @@ -0,0 +1,26 @@ +#!/bin/zsh + +# usage: src_container dst_container path/to/file [path/to/another ...] + +setopt no_unset no_chase_links + +(( $# <= 3 )) || exit 100 +src_container=$1 +dst_container=$2 +shift 2 || exit 100 +[[ -z $src_container || $src_container == */* ]] && exit 100 +[[ -z $dst_container || $dst_container == */* ]] && exit 100 + +containers_dir=/run/containers + +for f in "$@"; do + src=$containers_dir/$src_container/${f#/} + [[ $src == ${src:a} ]] || exit 100 # check for non-canonical path (eg. containing ../) + dst=$containers_dir/$dst_container/run/inbox/$src_container/$f + mkdir -p ${dst:h} || exit $? + if [[ -d $dst ]]; then + rm -rf $dst || exit $? + fi + cd -s ${src:h} || exit $? # should fail if there is a symlink in the path + ln -f ./${src:t} $dst || exit $? +done