details for this commit to come
parent
0d088cbcab
commit
ef8afa39c7
|
@ -9,7 +9,9 @@ local NAME
|
|||
DIR=$1
|
||||
NAME=$2
|
||||
# echo finding $NAME in $DIR
|
||||
FILE="$(command find -L ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh)"
|
||||
# TODO use file instead for valid extensions
|
||||
# allow explicit extension
|
||||
FILE="$(command find -L ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh -o -name "${NAME}".env)"
|
||||
# echo files found $FILE
|
||||
COUNT=0
|
||||
if [ "$FILE" ]; then
|
||||
|
@ -79,7 +81,8 @@ FILE=$(module_find $1)
|
|||
[ $? -ne 0 ] && echo no module $1 found && return 1
|
||||
# source $FILE "$0"
|
||||
# [[ $BASHPID -eq $$ ]] || echo $FILE
|
||||
source $FILE
|
||||
shift 1
|
||||
source $FILE "$@"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,14 @@ usage()
|
|||
echo "Options:"
|
||||
echo " -d DIRPERMS, directory permissions"
|
||||
echo " -f FILEPERMS, file permissions"
|
||||
exit 1
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
# Check if user entered arguments
|
||||
if [ $# -lt 1 ] ; then
|
||||
usage
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get options
|
||||
|
@ -62,7 +64,7 @@ ROOT=$1
|
|||
|
||||
# Check if the root path is a valid directory
|
||||
if [ ! -d $ROOT ] ; then
|
||||
echo "$ROOT does not exist or isn't a directory!" ; exit 1
|
||||
echo "$ROOT does not exist or isn't a directory!" ; return 2
|
||||
fi
|
||||
|
||||
# Recursively set directory/file permissions based on the permission variables
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# export BASH_DEBUG=true
|
||||
# module_load debug
|
||||
module_load debug
|
||||
module_load iecho
|
||||
|
||||
isFile() {
|
||||
|
|
|
@ -5,7 +5,7 @@ mounted () {
|
|||
mountpoint "$1" &> /dev/null && echo yes || return 1
|
||||
}
|
||||
|
||||
# peals back sub-directories until if finds a mountpoing
|
||||
# peals back sub-directories until if finds a mountpoint
|
||||
find_mountpoint () {
|
||||
local dir=$1
|
||||
if [[ ! $dir = "/" ]]; then
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#!/bin/bash
|
||||
# must be json as a string, depends on jq
|
||||
get_prop_value () {
|
||||
local value
|
||||
# echo in $1 get $2
|
||||
value=$(echo $1 | jq -r .$2)
|
||||
echo $value
|
||||
}
|
||||
|
||||
is_array() {
|
||||
local variable_name=$1
|
||||
[[ "$(declare -p $variable_name 2>/dev/null)" =~ "declare -a" ]]
|
||||
}
|
||||
|
||||
filename() {
|
||||
# passed entire path
|
||||
echo $(basename "$1" | rev | cut -f 2- -d '.' | rev)
|
||||
}
|
||||
|
||||
adirname() {
|
||||
# passed entire path
|
||||
echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )"
|
||||
}
|
||||
|
||||
user_exists() {
|
||||
id -u $1 > /dev/null 2>&1
|
||||
[[ $? == 1 ]] || echo $1
|
||||
}
|
||||
|
||||
|
||||
chmod_dirs() {
|
||||
# passed entire path
|
||||
local usesudo
|
||||
[[ $1 == -s ]] && usesudo="sudo" && shift 2
|
||||
$usesudo find $1 -type f -exec chmod $2 {} +
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# get full absolute bath from a current or parent path
|
||||
function abs-path {
|
||||
local target="$1"
|
||||
if [ "$target" == "." ]; then
|
||||
echo "$(pwd)"
|
||||
elif [ "$target" == ".." ]; then
|
||||
echo "$(dirname "$(pwd)")"
|
||||
else
|
||||
echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
|
||||
fi
|
||||
}
|
||||
|
||||
isAbsPath() {
|
||||
if [[ "${1:0:1}" == / || "${1:0:2}" == ~[/a-z] ]]
|
||||
then
|
||||
echo "true"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
function clone_user_ () {
|
||||
|
||||
module_load confirm
|
||||
type confirm
|
||||
|
||||
echo "============="
|
||||
echo "this script will create a new user"
|
||||
|
@ -51,32 +50,30 @@ echo "----"
|
|||
echo $olduser_GROUPS
|
||||
echo "olduser shell: "
|
||||
echo $olduser_SHELL
|
||||
# read -rsp $'Press any key to continue or ctrl-c to exit...\n' -n1 key
|
||||
# return
|
||||
# confirm "ready to clone user, begin?" || return 1
|
||||
|
||||
# useradd --groups $olduser_GROUPS --shell $olduser_SHELL $newuser
|
||||
confirm "ready to clone user, begin?" || return 1
|
||||
|
||||
# echo $newuser:$newpassword | chpasswd
|
||||
useradd --groups $olduser_GROUPS --shell $olduser_SHELL $newuser
|
||||
|
||||
# read -rsp $'ready to make home direcoty -- ctrl-c to exit...\n' -n1 key
|
||||
echo $newuser:$newpassword | chpasswd
|
||||
|
||||
# mkdir /home/$newuser
|
||||
# chown -R $newuser:$newuser /home/$newuser
|
||||
read -rsp $'ready to make home direcoty -- ctrl-c to exit...\n' -n1 key
|
||||
|
||||
# echo
|
||||
# echo "Script should be done now."
|
||||
# echo
|
||||
# echo "Do you see your new users name below?"
|
||||
# echo
|
||||
# awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd
|
||||
mkdir /home/$newuser
|
||||
chown -R $newuser:$newuser /home/$newuser
|
||||
|
||||
# echo
|
||||
# echo "We are now going to copy the old user's home folder to the new user"
|
||||
# echo "then change ownership to the new user"
|
||||
# echo
|
||||
# read -rsp $'Ready to copy home folder --- or ctrl-c to exit...\n' -n1 key
|
||||
echo
|
||||
echo "Script should be done now."
|
||||
echo
|
||||
echo "Do you see your new users name below?"
|
||||
echo
|
||||
awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd
|
||||
|
||||
echo
|
||||
echo "We are now going to copy the old user's home folder to the new user"
|
||||
echo "then change ownership to the new user"
|
||||
echo
|
||||
read -rsp $'Ready to copy home folder --- or ctrl-c to exit...\n' -n1 key
|
||||
|
||||
rsync -aPv --exclude 'Downloads' /home/$olduser/. /home/$newuser/
|
||||
chown -R --from=$olduser $newuser:$newuser /home/$newuser
|
||||
|
@ -108,5 +105,40 @@ if [[ $EUID != 0 ]]; then
|
|||
fi
|
||||
}
|
||||
|
||||
# # if script was executed then call the function
|
||||
(return 0 2>/dev/null) || clone_user
|
||||
rename_user () {
|
||||
|
||||
module_load confirm
|
||||
local force; local name; local newname; local newhome
|
||||
|
||||
[[ $1 = "-f" ]] && { force=true; shift 1; }
|
||||
[[ $1 = "-h" ]] && { newhome=$2; shift 2; }
|
||||
# usage: < -f, -h newhome > name newname
|
||||
# default new user home is /home/newname
|
||||
name=$1
|
||||
newname=$2
|
||||
if [[ ! ($name && $newname) ]]; then
|
||||
echo "============="
|
||||
echo "this script will rename an existing user"
|
||||
echo "user running this script must to root or have sudo priviledges to run"
|
||||
echo "---- Available Users to Rename ---"
|
||||
awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd
|
||||
echo "============="
|
||||
read -r -p "Enter an available user name: " name
|
||||
read -r -p "Enter users new name: " newname
|
||||
read -r -p "Enter users new home directory <enter for default /home/$newname>: " newhome
|
||||
fi
|
||||
|
||||
newhome=${newhome:-/home/$newname}
|
||||
|
||||
if [[ ! $force ]]; then
|
||||
echo "Changing $name to $newname with home $newhome"
|
||||
echo sudo usermod -l $newname $name
|
||||
echo sudo groupmod -n $newname $name
|
||||
echo sudo usermod --d $newhome --m $name
|
||||
confirm -s "These are the commands that will be run. Do you want to continue?" || return 1
|
||||
fi
|
||||
|
||||
sudo usermod -l $newname $name
|
||||
echo sudo groupmod -n $newname $name
|
||||
echo sudo usermod --d $newhome --m $name
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue