This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/common/bin/dotfiles-init

57 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-04-13 14:04:29 -05:00
#!/usr/bin/env bash
2021-03-25 09:04:51 -05:00
export dfp
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export ENV_PATH="$XDG_CONFIG_HOME/lytedev-env"
export CURDIR
2023-04-13 14:04:29 -05:00
mkdir -p "$ENV_PATH"
mkdir -p "$XDG_CONFIG_HOME"
2021-03-25 09:04:51 -05:00
dfp="$(realpath "$(dirname "$0")"/../..)"
2023-04-13 14:04:29 -05:00
# may not be running from inside the dotfiles repo, may have been curl'd down solo, so we need to check
if [[ ! -d "$dfp/.git" ]]; then
echo "Not running from inside the dotfiles git repo, so we need to download it first!"
2023-04-16 02:26:30 -05:00
# each os needs instructions to install git, then we can clone the repo and proceed
2023-04-16 02:30:45 -05:00
if ! command -v git; then
if head /etc/os-release --lines 1 | grep 'Arch Linux' > /dev/null 2>&1; then
if [[ "$EUID" -ne 0 ]]; then
if ! command -v sudo; then
echo "Error: No sudo command available to try and install 'git'"
exit 1
else
sudo pacman -Sy --needed git
fi
else
pacman -Sy --needed git
fi
fi
2023-04-16 02:26:30 -05:00
fi
2023-04-16 02:32:00 -05:00
dfp="$XDG_CONFIG_HOME/lytedev-dotfiles"
2023-04-16 02:26:30 -05:00
git clone https://git.lyte.dev/lytedev/dotfiles.git "$dfp"
2023-04-13 14:04:29 -05:00
fi
2023-04-16 02:26:30 -05:00
# auto-link any OS-specific environments
2023-04-13 14:04:29 -05:00
if head /etc/os-release --lines 1 | grep 'NixOS$' > /dev/null 2>&1; then
ln -s "$dfp/os/linux/nix" "$ENV_PATH/os-linux-nix" > /dev/null 2>&1
elif head /etc/os-release --lines 1 | grep 'Arch Linux' > /dev/null 2>&1; then
ln -s "$dfp/os/linux/arch" "$ENV_PATH/os-linux-arch" > /dev/null 2>&1
fi
2023-04-16 02:26:30 -05:00
# perform any pre-requisite setup (includes OS-specific setup scripts since we
# just included those)
2023-04-13 14:04:29 -05:00
for s in "$ENV_PATH"/*; do
f="$s/dotfiles-init.d.sh"
if [ -f "$f" ]; then
echo "dotfiles-init: Running $f..."
CURDIR="$s" "$f"
fi
2023-04-13 14:04:29 -05:00
done
2021-03-25 09:04:51 -05:00
2023-04-16 02:26:30 -05:00
# perform final dotfiles setup
2023-04-13 14:04:29 -05:00
echo "dotfiles-init: Running setup..."
"$dfp/common/bin/dotfiles-setup"
2023-04-16 02:38:29 -05:00
# TODO: setup personal files? (ssh keys, gpg keys, password stores, notes)
2023-04-16 02:26:30 -05:00
# these are probably best handled in a dotfiles-init.d.sh script in a particular layer