Last active 1695765632

A script to pull .ssh authorized_keys and config from a repository and update the current user's .ssh with them.

ssh-setup.sh Raw
1#!/bin/bash -x
2# curl s.aly.pet/ssh-setup | GIT_HOSTNAME=dotfiles.example.com GIT_USERNAME=you GIT_PASSWORD=password bash -x
3if [ -z $GIT_HOSTNAME ]; then
4 echo -n "Git hostname: "
5 read -s GIT_HOSTNAME
6fi
7if [ -z $GIT_USERNAME ]; then
8 echo -n "Git username: "
9 read -s GIT_USERNAME
10fi
11if [ -z $GIT_PASSWORD ]; then
12 echo -n "Git password: "
13 read -s GIT_PASSWORD
14fi
15git --version || sudo apt install -y git || pkg install -y git || sudo pacman -Sy git || apk add git
16git clone https://$GIT_USERNAME:$GIT_PASSWORD@$GIT_HOSTNAME/.ssh.git $TMPDIR/ssh_git
17if [ -d $HOME/.ssh ]; then
18 find $HOME/.ssh -type f -not -name authorized_keys -not -name config -not -name .gitignore -not -path "$HOME/.ssh/.git*" -exec mv -t $TMPDIR/ssh_git/ {} + && rm -rf $HOME/.ssh
19fi
20chown -R $UID $TMPDIR/ssh_git
21find $TMPDIR/ssh_git -type f -exec chmod 600 {} +
22find $TMPDIR/ssh_git -type d -exec chmod 700 {} +
23mv $TMPDIR/ssh_git $HOME/.ssh