-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.tmpl
249 lines (206 loc) · 7.35 KB
/
Makefile.tmpl
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Detect the OS
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
########################################
CHEZMOI := chezmoi --source={{ .chezmoi.sourceDir }}
dotfiles_init:
$(CHEZMOI) init
dotfiles_status:
$(CHEZMOI) status
dotfiles_diff:
$(CHEZMOI) diff
dotfiles_add:
@if [ -z "$(file)" ]; then \
echo "Error: Please provide a FILE to add."; \
exit 1; \
fi
$(CHEZMOI) add $(file)
dotfiles_apply:
$(CHEZMOI) apply
dotfiles_update:
$(CHEZMOI) update
extra_exports:
@echo "To export API keys to your current shell, run this command:"
@echo ""
@echo " source ~/extra-exports.sh"
@echo ""
@echo "NOTE: You must run this command directly in your terminal, not through make,"
@echo " because environment variables can't be exported from a Makefile to your shell."
########################################
# Determine the container engine (docker or podman)
CONTAINER_ENGINE := {{ .containerEngine }}
# Print OS-specific information
info:
ifeq ($(UNAME_S), Darwin)
@echo "Running on macOS"
@neofetch
else ifeq ($(UNAME_S), Linux)
@echo "Running on Linux"
@neofetch
endif
# Environment setup
env:
tmuxinator start -p `pwd`/.tmuxinator.yml app_workspace=`pwd`;
# Kill tmux session
tkill:
@tmux kill-session -t dotfiles || echo "Session 'dotfiles' does not exist."
tkill_all:
pkill -f tmux
quitapps:
ifeq ($(UNAME_S), Darwin)
osascript -e 'tell application "System Events" to set quitapps to (name of every process whose visible is true and name is not "Finder")' \
-e 'repeat with closeall in quitapps' \
-e 'tell application closeall to quit' \
-e 'end repeat'
else
@echo "This target is for macOS only."
endif
# macOS-specific commands
get_login_items:
ifeq ($(UNAME_S), Darwin)
@launchctl list | grep -v "apple" | awk '{print $$3}'
else
@echo "Login items command is specific to macOS."
endif
# macOS-specific updates
update_macos:
ifeq ($(UNAME_S), Darwin)
@echo "Updating macOS software..."
softwareupdate -i -a
else
@echo "This target is for macOS only."
endif
update_apps:
ifeq ($(UNAME_S), Darwin)
@echo "Updating Homebrew packages..."
brew outdated ; brew update ; brew upgrade --force ; brew upgrade --cask
brew cleanup
@echo "Updating App Store applications..."
mas outdated ; mas upgrade
else
@echo "This target is for macOS only."
endif
# Clear caches
clear_caches:
ifeq ($(UNAME_S), Darwin)
@echo "Clearing macOS caches..."
rm -rf ~/Library/Caches/*
rm -rf /Library/Caches/*
rm -rf ~/Library/Logs/*
else
@echo "This target is for macOS only."
endif
# Test Shared Volumes
test_shared_volumes:
ifeq ($(UNAME_S), Darwin)
$(CONTAINER_ENGINE) run -ti --rm \
-v "/Volumes:/media/share/Volumes" \
-v "/Users:/media/share/Users" \
busybox sh -c "cd /_shared && ls && sh"
else
@echo "This target is for macOS only."
endif
# Clean up containers
rm_a:
@$(CONTAINER_ENGINE) ps -aq | xargs $(CONTAINER_ENGINE) stop | xargs $(CONTAINER_ENGINE) rm
# Launch k9s for Kubernetes
k9s:
@k9s
# Ollama
# Function to kill process using the defined port
ollama_kill_port:
@PORT_PID=$$(lsof -ti tcp:{{ .ollamaPort }}); \
if [ -n "$$PORT_PID" ]; then \
echo "Killing process on port {{ .ollamaPort }}..."; \
kill -9 $$PORT_PID; \
fi
# Start ollama server in the background and save the PID
ollama_start: ollama_kill_port
@echo "Starting ollama server..."
@ollama serve & echo $$! > {{ .ollamaPidFile }}
@sleep 2 # Give the server some time to start
@echo "Ollama server started with PID $$(cat {{ .ollamaPidFile }})"
# Stop all ollama server processes, regardless of PID file
ollama_stop:
@if pgrep -f "ollama" > /dev/null; then \
echo "Stopping all ollama server processes..."; \
pkill -f "ollama"; \
echo "All ollama server processes stopped."; \
else \
echo "No ollama server processes running."; \
fi
@rm -f {{ .ollamaPidFile }}
# Pull the Ollama model and update it
ollama_pull:
@echo "Pulling and updating Ollama model {{ .ollamaModel }}..."
@ollama pull {{ .ollamaModel }}
# Chat with Ollama (ensure the server is running first)
ollama_chat:
@if [ -f {{ .ollamaPidFile }} ]; then \
echo "Running model {{ .ollamaModel }}..."; \
ollama run {{ .ollamaModel }}; \
else \
echo "Ollama server is not running. Start it first."; \
fi
# Tor
proxy_start:
$(CONTAINER_ENGINE) run -d --restart=always --name torproxy -p 127.0.0.1:{{- .torproxyPortSocks5 -}}:9150/tcp -p 127.0.0.1:{{- .torproxyPortDns -}}:8853/udp peterdavehello/tor-socks-proxy:latest
torproxy_start_without_dns:
$(CONTAINER_ENGINE) run -d --restart=always --name torproxy -p 127.0.0.1:{{- .torproxyPortSocks5 -}}:9150/tcp peterdavehello/tor-socks-proxy:latest
torproxy_stop:
$(CONTAINER_ENGINE) stop torproxy
$(CONTAINER_ENGINE) rm torproxy
torproxy_logs:
$(CONTAINER_ENGINE) logs torproxy
torproxy_ip_change:
$(CONTAINER_ENGINE) restart torproxy
torproxy_ports:
lsof -i :{{- .torproxyPortSocks5 -}}
lsof -i :{{- .torproxyPortDns -}}
torproxy_check:
@echo "ALL_PROXY: ${ALL_PROXY}"
@echo "HTTP_PROXY: ${HTTP_PROXY}"
@echo "HTTPS_PROXY: ${HTTPS_PROXY}"
@echo "NO_PROXY: ${NO_PROXY}"
@echo "DNS_PROXY: ${DNS_PROXY}"
curl https://ipinfo.tw/ip
curl --socks5-hostname {{ .torproxyHost }}:{{- .torproxyPortSocks5 -}} https://check.torproject.org/api/ip
##############################
backup_create:
/opt/homebrew/bin/borgmatic --verbosity 2 --progress
/opt/homebrew/bin/borgmatic prune --verbosity 1
backup_list:
/opt/homebrew/bin/borgmatic list --verbosity 1
backup_list_files:
# Usage: make backup_list_files repo=/path/to/repo archive=/path/to/archive [path=optional/path/in/archive]
@if [ -z "$(repo)" ] || [ -z "$(archive)" ]; then \
echo "Error: Please provide repo and archive parameters."; \
echo "Usage: make backup_list_files repo=<repository_path> archive=<archive_name> [path=<optional/path/in/archive>]"; \
echo "Example: make backup_list_files repo=/Volumes/Backup/borg archive=daily-2023-03-12"; \
echo "Example: make backup_list_files repo=/Volumes/Backup/borg archive=daily-2023-03-12 path=Documents"; \
echo "Use 'make backup_list' to see available archives."; \
exit 1; \
fi
@if [ -z "$(path)" ]; then \
/opt/homebrew/bin/borg list --verbose "$(repo)::$(archive)"; \
else \
/opt/homebrew/bin/borg list --verbose "$(repo)::$(archive)" "$(path)"; \
fi
backup_restore:
# Usage: make backup_restore repo=/path/to/repo archive=/path/to/archive dest=/path/to/destination [path=optional/path/in/archive]
@if [ -z "$(repo)" ] || [ -z "$(archive)" ] || [ -z "$(dest)" ]; then \
echo "Error: Please provide repo, archive, and dest parameters."; \
echo "Usage: make backup_restore repo=<repository_path> archive=<archive_name> dest=<destination_path> [path=<optional/path/in/archive>]"; \
echo "Example: make backup_restore repo=/backups/main archive=daily-2023-01-01 dest=/recovery"; \
echo "Example: make backup_restore repo=/backups/main archive=daily-2023-01-01 dest=/recovery path=Documents/important"; \
echo "Use 'make backup_list' to see available archives."; \
exit 1; \
fi
@if [ -z "$(path)" ]; then \
echo "Restoring entire archive $(archive) to $(dest)..."; \
/opt/homebrew/bin/borgmatic extract --verbosity 1 --progress --repository $(repo) --archive $(archive) --destination $(dest); \
else \
echo "Restoring path $(path) from archive $(archive) to $(dest)..."; \
/opt/homebrew/bin/borgmatic extract --verbosity 1 --progress --repository $(repo) --archive $(archive) --destination $(dest) --path "$(path)"; \
fi
##############################