-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot
executable file
·131 lines (110 loc) · 3.37 KB
/
dot
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
#!/usr/bin/env bash
set -ueo pipefail
# Print message to stdout.
msg() { echo "MESSAGE: $*"; }
# Print error message to stderr.
error() { echo "ERROR: $*"; } >&2
# Print error message and exit with error status.
die() { error "$*"; exit 1; }
# Paths
export DOTFILES="$HOME/dotfiles"
export DOTMODULE="$DOTFILES/module"
# File names
DEPENDENCIES="dependencies"
CONFIG="config.sh"
PACKAGES_OFFICIAL="packages/official"
PACKAGES_AUR="packages/aur"
# Define and create base and user directories
source "$DOTMODULE/xdg/config/@env.sh"
source "$DOTMODULE/xdg/config/@login.sh"
install() {
local MODULE=$1
"$DOTMODULE/$MODULE/install.sh"
}
__dependencies() {
for MODULE in "$@"; do
if [[ -z ${ALL_MODULES[$MODULE]} ]]; then
ALL_MODULES[$MODULE]="1"
DEPS="$DOTMODULE/$MODULE/$DEPENDENCIES"
[[ -f "$DEPS" ]] && \
__dependencies "$(tr '\n' ' ' < "$DEPS")"
fi
done
}
dependencies() {
local MODULES ALL_MODULES
MODULES=$*
declare -A ALL_MODULES
__dependencies "$MODULES"
echo "${!ALL_MODULES[@]}"
}
packages() {
# Collect and install packages from official repositories and AUR
local MODULES OFFICIAL AUR FILE
MODULES=$*
declare -a OFFICIAL
declare -a AUR
for MODULE in $(dependencies "$MODULES"); do
FILE="$DOTMODULE/$MODULE/$PACKAGES_OFFICIAL"
[[ -r "$FILE" ]] && OFFICIAL+=("$FILE")
FILE="$DOTMODULE/$MODULE/$PACKAGES_AUR"
[[ -r "$FILE" ]] && AUR+=("$FILE")
done
# If "yay" is not installed exit with error.
[[ -z "$(command -v "yay")" ]] && \
die "Install Yay before installing packages."
# Sync, Refresh and Upgrade
sudo pacman --sync --refresh --sysupgrade --color=auto
[[ "${#OFFICIAL[@]}" -gt 0 ]] && \
cat "${OFFICIAL[@]}" \
| sort \
| uniq \
| sudo pacman --sync --needed --color=auto -
[[ "${#AUR[@]}" -gt 0 ]] && \
cat "${AUR[@]}" \
| sort \
| uniq \
| yay --sync --needed --color=auto -
}
config() {
local MODULES=$*
for MODULE in $(dependencies "$MODULES"); do
if [[ -r "$DOTMODULE/$MODULE/$CONFIG" ]]; then
msg "config: $MODULE"
"$DOTMODULE/$MODULE/$CONFIG"
fi
done
}
check() {
# Shellsheck all files with extensions ".sh" and ".bash".
ARGS="--exclude=SC1090,SC1091 --enable=deprecate-which --enable=avoid-nullary-conditions"
# shellcheck disable=SC2086
find . -name '*.sh' -type 'f' -print0 | xargs -0 shellcheck $ARGS
# shellcheck disable=SC2086
find . -name '*.bash' -type 'f' -print0 | xargs -0 shellcheck $ARGS
}
function help() {
echo "Manage the Arch Linux configuration."
echo ""
echo "USAGE"
echo "- General usage."
echo " ./dotfiles.bash <operation> <args>"
echo ""
echo "- Print help message."
echo " ./dotfiles.bash help"
echo ""
echo "- Run install script for a module."
echo " ./dotfiles.bash install <module>"
echo ""
echo "- Install packages for one or more modules."
echo " ./dotfiles.bash packages <module1> <module2> <...>"
echo ""
echo "- Install configurations for one or more modules."
echo " ./dotfiles.bash config <module1> <module2> <...>"
}
# Print help message on:
# `./dotfiles.bash`
# `./dotfiles.bash help`
[[ -z "$*" ]] && help
# Expose functions as arguments.
"$@"