-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.sh
More file actions
143 lines (126 loc) · 3.96 KB
/
bootstrap.sh
File metadata and controls
143 lines (126 loc) · 3.96 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
#!/usr/bin/env bash
set -euo pipefail
if [ ! -d "$HOME/dotfiles/.git" ]; then
read -p "Clone dotfiles repository? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "→ Cloning git repository..."
git clone https://github.com/collinmurch/dotfiles "$HOME/dotfiles"
else
echo "✓ Nothing to do."
exit 0
fi
else
echo "✓ Dotfiles repo already exists – skipping clone."
fi
echo
read -p "Link dotfiles with stow? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "→ Linking dot-files with stow…"
stow -d ~/dotfiles -t ~ .
else
echo "✓ Skipping stow linking."
fi
echo
echo "→ Rebuilding bat cache…"
bat cache --build
echo
read -p "Install TX-02 fonts? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "→ Installing TX-02 fonts…"
# Create fonts directory
FONT_DIR="$HOME/.local/share/fonts/tx02"
mkdir -p "$FONT_DIR"
# Check if fonts already installed
if [ -f "$FONT_DIR/TX-02-Regular.otf" ]; then
echo "✓ TX-02 fonts already installed"
else
# Check if Bitwarden is available and handle authentication
if command -v bw >/dev/null 2>&1; then
BW_STATUS=$(bw status | nu -c 'from json | get status' 2>/dev/null || echo "unknown")
case "$BW_STATUS" in
"unauthenticated")
echo " Bitwarden CLI is not logged in."
read -r -p " Enter your Bitwarden email: " BW_EMAIL
echo " Logging in to Bitwarden..."
if bw login "$BW_EMAIL"; then
echo " Login successful. Now unlocking vault..."
if SESSION_KEY=$(bw unlock --raw); then
export BW_SESSION="$SESSION_KEY"
BW_CMD="bw"
else
echo "✗ Failed to unlock bw vault after login"
exit 1
fi
else
echo "✗ Failed to login to Bitwarden"
exit 1
fi
;;
"locked")
echo " Bitwarden vault is locked. Attempting to unlock..."
if SESSION_KEY=$(bw unlock --raw); then
export BW_SESSION="$SESSION_KEY"
BW_CMD="bw"
else
echo "✗ Failed to unlock bw vault"
exit 1
fi
;;
"unlocked")
BW_CMD="bw"
;;
*)
echo "✗ Unknown Bitwarden status: $BW_STATUS"
exit 1
;;
esac
else
echo "✗ bw command not found"
exit 1
fi
# Decrypt and install fonts if Bitwarden is available and unlocked
if [ -n "${BW_CMD:-}" ]; then
echo " Decrypting TX-02 fonts using Bitwarden SSH key..."
TEMP_KEY=$(mktemp)
trap 'rm -f "$TEMP_KEY"' EXIT
bw get item "GitHub Encryption Secret" | nu -c 'from json | get sshKey.privateKey' >"$TEMP_KEY"
AGE_KEY_FILE=$(mktemp)
trap 'rm -f "$TEMP_KEY" "$AGE_KEY_FILE"' EXIT
ssh-to-age -private-key -i "$TEMP_KEY" >"$AGE_KEY_FILE"
# Decrypt fonts using age with converted key
age -d -i "$AGE_KEY_FILE" ~/dotfiles/fonts/TX-02-Regular.otf.age >"$FONT_DIR/TX-02-Regular.otf"
age -d -i "$AGE_KEY_FILE" ~/dotfiles/fonts/TX-02-Bold.otf.age >"$FONT_DIR/TX-02-Bold.otf"
age -d -i "$AGE_KEY_FILE" ~/dotfiles/fonts/TX-02-Oblique.otf.age >"$FONT_DIR/TX-02-Oblique.otf"
age -d -i "$AGE_KEY_FILE" ~/dotfiles/fonts/TX-02-Bold-Oblique.otf.age >"$FONT_DIR/TX-02-Bold-Oblique.otf"
echo "✓ TX-02 fonts installed to $FONT_DIR"
# Refresh font cache on Linux
if [[ "$OSTYPE" == "linux-gnu"* ]] && command -v fc-cache >/dev/null 2>&1; then
fc-cache -f "$FONT_DIR"
fi
fi
fi
else
echo "✓ Skipping TX-02 font installation."
fi
echo
read -p "Open a new (nu) shell? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "✓ All done – opening a new (nu) shell..."
# Check if nu is available in PATH first
if command -v nu >/dev/null 2>&1; then
exec nu -l
# Fallback to nix profile location
elif [ -x "$HOME/.nix-profile/bin/nu" ]; then
exec "$HOME/.nix-profile/bin/nu" -l
else
echo "Error: nushell (nu) not found in PATH or at ~/.nix-profile/bin/nu"
echo "Please ensure nushell is installed and available."
exit 1
fi
else
echo "✓ All done!"
fi