2020-11-07 22:43:55 -06:00
|
|
|
#!/usr/bin/env bash
|
2020-10-26 16:33:46 -05:00
|
|
|
|
2020-11-07 22:43:55 -06:00
|
|
|
head /etc/os-release --lines 1 | grep 'NixOS$' &>/dev/null; test $? -eq 1; is_nixos=$?
|
|
|
|
head /etc/os-release --lines 1 | grep 'Arch Linux' &>/dev/null; test $? -eq 1; is_arch_linux=$?
|
2020-11-07 21:56:10 -06:00
|
|
|
|
2020-11-06 00:50:13 -06:00
|
|
|
set -e
|
|
|
|
|
|
|
|
# NOTE: run this from inside a Linux installation, not from the live USB/CD
|
|
|
|
# TODO: detect OS and perform OS-specific setup
|
2020-10-26 16:33:46 -05:00
|
|
|
|
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"
|
2020-10-26 16:33:46 -05:00
|
|
|
|
|
|
|
add_unstable_channel() {
|
|
|
|
nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
|
|
|
|
nix-channel --update
|
|
|
|
}
|
|
|
|
|
|
|
|
clone_dotfiles() {
|
2020-11-06 00:50:13 -06:00
|
|
|
echo "Setting up dotfiles for $USER..."
|
2020-10-26 16:33:46 -05:00
|
|
|
mkdir --parents "$1"
|
2020-11-07 22:43:55 -06:00
|
|
|
rm --recursive --force "$1"
|
2020-11-07 22:27:33 -06:00
|
|
|
git clone "https://git.lyte.dev/lytedev/dotfiles" "$1"
|
2020-10-26 16:33:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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" \
|
2020-10-26 16:33:46 -05:00
|
|
|
"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"
|
2020-10-26 16:33:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
generate_ssh_key() {
|
2020-10-26 16:39:09 -05:00
|
|
|
mkdir --mode 600 --parents "$daniel_home/.ssh"
|
|
|
|
keyfile="$daniel_home/.ssh/$(hostname --short)"
|
2020-11-06 00:50:13 -06:00
|
|
|
if ! [ -f "$keyfile" ]; then
|
|
|
|
ssh-keygen -N '' -t ed25519 -f "$keyfile"
|
|
|
|
mkdir --mode 640 --parents "$nice_home/public"
|
|
|
|
cp "$keyfile.pub" "$nice_home/public"
|
|
|
|
fi
|
2020-10-26 16:33:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fix_dotfiles_origin() {
|
2020-11-07 22:43:55 -06:00
|
|
|
pushd "$daniel_home$dotfiles"
|
2020-10-26 16:33:46 -05:00
|
|
|
git remote set-url origin "ssh://git@git.lyte.dev:2222/lytedev/dotfiles.git"
|
2020-11-07 22:43:55 -06:00
|
|
|
popd
|
2020-10-26 16:33:46 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-11-06 22:16:18 -06:00
|
|
|
setup_dotfiles() {
|
2020-11-07 22:43:55 -06:00
|
|
|
pushd "$daniel_home$dotfiles"
|
2020-11-06 22:16:18 -06:00
|
|
|
./bin/setup-dotfiles
|
2020-11-07 22:43:55 -06:00
|
|
|
popd
|
2020-11-06 22:16:18 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 21:56:10 -06:00
|
|
|
distro_specific_root_setup() {
|
2020-11-07 21:57:54 -06:00
|
|
|
if test $is_nixos -eq 1; then
|
2020-11-07 21:56:10 -06:00
|
|
|
symlink_nixos "$root_home$dotfiles/env/nix/"
|
|
|
|
add_unstable_channel
|
2020-11-07 22:23:52 -06:00
|
|
|
nixos-rebuild switch # this should create the `daniel` user
|
2020-11-07 21:57:54 -06:00
|
|
|
elif test $is_arch_linux -eq 1; then
|
2020-11-07 21:56:10 -06:00
|
|
|
# TODO: install any necessary packages for remaining setup portion
|
2020-11-07 22:23:52 -06:00
|
|
|
"$root_home$dotfiles/env/arch-linux/provision.d/00-add-user.bash"
|
2020-11-07 21:58:26 -06:00
|
|
|
printf ''
|
2020-11-07 21:56:10 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
distro_specific_user_setup() {
|
2020-11-07 21:57:54 -06:00
|
|
|
if test $is_nixos -eq 1; then
|
2020-11-07 21:56:10 -06:00
|
|
|
FUNC=$(declare -f symlink_nixos)
|
|
|
|
sudo sh -c "$FUNC; symlink_nixos \"$daniel_home$dotfiles/env/nix/\""
|
2020-11-07 21:57:54 -06:00
|
|
|
elif test $is_arch_linux -eq 1; then
|
2020-11-07 21:56:10 -06:00
|
|
|
# TODO: setup all the things
|
2020-11-07 21:58:26 -06:00
|
|
|
printf ''
|
2020-11-07 21:56:10 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-10-26 16:33:46 -05:00
|
|
|
init_for_root() {
|
2020-10-26 16:39:09 -05:00
|
|
|
clone_dotfiles "$root_home$dotfiles"
|
2020-11-07 21:58:55 -06:00
|
|
|
distro_specific_root_setup
|
2020-11-07 22:35:32 -06:00
|
|
|
clone_dotfiles "$daniel_home$dotfiles"
|
|
|
|
chown daniel:users -R "$daniel_home"
|
2020-10-26 16:33:46 -05:00
|
|
|
echo "Re-running as user daniel..."
|
2020-11-07 22:35:32 -06:00
|
|
|
sudo --user daniel "$daniel_home$dotfiles/bin/init-dotfiles"
|
2020-10-26 16:33:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
init_for_daniel() {
|
2020-11-07 22:43:55 -06:00
|
|
|
set +x
|
2020-10-26 16:39:09 -05:00
|
|
|
clone_dotfiles "$daniel_home$dotfiles"
|
2020-10-26 16:33:46 -05:00
|
|
|
generate_ssh_key
|
2020-11-07 21:56:10 -06:00
|
|
|
distro_specific_user_setup
|
2020-10-26 16:33:46 -05:00
|
|
|
setup_wallpaper
|
|
|
|
# TODO: setup ssh/gpg keys
|
|
|
|
# TODO: setup password store
|
|
|
|
fix_dotfiles_origin
|
2020-11-06 22:16:18 -06:00
|
|
|
setup_dotfiles
|
2020-11-06 22:24:55 -06:00
|
|
|
# TODO: fetch password store
|
|
|
|
# TODO: fetch notes database
|
2020-10-26 16:33:46 -05:00
|
|
|
}
|
|
|
|
|
2020-11-06 00:42:19 -06:00
|
|
|
if [ "$EUID" -eq 0 ]; then
|
2020-11-07 22:43:55 -06:00
|
|
|
if test $is_arch_linux -eq 1; then
|
|
|
|
pacman -S --needed git
|
|
|
|
fi
|
2020-10-26 16:33:46 -05:00
|
|
|
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")"
|
2020-10-26 16:33:46 -05:00
|
|
|
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!"
|
2020-11-07 22:33:15 -06:00
|
|
|
if test $is_arch_linux -eq 1; then
|
|
|
|
echo
|
|
|
|
echo 'You will need to set a password for your new user.'
|
|
|
|
fi
|
2020-10-26 16:33:46 -05:00
|
|
|
echo
|
|
|
|
echo "The simplest method for doing this is to run the following:"
|
2020-11-06 00:50:13 -06:00
|
|
|
echo ' scp -r "$TARGET_MACHINE:~/.gnupg" "$HOME/.gnupg'
|