removes legacy shell scripts

refactors dotf shell script
removes tailscale related code (now managed through nix)
removes shitty welcome prompt for ChatGPT (No longer used)
removes shitty git repos feature
This commit is contained in:
Menno van Leeuwen 2024-11-09 03:29:59 +01:00
parent 272aac9a94
commit 536b5f2e0b
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE
9 changed files with 90 additions and 345 deletions

View File

@ -142,6 +142,7 @@ launch_zellij_conditionally() {
fi
}
# Disabled for now, I don't like the way it behaves but I don't want to remove it either
# launch_zellij_conditionally
# Source ble.sh if it exists

View File

@ -1,29 +0,0 @@
#!/usr/bin/env bash
source $HOME/dotfiles/bin/helpers/functions.sh
# Push all changes from $HOME/dotfiles to ALL remotes in $HOME/dotfiles/.git/config
push_all() {
# Get all remotes from the .git/config file
remotes=($(cat $HOME/dotfiles/.git/config | grep url | awk '{print $3}'))
printfe "%s\n" "cyan" "Pushing all changes to all remotes..."
# For each remote, push all changes
for remote in "${remotes[@]}"; do
printfe "%s" "green" " - Pushing to ["
printfe "%s" "blue" "$remote"
printfe "%s\n" "green" "]..."
result=$(git -C $HOME/dotfiles push $remote 2>&1)
# If the push failed, print an error
if [ $? -ne 0 ]; then
printfe "%s\n" "red" " - Failed to push to $remote:"
printfe "%s\n" "red" " $result"
continue
fi
done
}
push_all

View File

@ -97,11 +97,11 @@ sys_packages_upgrade() {
cd $HOME/dotfiles/config/nixos && sudo nixos-rebuild switch --upgrade --flake .#$DOTF_HOSTNAME --impure
}
sys_packages() {
####################################################################################################
# Update system packages
####################################################################################################
####################################################################################################
# Update packages
####################################################################################################
sys_packages() {
printfe "%s\n" "cyan" "Updating system packages..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew update
@ -123,10 +123,6 @@ sys_packages() {
fi
}
####################################################################################################
# Update packages
####################################################################################################
cargopkgs() {
printfe "%s\n" "cyan" "Ensuring Cargo packages are installed..."
source $HOME/dotfiles/bin/helpers/cargo_packages.sh
@ -167,31 +163,6 @@ flatpakpkgs() {
ensure_flatpak_packages_installed
}
tailscalecmd() {
if is_wsl; then
printfe "%s\n" "yellow" "Running in WSL, skipping Tailscale."
return
fi
printfe "%s\n" "cyan" "Ensuring Tailscale is installed..."
source $HOME/dotfiles/bin/helpers/tailscale.sh
ensure_tailscale_installed
}
####################################################################################################
# Update system settings
####################################################################################################
git_repos() {
####################################################################################################
# Ensure git repos
####################################################################################################
printfe "%s\n" "cyan" "Ensuring git repos..."
source $HOME/dotfiles/bin/helpers/git.sh
ensure_git_repos
}
homemanager() {
# Due to weirdness delete this file if it exists
if [ -f "$HOME/.config/mimeapps.list.backup" ]; then
@ -202,41 +173,22 @@ homemanager() {
cd $HOME/dotfiles/config/home-manager && NIXPKGS_ALLOW_UNFREE=1 home-manager switch -b backup --flake .#$DOTF_HOSTNAME --impure
}
ensure_homemanager_installed() {
if [ ! -x "$(command -v home-manager)" ]; then
printfe "%s\n" "yellow" "Home Manager is not installed, installing it..."
nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
printfe "%s\n" "yellow" "Home Manager installed, please run the script again."
exit 1
fi
}
####################################################################################################
# Parse arguments
####################################################################################################
# Multiple options can be passed to the script, for example:
# ./update.sh --git --symlinks --packages
# If no options are passed, the script will run all functions
# Shift the first argument since this is the script name
shift
if [ "$#" -eq 0 ]; then
printfe "%s\n" "yellow" "No options passed, running full update..."
ensure_homemanager_installed
symlinks
sys_packages
homemanager
cargopkgs
pipxpkgs
git_repos
flatpakpkgs
tailscalecmd
dotf secrets encrypt
else
for arg in "$@"; do
@ -254,9 +206,6 @@ else
sys_packages
homemanager
;;
--git)
git_repos
;;
--symlinks)
symlinks
;;
@ -265,7 +214,6 @@ else
cargopkgs
pipxpkgs
flatpakpkgs
tailscalecmd
;;
--pipx)
pipxpkgs
@ -276,9 +224,6 @@ else
--flatpak)
flatpakpkgs
;;
--tailscale)
tailscalecmd
;;
*)
printfe "%s\n" "red" "Unknown option: $arg"
;;

