Skip to content

Commit 78cced7

Browse files
committed
Merge branch 'master' of github.com:ogabriel/setuper
2 parents f468c88 + 4498a1f commit 78cced7

File tree

8 files changed

+182
-34
lines changed

8 files changed

+182
-34
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ And inside that you can have three folders with the files to be used:
4848
- these files should be mostly the dotfiles
4949
- `./packages` - from your sourced files
5050

51-
you can also define custom locations to these files with a `$HOME/.config/setuper/config/entrypoint.sh`, like:
51+
you can also define custom locations to these files with a `$HOME/.config/setuper/init.sh`, like:
5252

5353
```bash
54+
config_files_dir=$HOME/.debian_config/
55+
config_files_dir=$HOME/.arch_config/
5456
system_files_dir=$HOME/.system/
5557
user_files_dir=$HOME/.dotfiles/
5658
sourced_package_dir=$HOME/.mypackages/
@@ -68,9 +70,14 @@ sourced_package_dir=$HOME/.mypackages/
6870
- `--flatpak` - flatpak packages
6971
- `--source=file` - this allows you to install a specific package in your config directories, like a `pkg.tar.zst` or `deb`, the file must be in the folder `packages/file`
7072
- `RemovePkg/RemovePackage packagename` - removes said package
71-
- `SystemdUnitSystemEnable unitname` - enables a systemd system unit
73+
- `SystemdUnitSystemEnable unitname` - enables a systemd system unit (auto-unmasks if masked)
74+
- `SystemdUnitSystemDisable unitname` - disables a systemd system unit
7275
- `SystemdUnitSystemMask unitname` - masks a systemd system unit
73-
- `SystemdUnitUserEnable unitname` -enables a system user unit
76+
- `SystemdUnitSystemUnmask unitname` - unmasks a systemd system unit
77+
- `SystemdUnitUserEnable unitname` - enables a system user unit (auto-unmasks if masked)
78+
- `SystemdUnitUserDisable unitname` - disables a system user unit
79+
- `SystemdUnitUserMask unitname` - masks a system user unit
80+
- `SystemdUnitUserUnmask unitname` - unmasks a system user unit
7481
- `SystemFile file` - copies a system file with superuser permissions, like a udev rule, tlp config etc.
7582
- `SystemFileFromTo from_file to_file` - same as above, but you can rename
7683
- `SystemDirectory directory` - copies a directory like `system/etc/sddm.conf.d` to `/etc/sddm.conf.d`
@@ -95,7 +102,7 @@ The order is thought to not cause any problems, so for example, the packages wil
95102

96103
### Sourcing order
97104

98-
When loading the configuration files, the file `entrypoint.sh` will be sourced first, and then the rest by alphabetical order
105+
When loading the configuration files, the file `init.sh` will be sourced first, and then the rest by alphabetical order
99106

100107
### Examples of configurations
101108

@@ -115,10 +122,10 @@ if [[ "$HOSTNAME" == "laptop" ]]; then
115122
fi
116123
```
117124

118-
Sometimes you want to define a variable to be used on other files, so you can set a variable on the `entrypoint.sh` to be later used:
125+
Sometimes you want to define a variable to be used on other files, so you can set a variable on the `init.sh` to be later used:
119126

