-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·79 lines (70 loc) · 2.55 KB
/
install
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
set -ex
# If dest has our install script, *assume* that it is us.
# Checking path equivalency does not always work correctly due to symlinks.
# example: FreeBSD has /home -> /usr/home symlink, so PWD might be outside HOME.
# Devtools like gitpod or coder clone us below ~/.config, so we cannot move or
# unlink that. Walking on eggshells...
if ! test -f ~/.config/install; then
# If not, make sure dest exists
mkdir -p ~/.config
# This evaluates true when we got called directly by path
# Only then we know where we got cloned to
if test -x "$0"; then
# Copy ourselves there
src=$(dirname "$0")
cp -r $src/* $src/.git ~/.config/
else
repo=https://codeberg.org/ain/dotconfig
# No idea where we got installed to. Re-fetch our data from codeberg.
# This happens when you stdin this file into ssh.
if command -v git >/dev/null 2>&1; then
(
cd ~/.config
# Turn this into a git repo
git init .
git remote add origin $repo.git
git fetch origin
git checkout -b master --track origin/master
)
else
wget -O - $repo/archive/master.tar.gz \
| tar x -zC .config --strip-components=1
fi
fi
fi
# Make sure checkout worked
test -f ~/.config/install
# cd to the directory where we will make the symlinks.
# This way, the relative path glob will be valid targets for the symlinks.
cd "${HOME?Home is not set}"
for target in .config/*/dot.*; do
# Extract command from first asterisk.
cmd=${target%/*};
cmd=${cmd##*/}
# Dotfile name from second asterisk.
dotfile=.${target#*/dot.}
# Either a command of that name exists, or we skip setting up the dotfile.
# This mechanism skips bashrc etc if bash not installed (i hate bash).
command -v "$cmd" >/dev/null 2>&1 || continue
# If the dotfile already exists and is a directory (likely with .ssh), merge.
# This might be destructive for us, but will save ssh keys
if ! test -h "$dotfile" && test -d "$dotfile"; then
mv -f "$dotfile"/* "$target"/
rmdir "$dotfile"
fi
# If dotfile is a symlink pointing to a directory, ln(1) will create symlink
# inside that directory instead of setting the symlink. Unlink it first.
# -f because failure is okay.
rm -f "$dotfile"
ln -s "$target" "$dotfile"
done
keytype=ed25519
privkey=.ssh/id_${keytype}
pubkey=${privkey}.pub
# Upload public key if exists.
# Remote is some kind of pastebin, not the SSH CA, if you are after that.
if test -f "${pubkey}"; then
wget --header="Content-Type: text/plain" \
--post-file="$pubkey" -O - https://w1r3.net/ssh/submit
fi