-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatch
More file actions
executable file
·112 lines (95 loc) · 3.75 KB
/
Copy pathdispatch
File metadata and controls
executable file
·112 lines (95 loc) · 3.75 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
#!/usr/bin/env bash
#
# _ _ _ _
# __| (_)___ _ __ __ _| |_ ___| |__
# / _` | / __| '_ \ / _` | __/ __| '_ \
# | (_| | \__ \ |_) | (_| | || (__| | | |
# \__,_|_|___/ .__/ \__,_|\__\___|_| |_|
# |_|
#
# Script : dispatch
# Location : /usr/local/bin/dispatch
# Author : Jens Ochmann
# Date : 2025-04-30
# License : MIT
# Description : Distribute files from the local OchiLinux84 repo to the system.
# Overwrites user/system configs; asks for confirmation.
# Run as user : Will only elevate specific actions with sudo.
#!/usr/bin/env bash
set -euo pipefail
# -------- Farben ----------
RED=${RED:-"\033[0;31m"}
GREEN=${GREEN:-"\033[0;32m"}
YELLOW=${YELLOW:-"\033[0;33m"}
BLUE=${BLUE:-"\033[0;34m"}
NC=${NC:-"\033[0m"}
info() { printf "%b%s%b\n" "$YELLOW" "$*" "$NC"; }
ok() { printf "%b%s%b\n" "$GREEN" "$*" "$NC"; }
err() { printf "%b%s%b\n" "$RED" "$*" "$NC" >&2; }
# -------- User-Home & Konfig ----------
USER_HOME=$(getent passwd "$USER" | cut -d: -f6)
CONFIG_FILE="${USER_HOME}/.config/sc.conf"
[[ -f "$CONFIG_FILE" ]] || { err "Configuration file not found: $CONFIG_FILE"; exit 1; }
# shellcheck source=/dev/null
source "$CONFIG_FILE"
: "${OCHILINUX_DIR:?OCHILINUX_DIR not set in sc.conf}"
if ! declare -p DIRS 2>/dev/null | grep -q 'declare -A'; then
err "DIRS is not an associative array in sc.conf"; exit 1;
fi
# -------- Bestätigung ----------
echo -e "\n${RED}⚠ This operation may overwrite configs.${NC}"
read -rp "Continue? (y/N) " reply
[[ ! $reply =~ ^[Yy]$ ]] && { info "Aborted."; exit 0; }
info "Starting dispatch …"
# -------- Kopierfunktion ----------
copy_item() {
local src=$1 dest=$2 perms=${3:-}
mkdir -p "$(dirname "$dest")"
if [[ $dest == /usr/* || $dest == /etc/* ]]; then
sudo rsync -a --progress "$src" "$dest" || return 1
[[ -n $perms ]] && sudo chmod "$perms" "$dest"
else
rsync -a --progress "$src" "$dest" || return 1
[[ -n $perms ]] && chmod "$perms" "$dest"
fi
}
# -------- Fonts dir ---------------
sudo install -d /usr/share/fonts/nerdfonts && ok "Nerdfonts directory ready."
# -------- Datei-Verteilung --------
for file in "${!DIRS[@]}"; do
src="${OCHILINUX_DIR}/${file}"
dest="${DIRS[$file]}"
[[ -e $src ]] || { info "Skip: $src not found"; continue; }
case $dest in
*/bin/*)
copy_item "$src" "$dest" 755 && ok "Script copied: $file" || err "Failed: $file" ;;
"$USER_HOME"/*)
copy_item "$src" "$dest" && ok "User config: $file" || err "Failed: $file" ;;
*/share/awesome/*|*/etc/*)
copy_item "$src" "$dest" && ok "Sys file: $file" || err "Failed: $file" ;;
*)
info "Unhandled path for $file → $dest" ;;
esac
echo
done
# -------- Tilix schemes -----------
if [[ -d "${OCHILINUX_DIR}/tilix" ]]; then
copy_item "${OCHILINUX_DIR}/tilix/" "$TILIX_DIR/" && ok "Tilix schemes copied." || err "Tilix schemes failed."
fi
# -------- Vim colours -------------
if [[ -d "${OCHILINUX_DIR}/vim/colors" ]]; then
copy_item "${OCHILINUX_DIR}/vim/colors" "$VIM_DIR/" && ok "Vim colours copied." || err "Vim colours failed."
fi
# -------- Tilix dconf -------------
if command -v dconf &>/dev/null && [[ -f "${OCHILINUX_DIR}/tilix.conf" ]]; then
dconf load '/com/gexperts/Tilix/' < "${OCHILINUX_DIR}/tilix.conf" && ok "Tilix dconf loaded." || err "Tilix dconf failed."
fi
# -------- dbus-x11 installieren ---
if command -v apt-get &>/dev/null && ! dpkg -s dbus-x11 &>/dev/null; then
info "Installing dbus-x11 …" && sudo apt-get -y install dbus-x11
fi
# -------- .dbus-Rechte fixieren ---
if [[ -d "${USER_HOME}/.dbus" ]]; then
sudo chown -R "$USER:$USER" "${USER_HOME}/.dbus" && ok "Fixed ~/.dbus ownership."
fi
echo -e "\n${GREEN}Dispatch completed successfully.${NC}"