This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/own.sh

27 lines
579 B
Bash
Raw Normal View History

2023-12-07 04:02:47 +03:00
# Change file ownership to specified user id and restrict access to him.
# Root user by default. This directory recursively by default.
# Usage: own [USER] [FILES]
2023-12-07 01:44:42 +03:00
function own() {
2023-12-10 04:18:37 +03:00
local IFS=$'\n'
local files=("${@:2}")
2023-12-05 21:50:45 +03:00
local user="${1}"
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# default to current dir.
2023-12-10 04:18:37 +03:00
if [ "${files[*]}" = "" ]; then
files=(".")
2023-12-05 21:50:45 +03:00
fi
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# default to current user.
if [ "${user}" = "" ]; then
user="${UID}"
fi
2023-08-08 16:24:15 +03:00
2023-12-10 04:18:37 +03:00
for file in "${files[@]}"; do
# set ownership.
chown "${user}":"${user}" -R "${file}" &> /dev/null
2023-08-08 16:24:15 +03:00
2023-12-10 04:18:37 +03:00
# remove access from group and others.
chmod -077 -R "${file}"
done
2023-08-08 16:24:15 +03:00
}