summaryrefslogtreecommitdiff
path: root/modules/10-ssh/install.sh
blob: 7799fd81ea3cfa721855a4899147ff04960d475f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
_script="$(realpath ${BASH_SOURCE[0]})"
_scriptname="$(basename $_script)"
_scriptdir="$(dirname $_script)"
_modulename="$(basename $_scriptdir)"
DOT_MODULE_NAME="ssh"

function preinstall() {
        if ! [[ -x "$(command -v ssh)" ]]; then
                PACKAGES+=("openssh")
        fi
        if ! [[ -x "$(command -v git-crypt)" ]]; then
                PACKAGES+=("git-crypt")
        fi
}

function _install() {
	git-crypt unlock
	
	if [[ "$?" -ne "0" ]]; then
		log error "error decrypting ssh files, bailing before we break anthing"
		return
	fi

	# backup old file if it exists and we haven't backed it up before
	if [[ -d "$HOME/.ssh" ]] && ! [[ -d "$HOME/.ssh.bak" ]] && ! [[ -f "$_scriptdir/.firstrun" ]]; then
		log verbose "making backup"
		cp -r "$HOME/.ssh" "$HOME/.ssh.bak"
		touch "$_scriptdir/.firstrun"
	fi

	log info "linking ~/.ssh"
	rm -rf "$HOME/.ssh"
	ln -sf "$_scriptdir/ssh" "$HOME/.ssh"
}