137
bin/dotf
View File

@ -1,76 +1,105 @@
#!/usr/bin/env bash
source $HOME/dotfiles/bin/helpers/functions.sh
export DOTFILES_CONFIG=$HOME/dotfiles/config/config.yaml
# strict mode
set -euo pipefail
IFS=$'\n\t'
status() {
$HOME/dotfiles/bin/actions/status.sh $@
}
# Script constants
readonly DOTFILES_ROOT="$HOME/dotfiles"
readonly DOTFILES_BIN="$DOTFILES_ROOT/bin"
readonly DOTFILES_CONFIG="$DOTFILES_ROOT/config/config.yaml"
# Source helper functions
if [[ ! -f "$DOTFILES_BIN/helpers/functions.sh" ]]; then
echo "Error: Required helper functions not found"
exit 1
fi
source "$DOTFILES_BIN/helpers/functions.sh"
export DOTFILES_CONFIG
# Command functions
update() {
$HOME/dotfiles/bin/actions/update.sh $@
local update_script="$DOTFILES_BIN/actions/update.sh"
if [[ ! -x "$update_script" ]]; then
printfe "%s\n" "red" "Error: Update script not found or not executable"
return 1
fi
"$update_script" "$@"
}
help() {
$HOME/dotfiles/bin/actions/help.sh $@
local help_script="$DOTFILES_BIN/actions/help.sh"
if [[ ! -x "$help_script" ]]; then
printfe "%s\n" "red" "Error: Help script not found or not executable"
return 1
fi
"$help_script" "$@"
}
secrets() {
$HOME/dotfiles/bin/actions/secrets.sh $@
}
push() {
$HOME/dotfiles/bin/actions/push.sh $@
local secrets_script="$DOTFILES_BIN/actions/secrets.sh"
if [[ ! -x "$secrets_script" ]]; then
printfe "%s\n" "red" "Error: Secrets script not found or not executable"
return 1
fi
"$secrets_script" "$@"
}
ensure_git_hooks() {
# If ~/dotfiles/.git/hooks is a symlink, skip this
if [[ -L ~/dotfiles/.git/hooks ]]; then
# Let's make sure the symlink is correct
if [[ $(readlink ~/dotfiles/.git/hooks) != $HOME/dotfiles/bin/actions/git ]]; then
printfe "%s\n" "yellow" "The ~/dotfiles/.git/hooks symlink is incorrect. Please remove it and run this script again."
local hooks_dir="$DOTFILES_ROOT/.git/hooks"
local target_link="$DOTFILES_BIN/actions/git"
# Validate target directory exists
if [[ ! -d "$target_link" ]]; then
printfe "%s\n" "red" "Error: Git hooks source directory does not exist: $target_link"
return 1
fi
# Handle existing symlink
if [[ -L "$hooks_dir" ]]; then
local current_link
current_link=$(readlink "$hooks_dir")
if [[ "$current_link" != "$target_link" ]]; then
printfe "%s\n" "yellow" "Incorrect git hooks symlink found. Removing and recreating..."
rm "$hooks_dir"
else
return 0
fi
return
fi
if [[ -d ~/dotfiles/.git/hooks ]]; then
rm -rf ~/dotfiles/.git/hooks
printfe "%s\n" "yellow" "The ~/dotfiles/.git/hooks directory already exists. We're removing it!"
# Handle existing directory
if [[ -d "$hooks_dir" ]]; then
printfe "%s\n" "yellow" "Removing existing hooks directory..."
rm -rf "$hooks_dir"
fi
ln -s $HOME/dotfiles/bin/actions/git ~/dotfiles/.git/hooks
printfe "%s\n" "green" "Git hooks are now set up!"
# Create new symlink
if ln -s "$target_link" "$hooks_dir"; then
printfe "%s\n" "green" "Git hooks successfully configured!"
else
printfe "%s\n" "red" "Failed to create git hooks symlink"
return 1
fi
}
ensure_git_hooks
main() {
# Ensure we're in the correct directory
if [[ ! -d "$DOTFILES_ROOT" ]]; then
printfe "%s\n" "red" "Error: Dotfiles directory not found"
exit 1
fi
# switch case for parameters
case $1 in
"update")
logo
update $@
;;
"push")
logo continue
push $@
;;
"help"|"--help"|"")
help $@
;;
"secrets")
secrets $@
;;
"term")
$HOME/dotfiles/bin/actions/term.sh $@
;;
"auto-start"|"-a"|"-auto-start"|"as")
$HOME/dotfiles/bin/actions/auto-start.sh $@
;;
"hotkey-daemon")
x-terminal-emulator -e $HOME/dotfiles/bin/actions/hotkey-daemon.sh $@
;;
*)
printfe "%s\n" "red" "Unknown command $1"
help $@
;;
esac
# Setup git hooks
ensure_git_hooks || exit 1
# Parse commands
case "${1:-help}" in
update) shift; update "$@" ;;
help) shift; help "$@" ;;
secrets) shift; secrets "$@" ;;
*) help ;;
esac
}
main "$@"

