-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.mk
More file actions
71 lines (65 loc) · 1.98 KB
/
common.mk
File metadata and controls
71 lines (65 loc) · 1.98 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
# Common utilities for dotfiles Makefiles
# Function to check if a command exists
check_command = $(shell command -v $(1) >/dev/null 2>&1 && echo "exists" || echo "missing")
# Function to install a dnf package if command is missing
define install_if_missing
@if ! command -v $(1) >/dev/null 2>&1; then \
echo "$(1) not found. Installing $(2) via dnf..."; \
sudo dnf install -y $(2); \
else \
echo "$(1) already installed"; \
fi
endef
# Function to install multiple dnf packages
define check_and_install_packages
@echo "Checking dependencies..."
@for pkg in $(1); do \
cmd=$$(echo $$pkg | cut -d: -f1); \
package=$$(echo $$pkg | cut -d: -f2); \
if ! command -v $$cmd >/dev/null 2>&1; then \
echo "$$cmd not found. Installing $$package via dnf..."; \
sudo dnf install -y $$package; \
else \
echo "$$cmd already installed"; \
fi; \
done
endef
# Function to check Python module and install via pip if missing
define install_python_module
@if ! python3 -c "import $(1)" 2>/dev/null; then \
echo "Installing $(1) via pip..."; \
pip3 install --user $(2); \
else \
echo "$(1) already installed"; \
fi
endef
# Function to add content to file if not present
define add_to_file_if_missing
@if ! grep -q '$(2)' $(1) 2>/dev/null; then \
echo "Adding $(3) to $(1)..."; \
echo '' >> $(1); \
echo '$(2)' >> $(1); \
else \
echo "$(3) already configured in $(1)"; \
fi
endef
# Function to enable and start systemd user services/timers
define enable_systemd_user_units
@echo "Enabling systemd user units..."
@for unit in $(1); do \
if systemctl --user is-enabled $$unit >/dev/null 2>&1; then \
echo "$$unit already enabled"; \
else \
echo "Enabling $$unit..."; \
systemctl --user enable $$unit; \
fi; \
if systemctl --user is-active $$unit >/dev/null 2>&1; then \
echo "$$unit already active"; \
else \
echo "Starting $$unit..."; \
systemctl --user start $$unit; \
fi; \
done
@echo "Reloading systemd user daemon..."
@systemctl --user daemon-reload
endef