made some little improvements
This commit is contained in:
parent
fa8fa53e48
commit
e5a6bf1d84
203
tilde
203
tilde
|
@ -74,34 +74,34 @@ prompt_confirm() {
|
||||||
}
|
}
|
||||||
|
|
||||||
help_message() {
|
help_message() {
|
||||||
printf "%s version %s\n" "$PROGNAME" "$VERSION"
|
cat <<-EOF
|
||||||
printf "wrapper for user-submitted scripts\n"
|
Usage: $PROGNAME [options] [command]
|
||||||
printf "supports submission and admin approval\n"
|
|
||||||
usage
|
Options:
|
||||||
|
-h, --help Show this help message and exit
|
||||||
|
-v, --version Show version information
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
list Show a list of approved user scripts
|
||||||
|
submit Start the submission flow for your own script
|
||||||
|
about <script> Show description and details of a specific script
|
||||||
|
approve Enter the approval queue for pending scripts (requires root)
|
||||||
|
revoke <script> Revoke a previously approved script (requires root)
|
||||||
|
run <script> Run an approved script
|
||||||
|
|
||||||
|
Please add /tilde/bin to your PATH to use approved scripts without this wrapper.
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "\nusage: %s [help|list|submit|about|script_name]\n\n" "$PROGNAME"
|
printf "\nusage: %s [help|list|submit|about|approve|revoke|run|script_name]\n\n" "$PROGNAME"
|
||||||
printf " list - show a list of approved userscripts\n"
|
printf " help - Show usage information\n"
|
||||||
printf " submit - start the submission flow for your own script\n"
|
printf " list - Show a list of approved user scripts\n"
|
||||||
|
printf " submit - Start the submission flow for your own script\n"
|
||||||
if isroot; then
|
printf " about <script> - Show description and details of a specific script\n"
|
||||||
printf " approve - enter the approval queue\n"
|
printf " approve - Enter the approval queue for pending scripts (requires root)\n"
|
||||||
printf " revoke <script_name> - send a script back to the author and remove from /tilde/bin\n"
|
printf " revoke <script> - Revoke a previously approved script (requires root)\n"
|
||||||
fi
|
printf " run <script> - Run an approved script\n"
|
||||||
|
|
||||||
printf " about <script_name> - get the description for script_name\n"
|
|
||||||
printf " <script_name> - run script_name with all remaining args are passed to the script\n"
|
|
||||||
|
|
||||||
case ":$PATH:" in
|
|
||||||
*:/tilde/bin:*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
printf "\nadd /tilde/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 " echo 'export PATH=\$PATH:/tilde/bin' >> ~/.bashrc && source ~/.bashrc\n"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
verify_script_name() {
|
verify_script_name() {
|
||||||
|
@ -129,20 +129,18 @@ verify_script_name() {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
submission_checklist() {
|
submission_checklist() {
|
||||||
cat <<- _EOF_
|
cat <<- _EOF_
|
||||||
requirements for submitting a user script or program:
|
Requirements for submitting a user script or program:
|
||||||
|
|
||||||
- placed in your ~/bin
|
- Placed in your ~/bin
|
||||||
- executable
|
- Executable
|
||||||
- responds to help or --help
|
- Responds to help or --help
|
||||||
- no name collisions with existing scripts or $PROGNAME subcommands
|
- No name collisions with existing scripts or $PROGNAME subcommands
|
||||||
|
|
||||||
_EOF_
|
_EOF_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mail_body() {
|
mail_body() {
|
||||||
cat <<- _EOF_
|
cat <<- _EOF_
|
||||||
Subject: tilde script submission from ${user}
|
Subject: tilde script submission from ${user}
|
||||||
|
@ -159,36 +157,32 @@ description:
|
||||||
$2
|
$2
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
you'll find the script and description in: /tilde/pending-submissions/$user/$1
|
You'll find the script and description in: /tilde/pending-submissions/$user/$1
|
||||||
|
|
||||||
run this to see the approval queue:
|
Run this to see the approval queue:
|
||||||
sudo tilde approve
|
sudo tilde approve
|
||||||
_EOF_
|
_EOF_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Trap signals
|
# Trap signals
|
||||||
trap "signal_exit TERM" TERM HUP
|
trap "signal_exit TERM" TERM HUP
|
||||||
trap "signal_exit INT" INT
|
trap "signal_exit INT" INT
|
||||||
|
|
||||||
|
|
||||||
# Parse command-line
|
# Parse command-line
|
||||||
case $1 in
|
case $1 in
|
||||||
-h | --help | help)
|
-h | --help)
|
||||||
help_message; exit
|
help_message
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-v | --version)
|
-v | --version)
|
||||||
printf "%s" "$VERSION"
|
printf "%s\n" "$VERSION"
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-* | --*)
|
list)
|
||||||
usage
|
# List approved scripts
|
||||||
error_exit "Unknown option $1"
|
printf "Available scripts:\n\n"
|
||||||
;;
|
|
||||||
|
|
||||||
list | ls)
|
|
||||||
printf "available scripts:\n\n"
|
|
||||||
for scr in /tilde/bin/*; do
|
for scr in /tilde/bin/*; do
|
||||||
if [ -f "$scr" ]; then
|
if [ -f "$scr" ]; then
|
||||||
script_name=$(basename "$scr")
|
script_name=$(basename "$scr")
|
||||||
|
@ -200,79 +194,80 @@ case $1 in
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
about | apropos | description)
|
about | description)
|
||||||
|
# Show details about a specific script
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
printf "Please provide a script name.\n"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "/tilde/descriptions/$2" ]; then
|
if [ -f "/tilde/descriptions/$2" ]; then
|
||||||
cat "/tilde/descriptions/$2"
|
cat "/tilde/descriptions/$2"
|
||||||
else
|
else
|
||||||
printf "%s not found. try %s list to see available user scripts.\n" "$2" "$PROGNAME"
|
printf "%s not found. Use '%s list' to see available user scripts.\n" "$2" "$PROGNAME"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
submit)
|
submit)
|
||||||
printf "hello, %s! so it's time to submit your script?\n" "$user"
|
# Submit a user script
|
||||||
|
printf "Hello, %s! Ready to submit your script?\n" "$user"
|
||||||
submission_checklist
|
submission_checklist
|
||||||
prompt_confirm "are you ready to continue?" || exit
|
prompt_confirm "Are you ready to continue?" || exit
|
||||||
printf "enter the name of your script: "
|
|
||||||
read -r script_name
|
|
||||||
|
|
||||||
|
printf "Enter the name of your script: "
|
||||||
|
read -r script_name
|
||||||
verify_script_name "$script_name"
|
verify_script_name "$script_name"
|
||||||
|
|
||||||
if [ -x "$HOME/bin/$script_name" ]; then
|
if [ ! -x "$HOME/bin/$script_name" ]; then
|
||||||
printf "cool, found your script\n"
|
|
||||||
if [ -x "/tilde/pending-submissions/$user/$script_name/$script_name" ]; then
|
|
||||||
error_exit "you've already submitted $script_name"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
error_exit "$script_name not found in ~/bin"
|
error_exit "$script_name not found in ~/bin"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "enter a description of your script: \n"
|
printf "Enter a description for your script: \n"
|
||||||
read -r description
|
read -r description
|
||||||
printf "\nyour script, along with your description will be sent to the admins for approval\n"
|
printf "\nYour script and description will be sent to the admins for approval.\n"
|
||||||
prompt_confirm "ready to submit?" || exit
|
prompt_confirm "Ready to submit?" || exit
|
||||||
|
|
||||||
# submit now
|
# Submit now
|
||||||
mkdir -p "/tilde/pending-submissions/$user/$script_name"
|
mkdir -p "/tilde/pending-submissions/$user/$script_name"
|
||||||
ln -s "$HOME/bin/$script_name" "/tilde/pending-submissions/$user/$script_name/$script_name"
|
ln -s "$HOME/bin/$script_name" "/tilde/pending-submissions/$user/$script_name/$script_name"
|
||||||
printf "%s\n" "$description" > "/tilde/pending-submissions/$user/$script_name/description.txt"
|
printf "%s\n" "$description" > "/tilde/pending-submissions/$user/$script_name/description.txt"
|
||||||
mail_body "$script_name" "$description" | sendmail root
|
mail_body "$script_name" "$description" | /usr/sbin/sendmail root
|
||||||
printf "script submitted. thanks! :)\n"
|
printf "Script submitted. Thank you! :)\n"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
approve)
|
approve)
|
||||||
if ! isroot; then
|
# Approve pending scripts (requires root)
|
||||||
error_exit "re-run this as root to access the approval queue"
|
isroot || \
|
||||||
fi
|
error_exit "Re-run this as root to access the approval queue."
|
||||||
|
printf "Welcome to the approval queue\n\n"
|
||||||
|
|
||||||
printf "welcome to the approval queue\n\n"
|
for user_submission in /tilde/pending-submissions/*; do
|
||||||
|
user=$(basename "$user_submission")
|
||||||
|
for script in "$user_submission"/*; do
|
||||||
|
script_name=$(basename "$script")
|
||||||
|
[ -f "$script/approved" ] && continue
|
||||||
|
|
||||||
for user in /tilde/pending-submissions/*; do
|
printf "Script name: %s\n" "$script_name"
|
||||||
for scr in $user/*; do
|
cat "$script/description.txt"
|
||||||
user=$(basename "$user")
|
prompt_confirm "Approve?" || continue
|
||||||
script_name=$(basename "$scr")
|
|
||||||
[ -f "$scr/approved" ] && continue
|
|
||||||
script="$scr/$script_name"
|
|
||||||
|
|
||||||
if [ -f "$script" ]; then
|
ln -s "$(readlink -f "$script/$script_name")" "/tilde/bin/$script_name"
|
||||||
printf "%s by %s\n" "$script_name" "$user"
|
cp "$script/description.txt" "/tilde/descriptions/$script_name"
|
||||||
cat "$scr/description.txt"
|
touch "$script/approved"
|
||||||
prompt_confirm "approve?" || continue
|
chmod 664 "/tilde/descriptions/$script_name"
|
||||||
|
printf "Your submission of %s has been approved and is now available at /tilde/bin/%s\n" "$script_name" "$script_name" \
|
||||||
ln -s "$(readlink -f "$script")" "/tilde/bin/$script_name"
|
| sendmail "$user"
|
||||||
cp "$scr/description.txt" "/tilde/descriptions/$script_name"
|
|
||||||
touch "$scr/approved"
|
|
||||||
chmod 664 /tilde/descriptions/*
|
|
||||||
printf "your submission of %s has been approved and is now available at /tilde/bin/%s" "$script_name" "$script_name" \
|
|
||||||
| sendmail "$user"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
printf "~~done for now~~\n"
|
printf "~~Done for now~~\n"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
revoke)
|
revoke)
|
||||||
|
# Revoke an approved script (requires root)
|
||||||
isroot || \
|
isroot || \
|
||||||
error_exit "re-run this as sudo to access the revoke menu"
|
error_exit "Re-run this as root to access the revoke menu."
|
||||||
[ -f "/tilde/bin/$2" ] || \
|
[ -f "/tilde/bin/$2" ] || \
|
||||||
error_exit "$2 isn't an approved script"
|
error_exit "$2 isn't an approved script"
|
||||||
|
|
||||||
|
@ -292,20 +287,32 @@ case $1 in
|
||||||
printf "%s revoked and returned to author" "$2"
|
printf "%s revoked and returned to author" "$2"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
run)
|
||||||
if [ -z "$1" ]; then
|
# Run an approved script
|
||||||
help_message
|
if [ -z "$2" ]; then
|
||||||
exit
|
printf "Please provide a script name.\n"
|
||||||
elif [ -x "/tilde/bin/$1" ]; then
|
usage
|
||||||
prog="/tilde/bin/$1"
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -x "/tilde/bin/$2" ]; then
|
||||||
|
prog="/tilde/bin/$2"
|
||||||
shift
|
shift
|
||||||
exec "$prog" "$@"
|
exec "$prog" "$@"
|
||||||
else
|
else
|
||||||
printf "%s not found. check %s list to see what's available\n\n" "$1" "$PROGNAME"
|
printf "%s not found or not approved yet. Use '%s list' to see available user scripts.\n" "$2" "$PROGNAME"
|
||||||
help_message
|
exit 1
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
"")
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
printf "Invalid command: %s\n" "$1"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
Loading…
Reference in New Issue