Added config script

This commit is contained in:
Randy Jordan 2024-11-03 17:17:47 -06:00
parent 814f827591
commit d20bcfb7bc
Signed by: Randy-Jordan
GPG Key ID: D57FA29E3B54663E
2 changed files with 158 additions and 0 deletions

84
config.sh Normal file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat << EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v]
This script clones a bare Git repository for dotfiles, checks out files,
and backs up any pre-existing files that may conflict.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# cleanup code here, if needed
}
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' YELLOW=''
fi
}
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
}
parse_params "$@"
setup_colors
# script logic here
msg "${YELLOW}Cloning dotfiles repository...${NOFORMAT}"
git clone --bare https://myrepos.dev/Randy-Jordan/dot.git "$HOME/.dot" || die "Failed to clone repository."
config() {
/usr/bin/git --git-dir="$HOME/.dot/" --work-tree="$HOME" "$@"
}
mkdir -p "$HOME/.config-backup"
if config checkout; then
msg "${GREEN}Checked out config.${NOFORMAT}"
else
msg "${YELLOW}Backing up pre-existing dot files...${NOFORMAT}"
config checkout 2>&1 | grep -E "\s+\." | awk '{print $1}' | xargs -I{} mv {} "$HOME/.config-backup/{}"
config checkout
fi
config config status.showUntrackedFiles no
msg "${GREEN}Dotfiles setup complete.${NOFORMAT}"

74
repoc.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat << EOF
Usage: $(basename "${BASH_SOURCE[0]}") <foldername>
Script to initialize a project folder with specific files and directories.
Available options:
<foldername> The name of the folder to create and initialize
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
parse_params() {
# Ensure exactly one argument is provided
if [ $# -ne 1 ]; then
usage
fi
foldername="$1"
# Ensure the foldername is not empty
if [ -z "${foldername-}" ]; then
die "Missing required argument: foldername"
fi
}
parse_params "$@"
# Create the specified folder
mkdir -p "$foldername"
# Copy the required files from Athena/code
cp ~/eg/c_dev/gitignore_c "$foldername/.gitignore"
cp ~/eg/README.md "$foldername/README.md"
cp ~/eg/c_dev/Makefile "$foldername/Makefile"
cp ~/eg/LICENSE_GPLV3.md "$foldername/LICENSE"
# Create src and tests subfolders
mkdir -p "$foldername/src"
mkdir -p "$foldername/tests"
mkdir -p "$foldername/include"
# Change directory to the created folder
cd "$foldername"
# Run ctags for C (not C++)
ctags -R --c-kinds=+p --fields=+iaS --extras=+q /usr/include
msg "Initialization and ctags generation complete for folder: $foldername"