-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.zsh
More file actions
executable file
·162 lines (139 loc) · 4.02 KB
/
Copy pathinstall.zsh
File metadata and controls
executable file
·162 lines (139 loc) · 4.02 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# stolen from https://github.com/ptrcnull/dotfiles/blob/master/install.zsh
# love you ptrc for your work <3
#!/bin/zsh
if [ "$ZSH_EVAL_CONTEXT" = "toplevel" ]; then
echo "[!] this script is meant to be sourced"
fi
plugins_dir="$HOME/.local/share/zsh-plugins"
plugins_alpine="
starship
zsh-syntax-highlighting
zsh-autosuggestions
zsh-completions
"
plugins_git="
https://github.com/zsh-users/zsh-syntax-highlighting
https://github.com/zsh-users/zsh-autosuggestions
"
for cmd in curl git sed install find; do
if ! command -v $cmd >/dev/null; then
echo "[!] $cmd not found"
exit 1
fi
done
set -e
# migrate legacy
mkdir -p "$HOME"/.config/zsh
touch "$HOME"/.config/zsh/local.zsh
if [ -d "$HOME"/.zsh-custom ]; then
for file in "$HOME"/.zsh-custom/*; do
echo "# $file" >> "$HOME"/.config/zsh/local.zsh
cat "$file" >> "$HOME"/.config/zsh/local.zsh
echo "" >> "$HOME"/.config/zsh/local.zsh
rm "$file"
done
rmdir "$HOME"/.zsh-custom
fi
if command -v rsync >/dev/null; then
echo "[*] installing config files"
rsync --archive --update --hard-links --itemize-changes --delay-updates \
./config/ ~/.config/
rsync --archive --update --hard-links --itemize-changes --delay-updates \
./.zshrc "$HOME"
echo "[*] installing executables"
rsync --archive --update --hard-links --itemize-changes --delay-updates \
./bin/ ~/.local/bin/
else
install() {
command install -dv "$(dirname "$2")" || true
# screw you coreutils install and your ugly messages
command install -v $@ | grep -v removed
}
echo "[*] installing config files"
install -m644 .zshrc "$HOME"/.zshrc
find config -type f | while read file; do
install $file $(echo $file | sed "s|config|$HOME/.config|")
done
echo "[*] installing executables"
find bin -type f | while read file; do
install $file $(echo $file | sed "s|bin|$HOME/.local/bin|")
done
unfunction install
fi
#if ! { [ -f "$HOME"/.ssh/authorized_keys ] && grep -q patrycja "$HOME"/.ssh/authorized_keys }; then
# echo "[*] installing SSH keys"
# mkdir -p "$HOME"/.ssh
#:whilefi
os_id="$( . /etc/os-release 2>/dev/null && echo "$ID" || echo "unknown" )"
# if on alpine, install stuff system-wide
if [ "$os_id" = "alpine" ]; then
elevate=
if [ "$(id -u)" != 0 ]; then
if command -v doas >/dev/null; then
elevate=doas
elif command -v sudo >/dev/null; then
elevate=sudo
else
echo "[!] cannot install zsh plugins system-wide"
elevate=:
fi
fi
for plugin in $=plugins_alpine; do
if ! grep -q "P:$plugin" /lib/apk/db/installed; then
echo "[*] installing $plugin system-wide"
$elevate apk add "$plugin"
else
echo "[+] $plugin installed already"
fi
done
else
for plugin in $=plugins_git; do
name="${plugin/*\//}"
if [ ! -d "$plugins_dir/$name" ]; then
echo "[*] installing $name locally"
git clone --depth=1 "$plugin" "$plugins_dir/$name"
else
echo "[+] $name installed already"
fi
done
fi
echo
echo "[*] installing homedir files"
find homedir -type f |while read -r file; do
install $file $(echo $file | sed "s|homedir|$HOME|")
done
echo
echo "[*] installing config files"
install -m644 .zshrc "$HOME"
find config -type f | while read file; do
install $file $(echo $file | sed "s|config|$HOME/.config|")
done
echo
echo "[*] installing executables"
find bin -type f | while read -r file; do
install $file $(echo $file | sed "s|bin|$HOME/.local/bin|")
done
for plugin in $=plugins_git; do
name="${plugin/*\//}"
mkdir -p "$plugins_dir"
if [ ! -d "$plugins_dir/$name" ]; then
echo "[*] installing $name locally"
git clone --depth=1 "$plugin" "$plugins_dir/$name"
else
echo "[+] $name installed already"
fi
done
if [ -d "$HOME"/.oh-my-zsh ]; then
echo "[*] cleaning up oh-my-zsh"
rm -rf "$HOME"/.oh-my-zsh
fi
if [ -d "$HOME"/.zsh ]; then
echo "[*] cleaning up .zsh"
rm -rf "$HOME"/.zsh
fi
# enable committed secret-scan pre-commit hook (if this is a git clone)
if [ -d "$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")/.git" ]; then
echo "[*] enabling pre-commit hooks for dotfiles repo"
git config core.hooksPath .githooks
fi
exec zsh