#!/bin/bash # $HeadURL: https://svn.pasta.freemyip.com/main/miniade/trunk/bin/nop-sh $ $LastChangedRevision: 10133 $ # Notes to users: # # (C) 2021-2024 Alexis Huxley - distributed under GPL3 - absolutely no warranty! # # BE VERY VERY CAREFUL not to run this script against something other than # a container directory! You do not want to change the ownership/groupship # of files installed on your actual host!!! # # Modules . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } # Configurable stuff # Other globals main() { local MY_ARGS local MODE RECIPE_TITLE OUTPUT_FILE PROGNAME # Defaults for options OUTPUT_FILE= # Process options special_opts_handler() { case $1 in -o) OUTPUT_FILE=$2 extra_shift ;; --html) MODE=html ;; --pdf) MODE=pdf ;; *) return 1 ;; esac } miniade_process_options --help-handler=help --special-opts-handler=special_opts_handler MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments [ $# = 3 ] || miniade_bad_usage DIR=$1 UID_OFFSET=$2 GID_OFFSET=$3 # Sanity checks and derivations [ -d "$DIR" ] || miniade_error "$DIR: directory not found" [[ $UID_OFFSET =~ ^-?[1-9][0-9]*$ ]] || miniade_error "$UID_OFFSET: invalid UID offset" [[ $GID_OFFSET =~ ^-?[1-9][0-9]*$ ]] || miniade_error "$GID_OFFSET: invalid GID offset" perl -e 'use File::Find;' 2>/dev/null || miniade_error "File::Find: perl module not installed" perl -e 'use File::lchown;' 2>/dev/null || miniade_error "File::lchown: perl module not installed" # Guts perl -e 'use File::Find; use File::lchown qw( lchown ); ($dir, $uid_offset, $gid_offset) = @ARGV; %dev_ino_tuples = (); sub wanted { lstat $_; # Ignore second hardlinks by ignoring device/inode numbers already encountered. return if defined $dev_ino_tuples[(lstat _)[0] + ";" + (lstat _)[1]]; # chown. lchown ((lstat _)[4]+$uid_offset, (lstat _)[5]+$gid_offset, $_); # Note we have seen this device/inode. $dev_ino_tuples[(lstat _)[0] + ";" + (lstat _)[1]] = 1; } find(\&wanted, $dir);' "$DIR" "$UID_OFFSET" "$GID_OFFSET" } help() { local PROGNAME miniade_get_progname PROGNAME echo "Usage: $PROGNAME [ ] " exit 0 } main "$@"