add more functionality to manage users_info.json entrys [show] [edit] [get] [set] [unset]

This commit is contained in:
creme 2019-09-06 01:13:00 +02:00
parent 91f27c9dd7
commit f2bab6d095
No known key found for this signature in database
GPG Key ID: C147C3B7FBDF08D0
1 changed files with 66 additions and 19 deletions

73
envs
View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# envs - manage user-submitted scripts and apps # envs - manage users_info.json entrys and user-submitted scripts and apps
# forked from tilde.team # forked from tilde.team
# Copyright 2018-2019, Ben Harris <ben@tilde.team> # Copyright 2018-2019, Ben Harris <ben@tilde.team>
@ -23,7 +23,9 @@
export TERM=xterm-256color export TERM=xterm-256color
PROGNAME=${0##*/} PROGNAME=${0##*/}
VERSION="0.0.2" VERSION="0.0.3"
INFO_FILE=/home/"$USER"/.envs
clean_up() { # Perform pre-exit housekeeping clean_up() { # Perform pre-exit housekeeping
@ -70,6 +72,7 @@ prompt_confirm() {
usage() { usage() {
printf '\n%sUser json-File Infomations%s\n' "$(tput setaf 6)" "$(tput sgr0)"
printf '\nusage: %s [help|list|submit|about|script_name]\n' "$PROGNAME" printf '\nusage: %s [help|list|submit|about|script_name]\n' "$PROGNAME"
printf ' %s list - show a list of approved userscripts\n' "$PROGNAME" printf ' %s list - show a list of approved userscripts\n' "$PROGNAME"
printf ' %s submit - start the submission flow for your own script\n' "$PROGNAME" printf ' %s submit - start the submission flow for your own script\n' "$PROGNAME"
@ -80,6 +83,14 @@ usage() {
printf ' %s about <script_name> - get the description for script_name\n' "$PROGNAME" printf ' %s about <script_name> - get the description for script_name\n' "$PROGNAME"
printf ' %s <script_name> - run script_name with all remaining args are passed to the script\n' "$PROGNAME" printf ' %s <script_name> - run script_name with all remaining args are passed to the script\n' "$PROGNAME"
printf '\n%sUser json-File Infomations%s\n' "$(tput setaf 6)" "$(tput sgr0)"
printf 'usage: %s [show]|[edit]|[get name]|[set name value]|[unset name]\n' "$PROGNAME"
printf ' %s show - show your config file\n' "$PROGNAME"
printf ' %s edit - edit your config file\n' "$PROGNAME"
printf ' %s get <entry> - show a entry from your config\n' "$PROGNAME"
printf " %s set <entry> <'value'> - set a entry to your config\n" "$PROGNAME"
printf ' %s unset <entry> - unset a entry from your config\n' "$PROGNAME"
if [[ :$PATH: != *:"/envs/bin":* ]] ; then if [[ :$PATH: != *:"/envs/bin":* ]] ; then
printf "\nadd /envs/bin to your PATH to use approved scripts without this wrapper\n" printf "\nadd /envs/bin to your PATH to use approved scripts without this wrapper\n"
printf "if you're using bash, run the following to add it quickly\n" printf "if you're using bash, run the following to add it quickly\n"
@ -90,9 +101,9 @@ usage() {
help_message() { help_message() {
cat <<- EOF cat <<- EOF
$PROGNAME (ver. $VERSION) $(tput setaf 6)$PROGNAME (ver. $VERSION)$(tput sgr0)
wrapper for user-submitted scripts wrapper for user-submitted scripts and users_info.json entrys
supports user submission and admin approval supports user settings, submission and admin approval
$(usage) $(usage)
EOF EOF
return return
@ -159,14 +170,18 @@ trap "signal_exit INT" INT
# Parse command-line # Parse command-line
case "$1" in case "$1" in
-h | --help | help) -h | --help | help)
help_message; graceful_exit ;; help_message; graceful_exit
;;
-v | --version) -v | --version)
printf '%s\n' "$VERSION" ;; printf '%s\n' "$VERSION"
;;
'-*' | '--*') '-*' | '--*')
usage usage
error_exit "Unknown option $1" ;; error_exit "Unknown option $1"
;;
list | ls) list | ls)
printf 'available scripts:\n\n' printf 'available scripts:\n\n'
@ -176,7 +191,8 @@ case "$1" in
printf '%s%s by %s%s\n' "$(tput setaf 6)" "$script_name" "$(stat -c '%U' "$target")" "$(tput sgr0)" printf '%s%s by %s%s\n' "$(tput setaf 6)" "$script_name" "$(stat -c '%U' "$target")" "$(tput sgr0)"
cat /envs/descriptions/"$script_name" cat /envs/descriptions/"$script_name"
printf '\n' printf '\n'
done ;; done
;;
about | apropos | description | desc) about | apropos | description | desc)
if [[ -f /envs/descriptions/"$2" ]]; then if [[ -f /envs/descriptions/"$2" ]]; then
@ -212,7 +228,8 @@ case "$1" in
ln -s "$HOME"/bin/"$script_name" /envs/pending-submissions/"$USER"/"$script_name"/"$script_name" ln -s "$HOME"/bin/"$script_name" /envs/pending-submissions/"$USER"/"$script_name"/"$script_name"
echo "$description" > /envs/pending-submissions/"$USER"/"$script_name"/description.txt echo "$description" > /envs/pending-submissions/"$USER"/"$script_name"/description.txt
mail_body "$script_name" "$description" | /usr/sbin/sendmail creme mail_body "$script_name" "$description" | /usr/sbin/sendmail creme
printf 'script submitted. thanks! :)\n' ;; printf 'script submitted. thanks! :)\n'
;;
approve) approve)
[[ $(id -u) != 0 ]] && error_exit "re-run this as sudo to access the approval queue" [[ $(id -u) != 0 ]] && error_exit "re-run this as sudo to access the approval queue"
@ -236,7 +253,8 @@ case "$1" in
echo "your submission of $script_name has been approved and is now available at /envs/bin/$script_name" | /usr/sbin/sendmail "$user" echo "your submission of $script_name has been approved and is now available at /envs/bin/$script_name" | /usr/sbin/sendmail "$user"
done done
done done
echo "~~done for now~~" ;; echo "~~done for now~~"
;;
revoke) revoke)
[[ "$(id -u)" != 0 ]] && error_exit "re-run this as sudo to access the revoke menu" [[ "$(id -u)" != 0 ]] && error_exit "re-run this as sudo to access the revoke menu"
@ -252,7 +270,34 @@ case "$1" in
sudo rm -rf /envs/pending-submissions/"$author"/"$2" sudo rm -rf /envs/pending-submissions/"$author"/"$2"
echo -e "your script $2 has been returned because: $reason\nfeel free to resubmit" | /usr/sbin/sendmail "$author" echo -e "your script $2 has been returned because: $reason\nfeel free to resubmit" | /usr/sbin/sendmail "$author"
printf '%s revoked and returned to author\n' "$2" ;; printf '%s revoked and returned to author\n' "$2"
;;
show)
cat "$INFO_FILE"
;;
edit)
if [[ -n "$EDITOR" ]]; then "$EDITOR" "$INFO_FILE"; else nano "INFO_FILE"; fi
;;
get)
sed -n "/^$2/{s#^.*=##;p}" "$INFO_FILE"
;;
set)
if [ -z "$(cat < "$INFO_FILE" | sed -n /^"$2"/p)" ]; then
echo "${2}=${3}" >> "$INFO_FILE"
else
sed -i "s#${2}=.*#${2}=${3}#" "$INFO_FILE"
fi
;;
unset)
sed -i "s#${2}=.*#${2}=#" "$INFO_FILE"
;;
*) *)
if [[ -f /envs/bin/"$1" ]]; then if [[ -f /envs/bin/"$1" ]]; then
@ -263,8 +308,10 @@ case "$1" in
else else
[[ "$1" == "" ]] || printf "%s not found. try %s list to see what's available\n" "$1" "$PROGNAME" [[ "$1" == "" ]] || printf "%s not found. try %s list to see what's available\n" "$1" "$PROGNAME"
help_message; graceful_exit; help_message; graceful_exit;
fi ;; fi
;;
esac esac
#
graceful_exit graceful_exit