120127
```bash
121-
# on the entrypoint.sh file
128+
# on the init.sh file
122129
case $HOSTNAME in
123130
my_work_PC)
124131
window_manager=sway

examples/init.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
case $HOSTNAME in
2+
my_work_PC)
3+
window_manager=sway
4+
5+
config_files_dir=$HOME/.config_work/
6+
;;
7+
my_personal_PC)
8+
window_manager=hyprland
9+
10+
config_files_dir=$HOME/.config_personal/
11+
;;
12+
esac

lib/apply.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
source $lib_dir/helper_functions.sh
22

3-
CheckConfig
43
CheckPermissons
54
DefineDistro
65

lib/config/main.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ source $lib_dir/config/files_and_directories.sh
66
source $lib_dir/config/users_and_groups.sh
77

88
function LoadConfig() {
9-
if [[ -f $config_files_dir/entrypoint.sh ]]; then
10-
Info "Loading entrypoint"
11-
source $config_files_dir/entrypoint.sh
9+
if [[ -f $config_dir/init.sh ]]; then
10+
Info "Loading init"
11+
source $config_dir/init.sh
1212
fi
1313

14+
: ${config_files_dir:=$config_dir/config}
1415
: ${system_files_dir:=$config_dir/system/}
1516
: ${user_files_dir:=$config_dir/user/}
1617
: ${sourced_package_dir:=$config_dir/packages/}
1718

19+
CheckConfig
20+
1821
for file in $config_files_dir/*.sh; do
19-
if [[ $file == $config_files_dir/entrypoint.sh ]]; then
20-
continue
21-
else
22-
Info "Loading $file"
23-
source $file
24-
fi
22+
Info "Loading $file"
23+
source $file
2524
done
2625
}

lib/config/systemd.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,38 @@ function SystemdUnitSystemDisable() {
1010
systemd_unit_system_disable+=($1)
1111
}
1212

13+
function SystemdUnitSystemMask() {
14+
ValidateExactFunctionParams 1 $# $FUNCNAME
15+
16+
systemd_unit_system_mask+=($1)
17+
}
18+
19+
function SystemdUnitSystemUnmask() {
20+
ValidateExactFunctionParams 1 $# $FUNCNAME
21+
22+
systemd_unit_system_unmask+=($1)
23+
}
24+
1325
function SystemdUnitUserEnable() {
1426
ValidateExactFunctionParams 1 $# $FUNCNAME
1527

1628
systemd_unit_user_enable+=($1)
1729
}
1830

19-
function SystemdUnitSystemMask() {
31+
function SystemdUnitUserDisable() {
2032
ValidateExactFunctionParams 1 $# $FUNCNAME
2133

22-
systemd_unit_system_mask+=($1)
34+
systemd_unit_user_disable+=($1)
35+
}
36+
37+
function SystemdUnitUserMask() {
38+
ValidateExactFunctionParams 1 $# $FUNCNAME
39+
40+
systemd_unit_user_mask+=($1)
41+
}
42+
43+
function SystemdUnitUserUnmask() {
44+
ValidateExactFunctionParams 1 $# $FUNCNAME
45+
46+
systemd_unit_user_unmask+=($1)
2347
}

lib/handler/systemd.sh

Lines changed: 122 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,118 @@
11
function HandleSystemdUnits() {
22
if [[ ${#systemd_unit_system_enable[*]} -gt 0 ]] ||
33
[[ ${#systemd_unit_system_mask[*]} -gt 0 ]] ||
4+
[[ ${#systemd_unit_system_unmask[*]} -gt 0 ]] ||
45
[[ ${#systemd_unit_system_disable[*]} -gt 0 ]] ||
5-
[[ ${#systemd_unit_user_enable[*]} -gt 0 ]]; then
6+
[[ ${#systemd_unit_user_enable[*]} -gt 0 ]] ||
7+
[[ ${#systemd_unit_user_unmask[*]} -gt 0 ]] ||
8+
[[ ${#systemd_unit_user_disable[*]} -gt 0 ]] ||
9+
[[ ${#systemd_unit_user_mask[*]} -gt 0 ]]; then
610

711
if ! __AllUnitsFound?; then
812
sudo systemctl daemon-reload
913
fi
1014

11-
__HandleSystemEnable
15+
__WarnConflicts
16+
1217
__HandleSystemMask
18+
__HandleSystemUnmask
19+
1320
__HandleSystemDisable
21+
__HandleSystemEnable
22+
23+
__HandleUserMask
24+
__HandleUserUnmask
25+
26+
__HandleUserDisable
1427
__HandleUserEnable
1528
fi
1629
}
1730

18-
function __HandleSystemEnable() {
19-
for service in ${systemd_unit_system_enable[*]}; do
20-
if ! systemctl is-enabled --quiet $service &>/dev/null; then
21-
Info "Enabling systemmd system unit $service"
22-
sudo systemctl enable $service --force
23-
fi
24-
done
25-
}
26-
2731
function __HandleSystemMask() {
2832
for service in ${systemd_unit_system_mask[*]}; do
2933
if ! systemctl list-unit-files --quiet --state=masked $service &>/dev/null; then
30-
Info "Masking systemmd unit $service"
34+
Info "Masking systemd system unit $service"
3135
sudo systemctl mask $service
3236
fi
3337
done
3438
}
3539

40+
function __HandleSystemUnmask() {
41+
for service in ${systemd_unit_system_unmask[*]}; do
42+
__HandleSystemUnmaskService $service
43+
done
44+
}
45+
46+
function __HandleSystemUnmaskService() {
47+
local service=$1
48+
49+
if systemctl list-unit-files --quiet --state=masked $service &>/dev/null; then
50+
Info "Unmasking systemd system unit $service"
51+
sudo systemctl unmask $service
52+
fi
53+
}
54+
3655
function __HandleSystemDisable() {
3756
for service in ${systemd_unit_system_disable[*]}; do
3857
if systemctl list-unit-files --quiet $service &>/dev/null &&
3958
! systemctl list-unit-files --quiet --state=disabled $service &>/dev/null; then
40-
Info "Disabling systemmd system unit $service"
59+
Info "Disabling systemd system unit $service"
4160
sudo systemctl disable $service
4261
fi
4362
done
4463
}
4564

65+
function __HandleSystemEnable() {
66+
for service in ${systemd_unit_system_enable[*]}; do
67+
__HandleSystemUnmaskService $service
68+
69+
if ! systemctl is-enabled --quiet $service &>/dev/null; then
70+
Info "Enabling systemd system unit $service"
71+
sudo systemctl enable $service --force
72+
fi
73+
done
74+
}
75+
76+
function __HandleUserUnmask() {
77+
for service in ${systemd_unit_user_unmask[*]}; do
78+
__HandleUserUnmaskService $service
79+
done
80+
}
81+
82+
function __HandleUserUnmaskService() {
83+
local service=$1
84+
85+
if systemctl --user list-unit-files --quiet --state=masked $service &>/dev/null; then
86+
Info "Unmasking systemd user unit $service"
87+
systemctl --user unmask $service
88+
fi
89+
}
90+
91+
function __HandleUserMask() {
92+
for service in ${systemd_unit_user_mask[*]}; do
93+
if ! systemctl --user list-unit-files --quiet --state=masked $service &>/dev/null; then
94+
Info "Masking systemd user unit $service"
95+
systemctl --user mask $service
96+
fi
97+
done
98+
}
99+
100+
function __HandleUserDisable() {
101+
for service in ${systemd_unit_user_disable[*]}; do
102+
if systemctl --user list-unit-files --quiet $service &>/dev/null &&
103+
! systemctl --user list-unit-files --quiet --state=disabled $service &>/dev/null; then
104+
Info "Disabling systemd user unit $service"
105+
systemctl --user disable $service
106+
fi
107+
done
108+
}
109+
46110
function __HandleUserEnable() {
47111
for service in ${systemd_unit_user_enable[*]}; do
112+
__HandleUserUnmaskService $service
113+
48114
if ! systemctl --user is-enabled --quiet $service &>/dev/null; then
49-
Info "Enabling systemmd user unit $service"
115+
Info "Enabling systemd user unit $service"
50116
systemctl --user enable $service
51117
fi
52118
done
@@ -71,11 +137,53 @@ function __AllUnitsFound?() {
71137
fi
72138
done
73139

140+
for service in ${systemd_unit_system_unmask[*]}; do
141+
if ! systemctl list-unit-files --quiet $service &>/dev/null; then
142+
return 1
143+
fi
144+
done
145+
74146
for service in ${systemd_unit_user_enable[*]}; do
75147
if ! systemctl --user list-unit-files --quiet $service &>/dev/null; then
76148
return 1
77149
fi
78150
done
79151

152+
for service in ${systemd_unit_user_disable[*]}; do
153+
if ! systemctl --user list-unit-files --quiet $service &>/dev/null; then
154+
return 1
155+
fi
156+
done
157+
158+
for service in ${systemd_unit_user_mask[*]}; do
159+
if ! systemctl --user list-unit-files --quiet $service &>/dev/null; then
160+
return 1
161+
fi
162+
done
163+
164+
for service in ${systemd_unit_user_unmask[*]}; do
165+
if ! systemctl --user list-unit-files --quiet $service &>/dev/null; then
166+
return 1
167+
fi
168+
done
169+
80170
return 0
81171
}
172+
173+
function __WarnConflicts() {
174+
for enable_service in ${systemd_unit_system_enable[*]}; do
175+
for mask_service in ${systemd_unit_system_mask[*]}; do
176+
if [[ $enable_service == $mask_service ]]; then
177+
Warn "System unit $enable_service present in both enable and mask lists; will end up enabled"
178+
fi
179+
done
180+
done
181+
182+
for enable_service in ${systemd_unit_user_enable[*]}; do
183+
for mask_service in ${systemd_unit_user_mask[*]}; do
184+
if [[ $enable_service == $mask_service ]]; then
185+
Warn "User unit $enable_service present in both enable and mask lists; will end up enabled"
186+
fi
187+
done
188+
done
189+
}

lib/helper_functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function CheckConfig() {
2525
fi
2626

2727
if ! [[ -n "$(find $config_files_dir -maxdepth 1 -type f -size +0 -iname "*.sh" -print -quit)" ]]; then
28-
Error "No valid .sh files found in $config_dir"
28+
Error "No valid .sh files found in $config_files_dir"
2929
fi
3030
}
3131

lib/main.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Options:
1313
else
1414
readonly lib_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
1515
readonly config_dir=${XDG_CONFIG_HOME:-$HOME/.config}/setuper
16-
readonly config_files_dir=$config_dir/config
1716

1817
case $1 in
1918
install)

0 commit comments

Comments
 (0)