View File

@ -1,127 +0,0 @@
#!/usr/bin/env bash
source $HOME/dotfiles/bin/helpers/functions.sh
ensure_git_repos() {
# Load config file with git repos:
repos=($(cat $HOME/dotfiles/config/config.yaml | shyaml keys config.git))
# For each repo in the config file, ensure it is cloned (url + branch, if specified)
for repo in "${repos[@]}"; do
url=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.git.$repo.url)
branch=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.git.$repo.branch)
target=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.git.$repo.target)
target_dirty=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.git.$repo.target)
# Replace ~ with $HOME
target="${target/#\~/$HOME}"
# If no url is specified, skip this repo
if [ -z "$url" ]; then
printfe "%s\n" "red" " - No URL specified for $repo, skipping"
continue
fi
# If no branch is specified, default to main
if [ -z "$branch" ]; then
branch="main"
printfe "%s\n" "yellow" " - No branch specified for $repo, defaulting to $branch"
fi
# If no target is specified, stop since we have no idea where to expect to put the repo
if [ -z "$target" ]; then
printfe "%s\n" "red" " - No target specified for $repo, skipping"
continue
fi
# If the target directory does not exist, clone the repo there with the specified branch
if [ ! -d "$target" ]; then
printfe "%s\n" "green" " - Cloning $repo to $target"
result=$(git clone --branch $branch $url $target 2>&1)
# If the clone failed, print an error
if [ $? -ne 0 ]; then
printfe "%s\n" "red" " - Failed to clone $repo to $target:"
printfe "%s\n" "red" " $result"
continue
fi
else
# If the target directory exists, check if it is a git repo
if [ -d "$target/.git" ]; then
# If it is a git repo, check if the remote is the same as the one specified in the config file
remote=$(git -C $target remote get-url origin)
if [ "$remote" != "$url" ]; then
# If the remote is different, print a warning
printfe "%s" "yellow" " - $target is a git repo, but the remote (origin) is different from the one in the config file. Replace it? [y/N] "
read -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
printfe "%s\n" "green" " - Replacing remote in $target with $url"
git -C $target remote set-url origin $url
fi
# Fast-forward the repo but only if it's in the correct branch
current_branch=$(git -C $target rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "$branch" ]; then
printfe "%s\n" "yellow" " - $target is a git repo, but it's not in the expected branch ($current_branch instead of $branch)"
else
printfe "%s\n" "green" " - Fast-forwarding $target"
result=$(git -C $target pull 2>&1)
# If the pull failed, print an error
if [ $? -ne 0 ]; then
printfe "%s\n" "red" " - Failed to fast-forward $target:"
printfe "%s\n" "red" " $result"
fi
fi
else
# Fast-forward the repo but only if it's in the correct branch
current_branch=$(git -C $target rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "$branch" ]; then
printfe "%s\n" "yellow" " - $target is a git repo, but it's not in the expected branch ($current_branch instead of $branch)"
else
printfe "%s\n" "green" " - Fast-forwarding $target"
result=$(git -C $target pull 2>&1)
# If the pull failed, print an error
if [ $? -ne 0 ]; then
printfe "%s\n" "red" " - Failed to fast-forward $target:"
printfe "%s\n" "red" " $result"
fi
fi
fi
else
# If the target directory exists but is not a git repo, print a warning
printfe "%s\n" "red" " - $target exists but is not a git repo?! Skipping"
fi
fi
# Print state of the repo example: "repo (branch) -> [target] ([untracked files] [unstaged changes] [staged changes] [unpushed commits])"
untracked=$(git -C $target status --porcelain | grep -c '^??')
unstaged=$(git -C $target status --porcelain | grep -c '^ M')
staged=$(git -C $target status --porcelain | grep -c '^M ')
unstaged_changes=$(git -C $target status --porcelain | grep -c '^M')
unpushed_commits=$(git -C $target log origin/$branch..HEAD --oneline | wc -l | tr -d ' ')
printfe "%s" "blue" " - $repo ($branch) -> [$target_dirty]"
if [ $untracked -gt 0 ]; then
printfe "%s" "red" " [$untracked] untracked"
fi
if [ $unstaged -gt 0 ]; then
printfe "%s" "yellow" " [$unstaged] modified"
fi
printfe "%s" "green" " [$staged]"
if [ $unstaged_changes -gt 0 ]; then
printfe "%s" "red" " [$unstaged_changes] unstaged changes"
fi
if [ $unpushed_commits -gt 0 ]; then
printfe "%s" "yellow" " [!] You have [$unpushed_commits] unpushed commits"
fi
echo
done
}

