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
case $clboss_enable in
"y" | "Y")
if ! check_exists clboss; then
if ! check_for clboss; then
install_clboss
fi
sed -i "s/#plugin/plugin/" $HOME/.lightning/config

2
ingredients/iron

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

86
ingredients/lead

@ -16,6 +16,7 @@ RED="\e[0;31m"
GREEN="\e[0;32m"
BLUE="\e[0;34m"
BOLD="\e[1m"
ITALIC="\e[3m"
ULINE="\e[4m"
RESET="\e[0m"
@ -56,7 +57,8 @@ RESET="\e[0m"
# Traps, in the case of shell scripting, listen for certain signals
# 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
# Make sure that ctrl+C consistently exits the script
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
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 ---------------
@ -82,20 +115,10 @@ source_env() {
# This one takes no arguments (words after the function name
source_env
# --------------- 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
# '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}"
}
# --------------- Program Installation ---------------
# Checks to see if we can use a command or not
check_exists() {
check_for() {
command -v "$1" >/dev/null
}
@ -105,8 +128,8 @@ install_if_needed() {
do
case $DISTRO in
"debian")
# TODO Better installation detection than check_exists
if [ -z $(check_exists $package) ]; then
# TODO Better installation detection than check_for
if [ -z $(check_for $package) ]; then
say "installing $package"
sudo apt install -y $package
else
@ -122,8 +145,8 @@ install_if_needed() {
fi
;;
"fedora")
# TODO Better installation detection than "check_exists"
if [ -z $(check_exists $package) ]; then
# TODO Better installation detection than "check_for"
if [ -z $(check_for $package) ]; then
say "installing $package"
sudo dnf install -y $package
else
@ -131,8 +154,8 @@ install_if_needed() {
fi
;;
"mac")
# TODO Better installation detection than "check_exists"
if [ -z $(check_exists $package) ]; then
# TODO Better installation detection than "check_for"
if [ -z $(check_for $package) ]; then
say "installing $package"
brew install $package
else
@ -164,15 +187,15 @@ forget() {
}
remember() {
KEY=$(echo ${1} | cut -d'=' -f 1)
VALUE=$(echo ${1} | cut -d'=' -f 2)
KEY=$(say ${1} | cut -d'=' -f 1)
VALUE=$(say ${1} | cut -d'=' -f 2)
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
if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:]+$ ]]; then
echo "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\"
say "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\"
fi
# If we're setting a valid key/value pair
@ -180,14 +203,13 @@ remember() {
DOTENV_ENTRY=$(cat .env | grep ${KEY})
# If something already exists and we're trying to set it to something new
if [ -n "$DOTENV_ENTRY" ] && [[ ! $DOTENV_ENTRY = $1 ]]; then
echo -e "I'm trying to remember ${BLUE}${1}${RESET}, but..."
echo ""
echo -e "${BLUE}${DOTENV_ENTRY}${RESET}"
echo -e "This has already been defined in the .env file!"
echo ""
echo -en "would you like to overwrite it? ${BLUE}(y/n)${RESET} "
read overwrite
if [ -n "$DOTENV_ENTRY" ] && [ "$DOTENV_ENTRY" != "$1" ]; then
say "I'm trying to remember ${BLUE}${1}${RESET}, but..."
say ""
say "${BLUE}${DOTENV_ENTRY}${RESET}"
say "This has already been defined in the .env file!"
say ""
ask_for overwrite "would you like to overwrite it? ${BLUE}(y/n)${RESET} "
case $overwrite in
"y" | "Y")
unset ${KEY}
@ -196,7 +218,7 @@ remember() {
export ${1}
;;
esac
else
elif [ -z "$DOTENV_ENTRY" ]; then
unset ${KEY}
echo "${1}" >> .env
export ${1}

6
ingredients/tin

@ -14,9 +14,9 @@
sha256_check() {
# Args: <sha256_hash> <filename>
#
if check_exists sha256sum; then
if check_for sha256sum; then
echo "${1} ${2}" | sha256sum -c
elif check_exists sha256; then
elif check_for sha256; then
if [ "$(uname)" = "FreeBSD" ]; then
sha256 -c "${1}" "${2}"
else
@ -35,7 +35,7 @@ http_get() {
#
if [ -f "${2}" ]; then
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}"
else
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 ""
if ! check_exists bitcoind; then
if ! check_for bitcoind; then
echo -e "Building bitcoind from source... might take a while!"
install_bitcoin
fi
if ! check_exists lightningd; then
if ! check_for lightningd; then
echo -e "Building lightningd from source... here we go again"
install_lightning
fi

Loading…
Cancel
Save