2024-08-20 17:25:22 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This file contains some really simple functions that are useful when building up customization scripts.
|
|
|
|
|
|
|
|
|
|
|
|
# Checks if the git config has a user registered - and sets it up if not.
|
|
|
|
#
|
|
|
|
# Param 1: name
|
|
|
|
# Param 2: email
|
|
|
|
#
|
|
|
|
config_user() {
|
|
|
|
local gcn=$(git config --global user.name)
|
|
|
|
if [ -z "${gcn}" ]; then
|
|
|
|
echo "Setting up git user / remote"
|
|
|
|
git config --global user.name "$1"
|
|
|
|
git config --global user.email "$2"
|
|
|
|
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Checks if the git remote is configured - and sets it up if not. Fetches either way.
|
|
|
|
#
|
|
|
|
# Param 1: remote name
|
|
|
|
# Param 2: remote url
|
|
|
|
#
|
|
|
|
config_remote() {
|
|
|
|
local gr=$(git remote -v | grep $1)
|
|
|
|
if [ -z "${gr}" ]; then
|
|
|
|
git remote add $1 $2
|
|
|
|
fi
|
|
|
|
git fetch $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Setup special .ssh files
|
2024-08-24 22:42:05 +00:00
|
|
|
# Prints out lines of text to make things pretty
|
2024-08-20 17:25:22 +00:00
|
|
|
# Param 1: bash array, filenames relative to the customization directory that should be copied to ~/.ssh
|
|
|
|
setup_ssh() {
|
2024-08-24 22:42:05 +00:00
|
|
|
echo "starting ~/.ssh directory setup..."
|
|
|
|
mkdir -p "${HOME}.ssh"
|
|
|
|
chmod 0700 "${HOME}/.ssh"
|
|
|
|
echo "-----"
|
2024-08-20 17:25:22 +00:00
|
|
|
local files=("$@")
|
2024-08-23 22:27:14 +00:00
|
|
|
for file in "${files[@]}" ; do
|
2024-08-20 17:25:22 +00:00
|
|
|
local cfile="/devcontainer-customization/${file}"
|
2024-08-24 22:42:05 +00:00
|
|
|
local hfile="${HOME}/.ssh/${file}"
|
2024-08-20 17:25:22 +00:00
|
|
|
if [ ! -f "${hfile}" ]; then
|
2024-08-24 22:42:05 +00:00
|
|
|
echo "copying \"${file}\""
|
2024-08-20 17:25:22 +00:00
|
|
|
cp "${cfile}" "${hfile}"
|
|
|
|
chmod 600 "${hfile}"
|
|
|
|
fi
|
|
|
|
done
|
2024-08-24 22:42:05 +00:00
|
|
|
echo "~/.ssh directory setup complete!"
|
2024-08-20 17:25:22 +00:00
|
|
|
}
|