This commit is contained in:
Menno van Leeuwen 2024-08-27 15:58:09 +02:00
parent f532a924fb
commit 3f5b980ddc
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE
5 changed files with 77 additions and 29 deletions

View File

@ -70,6 +70,11 @@ ensure_symlink() {
source=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.source) &>/dev/null
fi
# If this is still empty, last attempt, let's try use the hostname of the machine
if [ -z "$source" ]; then
source=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.sources.$(hostname)) &>/dev/null
fi
# If this is still empty, we can't continue and should throw up an error
if [ -z "$source" ]; then
printfe "%s\n" "red" " - No valid source defined for $1"
@ -77,6 +82,22 @@ ensure_symlink() {
fi
check_or_make_symlink $source $target
# Let's check if there was a chmod defined for the symlink
chmod=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.symlinks.$1.chmod 2>/dev/null)
if [ -n "$chmod" ]; then
# Let's see if the current target has the correct chmod
current_chmod=$(stat -c %a $target)
if [ "$current_chmod" != "$chmod" ]; then
printfe "%s" "yellow" " - Changing chmod of $target to $chmod"
# Replace ~ with $HOME in target
target=$(echo $target | sed "s|~|$HOME|g")
chmod $chmod $target
else
return
fi
fi
}
symlinks() {

View File

@ -157,41 +157,57 @@ add_to_hosts() {
# $1: file to check
# $2: link location
check_or_make_symlink() {
if [ ! -L $1 ]; then
if [ -f $1 ]; then
mv $1 $1.bak
printfe "%s\n" "yellow" " - Backed up $1 to $1.bak"
fi
mkdir -p $(dirname $1)
ln -s $2 $1
printfe "%s\n" "green" " - Created symlink $2 -> $1"
return
fi
SOURCE=$1
TARGET=$2
# Confirm the symlink that already exists point to the correct location
if [ -L $1 ]; then
if [ "$(readlink $1)" != $2 ]; then
printfe "%s\n" "yellow" " - Symlink $1 exists but points to the wrong location"
printfe "%s\n" "yellow" " Expected: $2"
printfe "%s\n" "yellow" " Actual: $(readlink $1)"
# Take any ~ and replace it with $HOME
SOURCE=$(echo $SOURCE | sed "s|~|$HOME|g")
TARGET=$(echo $TARGET | sed "s|~|$HOME|g")
# If target is already a symlink, we should check if it points to the correct location
if [ -L $TARGET ]; then
if [ "$(readlink $TARGET)" != "$SOURCE" ]; then
printfe "%s\n" "yellow" " - Symlink $TARGET exists but points to the wrong location"
printfe "%s\n" "yellow" " Expected: $SOURCE"
printfe "%s\n" "yellow" " Actual: $(readlink $TARGET)"
printfe "%s\n" "yellow" " Fixing symlink"
rm $1
mkdir -p $(dirname $1)
ln -s $2 $1
printfe "%s\n" "green" " Created symlink $2 -> $1"
rm $TARGET
mkdir -p $(dirname $TARGET)
ln -s $SOURCE $TARGET
printfe "%s\n" "green" " Created symlink $TARGET -> $SOURCE"
return
fi
fi
if [ ! -L $1 ]; then
printfe "%s\n" "red" " - Failed to create symlink $2 -> $1"
# If target is a file and it's not a symlink, we should back it up
if [ -f $TARGET ] && [ ! -L $TARGET ]; then
printfe "%s\n" "yellow" " - File $TARGET exists, backing up and creating symlink"
mv $TARGET $TARGET.bak
fi
# If the target is already a symlink, and it points to the correct location, we should return and be happy
if [ -L $TARGET ]; then
printfe "%s" "green" " - OK: "
printfe "%-30s" "blue" "$SOURCE"
printfe "%s" "cyan" " -> "
printfe "%-30s\n" "blue" "$TARGET"
return
fi
printfe "%s" "green" " - OK: "
printfe "%-30s" "blue" "$1"
# Create the symlink
mkdir -p $(dirname $TARGET)
ln -s $SOURCE $TARGET
# Check if the symlink was created successfully
if [ ! -L $TARGET ]; then
printfe "%s\n" "red" " - Failed to create symlink $TARGET -> $SOURCE"
return
fi
printfe "%s" "green" " - Added new symlink: "
printfe "%-30s" "blue" "$SOURCE"
printfe "%s" "cyan" " -> "
printfe "%-30s\n" "blue" "$2"
printfe "%-30s\n" "blue" "$TARGET"
}
clear_line() {

View File

@ -17,6 +17,14 @@ config:
source: ~/dotfiles/config/ssh/config.d
target: ~/.ssh/config.d
ssh_authorized_keys:
sources:
mennos-laptop: ~/dotfiles/config/ssh/authorized_keys/mennos-laptop
mennos-desktop: ~/dotfiles/config/ssh/authorized_keys/mennos-desktop
homeserver-pc: ~/dotfiles/config/ssh/authorized_keys/homeserver-pc
target: ~/.ssh/authorized_keys
chmod: 600
# Zshrc
zshrc:
source: ~/dotfiles/.zshrc
@ -56,7 +64,7 @@ config:
command: alacritty
screenshot:
shortcut: Shift + Alt + 4
command: cosmic-screenshot --interactive
command: flameshot gui
missioncenter:
shortcut: Ctrl + Shift + Escape
command: flatpak run io.missioncenter.MissionCenter
@ -122,10 +130,10 @@ config:
fd-find:
procs:
bottom:
swhkd:
Simple-Wayland-HotKey-Daemon:
git_url: https://github.com/waycrate/swhkd.git
binary: Simple-Wayland-HotKey-Daemon
swhkd:
swhks:
git_url: https://github.com/waycrate/swhkd.git
binary: swhks
@ -151,7 +159,6 @@ config:
- vim
- sl
- jq
# - just
- libglvnd-dev
- libwayland-dev
- libseat-dev

View File

@ -0,0 +1,2 @@
# This is the authrorized_keys file for the user mennos-desktop
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM+sKpcREOUjwMMSzEWAso6830wbOi8kUxqpuXWw5gHr

View File

@ -0,0 +1,2 @@
# This is the authrorized_keys file for the user mennos-laptop
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM+sKpcREOUjwMMSzEWAso6830wbOi8kUxqpuXWw5gHr