View File

@ -1,33 +0,0 @@
#!/usr/bin/env bash
ensure_tailscale_installed() {
# if tailscale is already installed, skip the installation
if [ -x "$(command -v tailscale)" ]; then
printfe "%s\n" "green" " - Tailscale is already installed"
return
fi
result=$(curl -fsSL https://tailscale.com/install.sh | sh)
# Ensure it ended with something like Installation complete
if [[ $result == *"Installation complete"* ]]; then
# Check if it successfully installed
if [ -x "$(command -v tailscale)" ]; then
printfe "%s\n" "green" " - Tailscale is installed"
else
printfe "%s\n" "red" " - Tailscale is not installed"
printfe "%s\n" "red" " Something went wrong while installing Tailscale, investigate the issue"
exit 1
fi
else
printfe "%s\n" "red" " - Tailscale is not installed"
printfe "%s\n" "red" " Something went wrong while installing Tailscale, investigate the issue"
exit 1
fi
# Let's set the current user to the operator
sudo tailscale set --operator=$USER
# Start the service
tailscale up
}

View File

@ -5,5 +5,7 @@ Usage: dotf [options] [optional parameters]
update: Pull latest changes, and update symlinks and configurations.
status: Show the status of the dotfiles repository.
secrets: Encrypt and decrypt secrets.
auto-start: Runs various programs for easy startup in case GNOME doesn't properly auto-start them.
term: Shows the welcome message for the terminal and the current dotfiles git status.
help: Shows this help message

View File

@ -1,28 +0,0 @@
You are an assistant, you are getting prompted by an automated bash script on boot-up of Menno's computer $HOSTNAME. Menno is a software engineer who loves to automate everything. (Menno van Leeuwen)
This script starts up all his stuff on the PC and your task is quite silly but simple:
- Give menno a nice and comedy welcome.
- Keep it short and concise but funny.
Rules:
- Do not actually output any bash/zsh scripting, just a message to Menno for his entertainment.
- No open and closing quotes, tags or any syntax that would indicate this is a script.
- Be creative, Menno loves a good laugh.
- Output in a nice format that's easily to read.
- Make sure to include the forecast.
- You don't have to always make it centered about code, but it's a good start.
- You don't have to include every topic mentioned, just pick a couple and make it funny.
Topics:
- Weekend coming up (If it's Friday or half way through the week and desperate for the weekend)
- A beer is always a good idea in the weekend (Only applicable on Friday, Saturday or Sunday)
- The weather (Menno loves to know the weather)
- Space, stars, planets, etc
- Programming
- Gaming
- Astrophotography
- Trying to avoid death scrolling on Reddit, Youtube, etc
For funs here is some maybe or maybe not so relevant info:
- The time now is $TIME ($DATE)
- The current weather and moon phase follows: $WEATHER
- The moon phase is as follows: $MOON_PHASE

View File

@ -61,21 +61,6 @@ config:
source: ~/dotfiles/config/starship.toml
target: ~/.config/starship.toml
git:
dotfiles:
url: git@git.mvl.sh:vleeuwenmenno/dotfiles.git
branch: master
target: ~/dotfiles
ssdc_app_v2:
url: git@github.com:vleeuwenmenno/ssdc_app_v2.git
branch: master
target: ~/Projects/Private/ssdc_app_v2
infra:
url: git@github.com:tradaware/infra.git
branch: main
target: ~/Projects/Work
# Packages to install
# Note: Uninstalling packages is not supported, if you remove a package from this list it will not be removed from the system!