commit caf3d4fea7353926bca61bbbacbc4b3d7f89186b
parent 4e6fb274243b74e3589f38b7d77d32c5ccf3530c
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 18 Feb 2020 19:40:44 +0100
Remove option to run command with user in newuser
Diffstat:
1 file changed, 7 insertions(+), 44 deletions(-)
diff --git a/.local/bin/newuser b/.local/bin/newuser
@@ -9,9 +9,8 @@ die() {
}
help() {
- echo "usage: ${0##*/} [OPTIONS] USER [CMD]"
+ echo "usage: ${0##*/} [OPTIONS] USER ..."
echo "will create a new USER with 'nopass' and 'keepenv' rules."
- echo "If USER already exists, run CMD as USER."
echo
echo "Graphical commands can be started with:"
echo " $ ssh -Y USER@localhost COMMAND"
@@ -24,7 +23,6 @@ help() {
echo " -h show this message"
echo " -v show version and license information"
echo " -V show verbose information during execution"
- echo " -t transfer any output files from CMD to current directory"
echo " -- do not consider any following args as options"
}
@@ -41,7 +39,6 @@ if [ $# -lt 1 ]; then
fi
verbose=0
-transfer=0
while :; do
case "$1" in
-h)
@@ -55,9 +52,6 @@ while :; do
-V)
verbose=1
;;
- -t)
- transfer=1
- ;;
--)
shift
break
@@ -78,43 +72,12 @@ add_user() {
printf 'adding ssh key to %s\n' "$1"
printf 'limiting access to /home/%s\n' "$1"
fi
- doas "useradd -m '$1' && \
+ doas "useradd -m $1 && \
echo 'permit nopass keepenv ad as $1' >> /etc/doas.conf && \
- cat /home/$HOME/.ssh/id_rsa.pub >> /home/'$1'/.ssh/authorized_keys && \
- chmod go-rx /home/'$1'"
-}
-
-run_as_user() {
- u="$1"
- shift
- orig="$PWD"
- if [ "$transfer" = 1 ]; then
- d="$(mktemp -d)"
- mkdir -p "$d"
- chmod 777 "$d"
- cd "$d"
- else
- d="$orig"
- fi
- if [ "$verbose" = 1 ]; then
- printf 'executing "%s" as %s in %s\n' "$*" "$u" "$d"
- fi
- doas -u "$u" sh -c "cd '$d' && \
- PATH=/home/'$u'/.local/bin:/home/'$u'/bin:\$PATH && \
- $*"
- if [ "$transfer" = 1 ]; then
- if ls -lqA "$d" | grep -q .; then
- if cp -prf "$d"/* "$orig"; then
- rm -rf "$d"
- else
- die "could not transfer files from '$d' to '$orig'"
- fi
- fi
- fi
+ cat $HOME/.ssh/id_rsa.pub >> /home/$1/.ssh/authorized_keys && \
+ chmod go-rx /home/$1"
}
-if [ -d "/home/${1}" ]; then
- run_as_user "$@"
-else
- add_user "$1"
-fi
+for u in "$@"; do
+ add_user "$u"
+done