From a21b588d083e9be0e853113eb8cb89f8c9776300 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Thu, 11 Feb 2021 18:29:28 -0800 Subject: [PATCH] added group_add and user_reload to basic functions switched to acl functions loaded via module load rysnc add ignore cache add chmod_dirs to helpers --- function/01-basic | 16 +++++++++++- function/acl | 52 +------------------------------------ function/rsync | 2 +- modules/utility/helpers.mod | 8 ++++++ 4 files changed, 25 insertions(+), 53 deletions(-) diff --git a/function/01-basic b/function/01-basic index b81f2f7..88f9a94 100644 --- a/function/01-basic +++ b/function/01-basic @@ -3,7 +3,21 @@ ##-- functions which may be used by any of the alias file --# -function function_list() { +group_add() { + [[ ! $(getent group $1) ]] && echo "no group $1, aborting" && return 1 + echo adding group $1 to $USER + sudo usermod -a -G $1 $USER +} + +user_reload() { + save=$PWD + exec su -l $USER + cd $save + +} + + +function function_list { if [ $1 ]; then # will list functions in passed file local STR diff --git a/function/acl b/function/acl index ea8e0a1..468fb51 100644 --- a/function/acl +++ b/function/acl @@ -1,51 +1 @@ -#!/bin/bash -acluserdir() { - module_load confirm - local uid - local usesudo - local del - local spec - local cmd="-R -m " - local cmdd="-dR -m" - if [[ $1 == "-d" ]]; then - shift - echo deleting an acl entries for $1 - opts="-R -x" - optsd="-dR -x" - spec="u:$1 $2" - else - opts="-R -m " - optsd="-dR -m" - spec="u:$1:rwX $2" - fi - [[ ! $2 ]] && echo acluserdir: both user and direcotory must be passed && return 1 - uid=$(id -u $1 2>/dev/null) - [[ $uid -lt 1000 ]] && echo no such regular user $1 && return 2 - [[ ! -d $2 ]] && echo no such directory $2 && return 3 - if [[ ! -w $2 ]];then - echo $2 not writable by current user $USER - if [[ ! $(sudo -l -U $USER 2>/dev/null) ]]; then - echo user does not have sudo privilges, aborting - return 4 - else - confirm "do you want to elevate to root and continue?" || return 5 - usesudo="sudo" - fi - fi - - echo this are the commands that you will run - echo '******************' - echo $usesudo setfacl $opts $spec - echo $usesudo setfacl $optsd $spec - echo '******************' - confirm Double Check. Do you want to continue? || return 6 - $usesudo setfacl $opts $spec - $usesudo setfacl $optsd $spec - echo '*** new acl entries ***' - $usesudo getfacl -p --omit-header $2 | grep $1 -} - - - - - +module_load acl \ No newline at end of file diff --git a/function/rsync b/function/rsync index fc4495c..f110fae 100755 --- a/function/rsync +++ b/function/rsync @@ -9,5 +9,5 @@ function cprs () { echo Command to run: rsync --progress -a -r -u "$1" "$2" confirm Do you want to start the rsync copy? || return 0 echo copying..... - rsync --progress -a -r -u "$1" "$2" + rsync --exclude *[C]ache* --progress -a -r -u "$1" "$2" } diff --git a/modules/utility/helpers.mod b/modules/utility/helpers.mod index 26854ed..2152eab 100644 --- a/modules/utility/helpers.mod +++ b/modules/utility/helpers.mod @@ -22,4 +22,12 @@ adirname() { echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" } +chmod_dirs() { + # passed entire path + local usesudo + [[ $1 == -s ]] && usesudo="sudo" && shift 2 + $usesudo find $1 -type f -exec chmod $2 {} + +} + +