Skip to content

Instantly share code, notes, and snippets.

@lynsei
Last active January 22, 2025 22:36
Show Gist options
  • Save lynsei/a3f8f61a69bcd6a9e49eab4e008b82fb to your computer and use it in GitHub Desktop.
Save lynsei/a3f8f61a69bcd6a9e49eab4e008b82fb to your computer and use it in GitHub Desktop.
[install] run.sh
#!/usr/bin/env bash
# -u Treat unset variables as an error when substituting them
# -e Exit immediately on Error.
# -x Print commands and their arguments as they are read
# -v Print shell input lines as they are read
# -B Perform brace expansion and
# -n read commands but do not execute them (dry run)
# -a mark variables which are modified or created for exporting
set -e
export __base_path=`basename $PWD`
if [[ "$__base_path" != "b2b-connect-devops-cli-connect-poc" ]]
then
mkdir -p $PWD/b2b-connect-devops-cli-connect-poc/scripts
cd $PWD/b2b-connect-devops-cli-connect-poc
fi
pushd . && cd $PWD/scripts
export PATH="$PATH:$PWD" && echo -e "\n\n\nPATH: \n\n $PATH"
# always pull new .run
curl -fsSL https://gist.githubusercontent.com/lynsei/116fd036050b50aa8d7e0c2faf8e3cc4/raw/8cc32645eaee0b83be49f334f898f2d107f0f788/run.sh -o $PWD/.run
popd
# install brew if it does not exist
if [[ `which brew` ]]
then
echo "Brew detected!"
else
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh -o $PWD/install.sh
chmod +x $PWD/install.sh
bash -c "NONINTERACTIVE=true $PWD/install.sh"
fi
# add path to fish if it exists otherwise install it
if [[ `which fish` ]]
then
echo "Fish detected! Adding to your config.fish"
echo "fish_add_path -ag $PWD/scripts" >> ~/.config/fish/config.fish
else
echo "Fish not detected, installing..."
brew reinstall fish
fi
echo -e "\nAdded $PWD/scripts to your PATH. \n\n"
echo -e "This application is easily configured using YAML.\n"
echo "Do you want to output an example configuration file?"
read -r -p "[y/n] " response
YML_CONFIG=$(cat <<-END
secrets:
storage:
command:
- "gh auth token"
files:
- "/secrets/.tokens/secrets.sh"
mounts:
bind:
- "$PWD/.cache:/root/devops"
- "$PWD/.config:/root/.config"
tokens:
az:
- "as9fweh390f8h02hbf08y2343oi8bnf0823i8hf"
jfrog:
- "da80uh30efhewh3208inee802hnf324i8fya9na"
github:
- "fa60uh80efhewh3208inee802hnf324i8fya9Yx"
globals:
az:
- "az"
- "AZURE_TOKEN"
jfrog:
- "jfrog"
- "JFROG_TOKEN"
github:
- "github"
- "GITHUB_TOKEN"
END
)
case "$response" in
[yY][eE][sS]|[yY])
def_path="$PWD/.config.yaml"
echo "Default Path: $PWD/.config.yaml"
read -r -p "[leave blank for default]" fn_response
fn_response=${fn_response:-$def_path}
echo "Output to: $fn_response"
if [[ $def_path != $fn_response ]]; then
echo "$YML_CONFIG" > $fn_response
echo "$fn_response" > $PWD/.config.location
else
echo "$YML_CONFIG" > $def_path
echo "$def_path" > $PWD/.config.location
fi
;;
*)
echo "File has not been created."
;;
esac
echo -e "\n\n\nStore Docker Credentials?"
echo "(requires docker)"
read -r -p "[y/n] " response2
case "$response2" in
[yY][eE][sS]|[yY])
rm -rf $PWD/.registry # adding credentials removes existing ones
mkdir -p $PWD/.registry # recreate .registry
export __saltstring=`date '+%Y-%m-%d %H:%M:%S' | sha1sum | rev | cut -c2- | rev`
echo "$__saltstring" > $PWD/.registry/.env.salt
echo -e "\nWrote salt.\n\n"
echo "Type your docker registry URL here:"
read -p "Enter registry: " registry
echo "$registry" > $PWD/.registry/.env.docker.registry
echo "Type your docker username here:"
read -p "Enter user: " username
echo "$username" > $PWD/.registry/.env.docker.user
echo "Type your docker password here (storage is encrypted):"
read -s -p "Enter password: " password
echo "$password" > $PWD/.registry/.tmppass
docker run -it --rm --platform linux/`uname -m` -v $PWD/.registry:/tmp lynsei/run.child.openssl:`uname -m` enc -e -aes-256-cbc -pbkdf2 -iter 1000000 -nosalt -base64 -in /tmp/.tmppass -k pass:"$__saltstring" -out /tmp/.encrypted
rm $PWD/.registry/.tmppass
mv $PWD/.registry/.encrypted $PWD/.registry/.env.docker.pass.encrypted
;;
*)
echo "Credentials not stored."
;;
esac
echo "$USAGE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment