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/bin/init-dotfiles

90 lines
2.5 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
# NOTE: run this from inside a NixOS installation, not from the live USB/CD
2020-10-26 16:39:09 -05:00
root_home="/root"
daniel_home="/home/daniel/.home"
nice_home="/home/daniel"
2020-11-06 00:31:43 -06:00
dotfiles="/.config/lytedev-dotfiles"
add_unstable_channel() {
nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
nix-channel --update
}
clone_dotfiles() {
echo "Setting up dotfiles for root..."
mkdir --parents "$1"
git clone "https://git.lyte.dev/lytedev/dotfiles" "$1"
}
symlink_nixos() {
rm --force "/etc/nixos/lytedev"
ln --symbolic "$1" "/etc/nixos/lytedev"
}
setup_wallpaper() {
2020-10-26 16:39:09 -05:00
mkdir --parents "$nice_home/img/walls"
curl --silent --output "$nice_home/img/walls/clouds_by_souredapply.png" \
"https://art.ngfiles.com/images/530000/530895_souredapple_clouds.png"
2020-10-26 16:39:09 -05:00
rm --recursive --force "$daniel_home/.wallpaper"
ln --symbolic "$nice_home/img/walls/clouds_by_souredapply.png" "$daniel_home/.wallpaper"
}
generate_ssh_key() {
2020-10-26 16:39:09 -05:00
mkdir --mode 600 --parents "$daniel_home/.ssh"
keyfile="$daniel_home/.ssh/$(hostname --short)"
ssh-keygen -N '' -t ed25519 -f "$keyfile"
mkdir --mode 640 --parents "$nice_home/public"
cp "$keyfile.pub" "$nice_home/public"
ssh-add "$keyfile"
}
fix_dotfiles_origin() {
2020-10-26 16:39:09 -05:00
cd "$daniel_home$dotfiles"
git remote set-url origin "ssh://git@git.lyte.dev:2222/lytedev/dotfiles.git"
}
2020-10-27 17:10:54 -05:00
setup_home_manager() {
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
}
init_for_root() {
2020-10-26 16:39:09 -05:00
clone_dotfiles "$root_home$dotfiles"
symlink_nixos "$root_home$dotfiles/env/nix/"
add_unstable_channel
nixos-rebuild switch
2020-10-26 16:39:09 -05:00
chown daniel:users "$daniel_home"
echo "Re-running as user daniel..."
2020-10-26 16:39:09 -05:00
sudo --user daniel "$root_home$dotfiles/init.sh"
}
init_for_daniel() {
2020-10-26 16:39:09 -05:00
clone_dotfiles "$daniel_home$dotfiles"
generate_ssh_key
2020-10-26 16:39:09 -05:00
symlink_nixos "$daniel_home$dotfiles/env/nix/"
setup_wallpaper
# TODO: setup ssh/gpg keys
# TODO: setup password store
fix_dotfiles_origin
}
2020-11-06 00:42:19 -06:00
if [ "$EUID" -eq 0 ]; then
init_for_root
else
init_for_daniel
fi
echo "Here is this machine's public SSH key:"
2020-10-26 16:39:09 -05:00
echo " $(cat "$daniel_home/.ssh/$(hostname --short).pub")"
echo "It needs to be added to existing cloud-based git accounts"
echo "and other machines before proceeding."
echo
echo "Don't forget to setup GPG keys by importing from an existing machine"
echo "or adding new child keys!"
echo
echo "The simplest method for doing this is to run the following:"
echo ' scp -r "$TARGET_MACHINE:~/.gnupg" "$HOME/.gnupg"