From 0e3797fb7b7292c57ce4bcc10d1bfd58c36a812b Mon Sep 17 00:00:00 2001 From: deepend-tildeclub <58404188+deepend-tildeclub@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:01:20 -0600 Subject: [PATCH] Update tilde --- tilde | 424 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 222 insertions(+), 202 deletions(-) diff --git a/tilde b/tilde index 262e748..c862699 100755 --- a/tilde +++ b/tilde @@ -1,10 +1,8 @@ -#!/usr/bin/env bash +#!/bin/sh # --------------------------------------------------------------------------- -# tilde - manage user-submitted scripts -# forked from tilde.team +# tilde - manage user-submitted scripts and apps -# Copyright 2018-2019, Ben Harris -# Copyright 2019, Sven Kinne +# Copyright 2018, Ben Harris # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,126 +18,125 @@ # Usage: tilde [-h|--help] # --------------------------------------------------------------------------- -export TERM=xterm-256color PROGNAME=${0##*/} -VERSION="0.0.5" +VERSION="0.1.0" +user=$(whoami) +hostname=$(hostname -f) -INFO_FILE="/home/$(id -un)/.tilde" +# check coreutils and wrap stat for portability +if stat -c"%U" /dev/null >/dev/null 2>/dev/null ; then + # GNU environment + stat_func () { + stat -c '%U' "$1" + } +else + # BSD environment + stat_func () { + stat -f %Su "$1" + } +fi -### - -clean_up() { # Perform pre-exit housekeeping - return +isroot() { + [ "$(id -u)" = "0" ] } - error_exit() { - echo -e "${1:-"unknown Error"}" >&2 - clean_up - exit 1 + printf "%s\n" "${1:-"unknown Error"}" >&2 + exit 1 } - -graceful_exit() { - clean_up - exit -} - - signal_exit() { # Handle trapped signals - case $1 in - INT) - error_exit "program interrupted by user" ;; - TERM) - printf '\n%s: program terminated\n' "$PROGNAME" >&2 - graceful_exit ;; - *) - error_exit "$PROGNAME: terminating on unknown signal" ;; - esac + case $1 in + INT) + error_exit "program interrupted by user" + ;; + TERM) + printf "\n%s: program terminated" "$PROGNAME" >&2 + exit + ;; + *) + error_exit "$PROGNAME: terminating on unknown signal" + ;; + esac } - prompt_confirm() { - while true; do - read -r -n 1 -p "${1:-continue?} [y/n]: " REPLY - case "$REPLY" in - [yY]) echo ; return 0 ;; - [nN]) echo ; return 1 ;; - *) printf ' \033[31m %s \n\033[0m' "invalid input" - esac - done + while true; do + printf "%s [y/n]: " "${1:-continue?}" + read -r REPLY + case $REPLY in + [yY]) printf "\n" ; return 0 ;; + [nN]) printf "\n" ; return 1 ;; + *) printf " \033[31m %s \n\033[0m" "invalid input" ;; + esac + done } - -usage() { - printf '\n%sUser Scripts%s\n' "$(tput setaf 6)" "$(tput sgr0)" - printf '\nusage: %s [help|list|submit|about|script_name]\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" - [[ $(id -u) == 0 ]] && { - printf ' %s approve - enter the approval queue\n' "$PROGNAME" - printf ' %s revoke - send a script back to the author and remove from /tilde/bin\n' "$PROGNAME" - } - printf ' %s about - get the description for script_name\n' "$PROGNAME" - printf ' %s - run script_name with all remaining args are passed to the script\n' "$PROGNAME" - - if [[ :$PATH: != *:"/tilde/bin":* ]] ; then - 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" - fi - - printf '\nSource is on github: https://github.com/tildeclub/launcher, please open an issue or send in a PR!\n' -} - - help_message() { - cat <<- EOF -$(tput setaf 6)$PROGNAME (ver. $VERSION)$(tput sgr0) -wrapper for user-submitted scripts -supports user settings, submission and admin approval -$(usage) -EOF - return -} + cat <<-EOF +Usage: $PROGNAME [options] [command] +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