WSL fixes
This commit is contained in:
22
bin/1password-agent-bridge.sh
Executable file
22
bin/1password-agent-bridge.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
# Check if is_wsl function returns true, don't continue if we are not on WSL
|
||||
if ! is_wsl; then
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s" "cyan" "Running in WSL, ensuring 1Password SSH-Agent relay is running..."
|
||||
|
||||
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
|
||||
ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?)
|
||||
if [[ $ALREADY_RUNNING != "0" ]]; then
|
||||
if [[ -S $SSH_AUTH_SOCK ]]; then
|
||||
rm $SSH_AUTH_SOCK
|
||||
fi
|
||||
|
||||
(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1
|
||||
printfe "%s\n" "green" " [ Started ]"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printfe "%s\n" "green" " [ Already running ]"
|
@@ -10,7 +10,7 @@ push_all() {
|
||||
printfe "%s\n" "cyan" "Pushing all changes to all remotes..."
|
||||
|
||||
# For each remote, push all changes
|
||||
for remote in $remotes; do
|
||||
for remote in "${remotes[@]}"; do
|
||||
printfe "%s" "green" " - Pushing to ["
|
||||
printfe "%s" "blue" "$remote"
|
||||
printfe "%s\n" "green" "]..."
|
||||
|
@@ -8,23 +8,43 @@ source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
printfe "%s\n" "cyan" "Fetching password from 1Password..."
|
||||
echo -en '\r'
|
||||
|
||||
# if WSL alias op to op.exe
|
||||
if [[ $(uname -a) == *"microsoft-standard-WSL2"* ]]; then
|
||||
alias op="op.exe"
|
||||
if is_wsl; then
|
||||
output=$(op.exe item get "Dotfiles Secrets" --fields password)
|
||||
else
|
||||
alias op="op"
|
||||
output=$(op item get "Dotfiles Secrets" --fields password)
|
||||
fi
|
||||
|
||||
output=$(op item get "Dotfiles Secrets" --fields password)
|
||||
|
||||
# Check if the password was found
|
||||
if [[ -z "$output" ]]; then
|
||||
printfe "%s\n" "red" "Password not found in 1Password, add a login item with the name 'Dotfiles Secrets' and give it a password."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
command=$(echo "$output" | grep -oP "(?<=use ').*(?=')")
|
||||
password=$(eval $command | grep -oP "(?<= password: ).*" | tr -d '\n')
|
||||
token=$(echo "$output" | grep -oP "(?<=\[use 'op item get ).*(?= --)")
|
||||
printfe "%s\n" "cyan" "Got fetch token: $token"
|
||||
|
||||
if is_wsl; then
|
||||
password=$(op.exe item get $token --reveal --field password)
|
||||
else
|
||||
password=$(op item get $token --reveal --fields password)
|
||||
fi
|
||||
|
||||
# only continue if password isn't empty
|
||||
if [[ -z "$password" ]]; then
|
||||
printfe "%s\n" "red" "Something went wrong while fetching the password from 1Password."
|
||||
|
||||
# Ask for manual input
|
||||
printfe "%s" "cyan" "Enter the password manually: "
|
||||
read -s password
|
||||
echo
|
||||
|
||||
if [[ -z "$password" ]]; then
|
||||
printfe "%s\n" "red" "Password cannot be empty."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printfe "%s\n" "green" "Password entered successfully."
|
||||
fi
|
||||
|
||||
encrypt_folder() {
|
||||
for file in $1/*; do
|
||||
|
@@ -11,6 +11,11 @@ countdown() {
|
||||
}
|
||||
|
||||
run_startup_scripts() {
|
||||
if is_wsl; then
|
||||
echo "Running in WSL, skipping startup scripts."
|
||||
return
|
||||
fi
|
||||
|
||||
logo continue
|
||||
echo ""
|
||||
local time_of_day
|
||||
|
@@ -97,7 +97,7 @@ symlinks() {
|
||||
symlinks=($(cat $HOME/dotfiles/config/config.yaml | shyaml keys config.symlinks))
|
||||
printfe "%s\n" "cyan" "Updating symlinks..."
|
||||
|
||||
for symlink in $symlinks; do
|
||||
for symlink in "${symlinks[@]}"; do
|
||||
ensure_symlink $symlink
|
||||
done
|
||||
}
|
||||
@@ -155,6 +155,11 @@ pipxpkgs() {
|
||||
}
|
||||
|
||||
flatpakpkgs() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping Flatpak."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring Flatpak packages are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/flatpak_packages.sh
|
||||
ensure_flatpak_packages_installed
|
||||
@@ -167,12 +172,22 @@ dockercmd() {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
extensions() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping extensions."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring GNOME Extensions are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/gnome_extensions.sh
|
||||
ensure_gnome_extensions_installed
|
||||
@@ -194,18 +209,33 @@ extensions() {
|
||||
####################################################################################################
|
||||
|
||||
keyboard() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping keyboard shortcuts."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Setting up keyboard shortcuts..."
|
||||
source $HOME/dotfiles/bin/helpers/keyboard_shortcuts.sh
|
||||
ensure_keyboard_shortcuts
|
||||
}
|
||||
|
||||
fonts() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping fonts."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Ensuring fonts are installed..."
|
||||
source $HOME/dotfiles/bin/helpers/fonts.sh
|
||||
ensure_fonts_installed
|
||||
}
|
||||
|
||||
terminal() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping setting default terminal."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "cyan" "Setting gnome-terminal as default terminal..."
|
||||
if [ -x "$(command -v gnome-terminal)" ]; then
|
||||
current_terminal=$(sudo update-alternatives --query x-terminal-emulator | grep '^Value:' | awk '{print $2}')
|
||||
@@ -270,8 +300,8 @@ if [ "$#" -eq 0 ]; then
|
||||
aptpkgs
|
||||
cargopkgs
|
||||
pipxpkgs
|
||||
flatpakpkgs
|
||||
dockercmd
|
||||
flatpakpkgs
|
||||
tailscalecmd
|
||||
extensions
|
||||
keyboard
|
||||
|
@@ -71,7 +71,7 @@ ensure_repositories() {
|
||||
add_vscode_repo
|
||||
|
||||
repos=($(cat $DOTFILES_CONFIG | shyaml get-values config.packages.apt.repos))
|
||||
for repo in $repos; do
|
||||
for repo in "${repos[@]}"; do
|
||||
repo_name=$(echo $repo | cut -d ":" -f 2)
|
||||
|
||||
# Go through sources.list.d and check if there's a file containing part of URIs: https://ppa.launchpad.net/$repo_name
|
||||
@@ -94,8 +94,9 @@ ensure_repositories() {
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
ensure_apt_packages_installed() {
|
||||
apt_packages=($(cat $DOTFILES_CONFIG | shyaml get-values config.packages.apt.apps))
|
||||
apt_packages=($(cat $DOTFILES_CONFIG | shyaml get-values config.packages.apt.apps | tr '\n' ' '))
|
||||
|
||||
# Check if apt_packages array contains duplicates
|
||||
if [ $(echo $apt_packages | tr ' ' '\n' | sort | uniq -d | wc -l) -ne 0 ]; then
|
||||
@@ -105,7 +106,7 @@ ensure_apt_packages_installed() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for package in $apt_packages; do
|
||||
for package in "${apt_packages[@]}"; do
|
||||
pkg_status=$(dpkg -s $package 2> /dev/null | grep "Status" | cut -d " " -f 4)
|
||||
|
||||
# If pkg_status is `installed` then we don't need to install the package, otherwise if it's empty then the package is not installed
|
||||
@@ -140,7 +141,7 @@ print_apt_status() {
|
||||
count=$(echo $apt_packages | wc -w)
|
||||
installed=0
|
||||
|
||||
for package in $apt_packages; do
|
||||
for package in "${apt_packages[@]}"; do
|
||||
pkg_status=$(dpkg -s $package 2> /dev/null | grep "Status" | cut -d " " -f 4)
|
||||
|
||||
if [ "$pkg_status" = "installed" ]; then
|
||||
|
@@ -14,7 +14,7 @@ ensure_cargo_packages_installed() {
|
||||
binary=$(cat $DOTFILES_CONFIG | shyaml get-value config.packages.cargo.$package.binary 2>/dev/null)
|
||||
|
||||
# If pkg_status is `installed` then we don't need to install the package, otherwise if it's empty then the package is not installed
|
||||
if [ -z $pkg_status ]; then
|
||||
if [ -z "$pkg_status" ]; then
|
||||
ensure_sudo_privileges "In order to install $package, please provide your password:"
|
||||
printfe "%s" "yellow" " - Compiling/Installing $package... (This may take a while)"
|
||||
clear_line
|
||||
@@ -50,7 +50,7 @@ print_cargo_status() {
|
||||
count=$(echo $cargo_packages | wc -w)
|
||||
installed=0
|
||||
|
||||
for package in $cargo_packages; do
|
||||
for package in "${cargo_packages[@]}"; do
|
||||
pkg_status=$(cargo install --list | grep -E "^${package}\sv[0-9.]+:$")
|
||||
|
||||
if [ -z $pkg_status ]; then
|
||||
|
@@ -5,7 +5,7 @@ source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
ensure_flatpak_packages_installed() {
|
||||
flatpak_packages=($(ls $HOME/dotfiles/config/flatpaks/ | sed 's/.flatpakref//g'))
|
||||
|
||||
for package in $flatpak_packages; do
|
||||
for package in "${flatpak_packages[@]}"; do
|
||||
if ! flatpak list | grep -q $package; then
|
||||
printfe "%s\n" "cyan" " - Installing $package..."
|
||||
flatpak install -y flathub $package
|
||||
@@ -22,6 +22,11 @@ ensure_flatpak_packages_installed() {
|
||||
}
|
||||
|
||||
print_flatpak_status() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping Flatpak packages check."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s" "cyan" "Checking Flatpak packages..."
|
||||
clear_line
|
||||
|
||||
@@ -30,7 +35,7 @@ print_flatpak_status() {
|
||||
count=$(echo $flatpak_packages | wc -w)
|
||||
installed=0
|
||||
|
||||
for package in $flatpak_packages; do
|
||||
for package in "${flatpak_packages[@]}"; do
|
||||
if flatpak list | grep -q $package; then
|
||||
installed=$((installed + 1))
|
||||
else
|
||||
|
@@ -6,6 +6,15 @@ println() {
|
||||
printfe "%s\n" $color "$1"
|
||||
}
|
||||
|
||||
is_wsl() {
|
||||
unameres=$(uname -a | grep -i "microsoft" | wc -l)
|
||||
if [ -n "$unameres" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
logo() {
|
||||
tput setaf 2
|
||||
cat $HOME/dotfiles/bin/resources/logo.txt
|
||||
|
@@ -7,7 +7,7 @@ ensure_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
|
||||
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)
|
||||
|
@@ -3,6 +3,11 @@
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
ensure_gnome_extensions_installed() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping GNOME extensions."
|
||||
return
|
||||
fi
|
||||
|
||||
# In case gnome-extensions is installed but we don't use GNOME let's do a check
|
||||
if [ "$XDG_CURRENT_DESKTOP" != "GNOME" ]; then
|
||||
printfe "%s\n" "red" " - XDG_CURRENT_DESKTOP is not GNOME, likely not running GNOME."
|
||||
|
@@ -30,6 +30,11 @@ ensure_swhkd() {
|
||||
}
|
||||
|
||||
ensure_keyboard_shortcuts() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping keyboard shortcuts."
|
||||
return
|
||||
fi
|
||||
|
||||
printfe "%s\n" "green" " - Setting up swhkd configuration..."
|
||||
ensure_swhkd
|
||||
|
||||
|
@@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $HOME/dotfiles/bin/helpers/functions.sh
|
||||
|
||||
ensure_ohmyzsh_installed() {
|
||||
if [ -d ~/.oh-my-zsh ]; then
|
||||
printfe "%s" "yellow" " - Updating Oh My Zsh..."
|
||||
echo -en "\r"
|
||||
|
||||
zstyle ':omz:update' verbose minimal
|
||||
result=$($ZSH/tools/upgrade.sh)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printfe "%s\n" "red" "Failed to update Oh My Zsh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if result contains "already at the latest version" then it's already up to date and we should say so
|
||||
if [[ $result == *"already at the latest version"* ]]; then
|
||||
printfe "%s\n" "green" " - Oh My Zsh is already up to date"
|
||||
else
|
||||
printfe "%s\n" "green" " - Oh My Zsh updated successfully"
|
||||
printfe "%s\n" "green" "$result"
|
||||
fi
|
||||
else
|
||||
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||
sh install.sh --unattended --keep-zshrc
|
||||
fi
|
||||
}
|
@@ -35,7 +35,7 @@ print_pipx_status() {
|
||||
count=$(echo $pipx_packages | wc -w)
|
||||
installed=0
|
||||
|
||||
for package in $pipx_packages; do
|
||||
for package in "${pipx_packages[@]}"; do
|
||||
if pipx list | grep -q $package; then
|
||||
installed=$((installed + 1))
|
||||
else
|
||||
|
@@ -7,7 +7,7 @@ ensure_user_groups() {
|
||||
users=($(cat $DOTFILES_CONFIG | shyaml keys config.user_groups))
|
||||
|
||||
# For each user, ensure they are in the correct groups
|
||||
for user in $users; do
|
||||
for user in "${users[@]}"; do
|
||||
# Ensure this user exists
|
||||
if [[ ! $(id -u $user) ]]; then
|
||||
printfe "%s\n" "red" " - User $user does not exist"
|
||||
@@ -25,7 +25,7 @@ ensure_user_in_groups() {
|
||||
printfe "%s\n" "cyan" " - For user $user..."
|
||||
|
||||
# For each group, ensure the user is in it
|
||||
for group in $groups; do
|
||||
for group in "${groups[@]}"; do
|
||||
# Check if the group exists at all, otherwise skip
|
||||
if [[ ! $(getent group $group) ]]; then
|
||||
printfe "%s\n" "red" " Group $group does not exist"
|
||||
|
@@ -13,6 +13,11 @@ load_vscode_extensions() {
|
||||
}
|
||||
|
||||
ensure_vscode_extensions_installed() {
|
||||
if is_wsl; then
|
||||
printfe "%s\n" "yellow" "Running in WSL, skipping VSCode extensions."
|
||||
return
|
||||
fi
|
||||
|
||||
# Load extensions list from jq in ~/dotfiles/vscode/extensions.json
|
||||
load_vscode_extensions
|
||||
|
||||
|
Reference in New Issue
Block a user