Browse Source

added more utility commands to lead (say, ask_for, remember, forget)

main
Zen 3 years ago
parent
commit
b1900495cb
  1. 2
      ingredients/gold
  2. 2
      ingredients/iron
  3. 86
      ingredients/lead
  4. 6
      ingredients/tin
  5. 4
      recipes/ao.sh

2
ingredients/gold

@ -140,7 +140,7 @@ configure_lightning() {
read clboss_enable read clboss_enable
case $clboss_enable in case $clboss_enable in
"y" | "Y") "y" | "Y")
if ! check_exists clboss; then if ! check_for clboss; then
install_clboss install_clboss
fi fi
sed -i "s/#plugin/plugin/" $HOME/.lightning/config sed -i "s/#plugin/plugin/" $HOME/.lightning/config

2
ingredients/iron

@ -21,7 +21,7 @@ if [ -d $NVM_DIR ]; then
fi fi
set_node_to() { set_node_to() {
if check_exists nvm; then if check_for nvm; then
if [ ! $(node -v) = $1 ]; then if [ ! $(node -v) = $1 ]; then
nvm install $1 nvm install $1
nvm alias default $1 nvm alias default $1

86
ingredients/lead

@ -16,6 +16,7 @@ RED="\e[0;31m"
GREEN="\e[0;32m" GREEN="\e[0;32m"
BLUE="\e[0;34m" BLUE="\e[0;34m"
BOLD="\e[1m" BOLD="\e[1m"
ITALIC="\e[3m"
ULINE="\e[4m" ULINE="\e[4m"
RESET="\e[0m" RESET="\e[0m"
@ -56,7 +57,8 @@ RESET="\e[0m"
# Traps, in the case of shell scripting, listen for certain signals # Traps, in the case of shell scripting, listen for certain signals
# that are broadcast by the system and execute a command in response # that are broadcast by the system and execute a command in response
# We only want these to activate if we're running a recipe # We only want these to activate if we're running a recipe, so we
# check to see if we're running a "shell inside of a shell"
if [[ $SHLVL -gt 1 ]]; then if [[ $SHLVL -gt 1 ]]; then
# Make sure that ctrl+C consistently exits the script # Make sure that ctrl+C consistently exits the script
trap "exit" INT trap "exit" INT
@ -64,6 +66,37 @@ if [[ $SHLVL -gt 1 ]]; then
trap 'say "${RED}Oops...${RESET} Something went wrong on line $LINENO of this script. Exit code was $?" >&2' ERR trap 'say "${RED}Oops...${RESET} Something went wrong on line $LINENO of this script. Exit code was $?" >&2' ERR
fi fi
# --------------- Functions ---------------
# Coding Moment: generally, whenever you see something with brackets
# at the end of it, like this() or like(this), it's a function!
# It takes inputs and gives (or does) something as an output
# --------------- Input/Output ---------------
# 'say' is a simple function that imitates "echo"
# This needs to be built out way more! Replace echo for POSIX compatibility
say() {
printf "%b\n" "${1}"
}
ask_for() {
if [ ${#} -eq 0 ]; then
say "To use this command, you need to pass the variable you want,"
say "and then add as string of text to ask for it if you want. Example:\n"
say "ask_for RESPONSE \"Could you give me a RESPONSE please?\""
say ""
say "Afterwards, you'll be able to use \$RESPONSE as a variable,"
say "and ${ITALIC}say \$RESPONSE${RESET} will respond with your entry"
return 0
fi
if [ -n "${2}" ]; then
printf "%b" "${2}"
fi
read ${1}
}
# --------------- Environment Setup --------------- # --------------- Environment Setup ---------------
@ -82,20 +115,10 @@ source_env() {
# This one takes no arguments (words after the function name # This one takes no arguments (words after the function name
source_env source_env
# --------------- Functions --------------- # --------------- Program Installation ---------------
# Coding Moment: generally, whenever you see something with brackets
# at the end of it, like this() or like(this), it's a function!
# It takes inputs and gives (or does) something as an output
# 'say' is a simple function that imitates "echo"
# This needs to be built out way more! Replace echo for POSIX compatibility
say() {
printf "%b\n" "${1}"
}
# Checks to see if we can use a command or not # Checks to see if we can use a command or not
check_exists() { check_for() {
command -v "$1" >/dev/null command -v "$1" >/dev/null
} }
@ -105,8 +128,8 @@ install_if_needed() {
do do
case $DISTRO in case $DISTRO in
"debian") "debian")
# TODO Better installation detection than check_exists # TODO Better installation detection than check_for
if [ -z $(check_exists $package) ]; then if [ -z $(check_for $package) ]; then
say "installing $package" say "installing $package"
sudo apt install -y $package sudo apt install -y $package
else else
@ -122,8 +145,8 @@ install_if_needed() {
fi fi
;; ;;
"fedora") "fedora")
# TODO Better installation detection than "check_exists" # TODO Better installation detection than "check_for"
if [ -z $(check_exists $package) ]; then if [ -z $(check_for $package) ]; then
say "installing $package" say "installing $package"
sudo dnf install -y $package sudo dnf install -y $package
else else
@ -131,8 +154,8 @@ install_if_needed() {
fi fi
;; ;;
"mac") "mac")
# TODO Better installation detection than "check_exists" # TODO Better installation detection than "check_for"
if [ -z $(check_exists $package) ]; then if [ -z $(check_for $package) ]; then
say "installing $package" say "installing $package"
brew install $package brew install $package
else else
@ -164,15 +187,15 @@ forget() {
} }
remember() { remember() {
KEY=$(echo ${1} | cut -d'=' -f 1) KEY=$(say ${1} | cut -d'=' -f 1)
VALUE=$(echo ${1} | cut -d'=' -f 2) VALUE=$(say ${1} | cut -d'=' -f 2)
if [[ ! $KEY =~ ^[A-Z_]+$ ]]; then if [[ ! $KEY =~ ^[A-Z_]+$ ]]; then
echo "Keys must consist only of capital letters and underscores" say "Keys must consist only of capital letters and underscores"
fi fi
if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:]+$ ]]; then if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:]+$ ]]; then
echo "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\" say "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\"
fi fi
# If we're setting a valid key/value pair # If we're setting a valid key/value pair
@ -180,14 +203,13 @@ remember() {
DOTENV_ENTRY=$(cat .env | grep ${KEY}) DOTENV_ENTRY=$(cat .env | grep ${KEY})
# If something already exists and we're trying to set it to something new # If something already exists and we're trying to set it to something new
if [ -n "$DOTENV_ENTRY" ] && [[ ! $DOTENV_ENTRY = $1 ]]; then if [ -n "$DOTENV_ENTRY" ] && [ "$DOTENV_ENTRY" != "$1" ]; then
echo -e "I'm trying to remember ${BLUE}${1}${RESET}, but..." say "I'm trying to remember ${BLUE}${1}${RESET}, but..."
echo "" say ""
echo -e "${BLUE}${DOTENV_ENTRY}${RESET}" say "${BLUE}${DOTENV_ENTRY}${RESET}"
echo -e "This has already been defined in the .env file!" say "This has already been defined in the .env file!"
echo "" say ""
echo -en "would you like to overwrite it? ${BLUE}(y/n)${RESET} " ask_for overwrite "would you like to overwrite it? ${BLUE}(y/n)${RESET} "
read overwrite
case $overwrite in case $overwrite in
"y" | "Y") "y" | "Y")
unset ${KEY} unset ${KEY}
@ -196,7 +218,7 @@ remember() {
export ${1} export ${1}
;; ;;
esac esac
else elif [ -z "$DOTENV_ENTRY" ]; then
unset ${KEY} unset ${KEY}
echo "${1}" >> .env echo "${1}" >> .env
export ${1} export ${1}

6
ingredients/tin

@ -14,9 +14,9 @@
sha256_check() { sha256_check() {
# Args: <sha256_hash> <filename> # Args: <sha256_hash> <filename>
# #
if check_exists sha256sum; then if check_for sha256sum; then
echo "${1} ${2}" | sha256sum -c echo "${1} ${2}" | sha256sum -c
elif check_exists sha256; then elif check_for sha256; then
if [ "$(uname)" = "FreeBSD" ]; then if [ "$(uname)" = "FreeBSD" ]; then
sha256 -c "${1}" "${2}" sha256 -c "${1}" "${2}"
else else
@ -35,7 +35,7 @@ http_get() {
# #
if [ -f "${2}" ]; then if [ -f "${2}" ]; then
echo "File ${2} already exists; not downloading again" echo "File ${2} already exists; not downloading again"
elif check_exists curl; then elif check_for curl; then
curl --insecure --retry 5 "${1}" -o "${2}" curl --insecure --retry 5 "${1}" -o "${2}"
else else
wget --no-check-certificate "${1}" -O "${2}" wget --no-check-certificate "${1}" -O "${2}"

4
recipes/ao.sh

@ -131,12 +131,12 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo -e "${BOLD}Installing Bitcoin Ecosystem${RESET}" echo -e "${BOLD}Installing Bitcoin Ecosystem${RESET}"
echo "" echo ""
if ! check_exists bitcoind; then if ! check_for bitcoind; then
echo -e "Building bitcoind from source... might take a while!" echo -e "Building bitcoind from source... might take a while!"
install_bitcoin install_bitcoin
fi fi
if ! check_exists lightningd; then if ! check_for lightningd; then
echo -e "Building lightningd from source... here we go again" echo -e "Building lightningd from source... here we go again"
install_lightning install_lightning
fi fi

Loading…
Cancel
Save