Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip task if config list not defined #129

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/customize/apps/atom
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _install-packages() {
local cfg_file="${2:?Config file missing}"
local package

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" atom-packages; then
return 0
fi

print-header Install Atom packages "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for package in $(cfg-read "${cfg_file}" atom-packages); do
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/gnome/user-dirs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ _copy-bookmarks() {
local cfg_file="${2:?Config file missing}"
local line

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" bookmarks; then
return 0
fi

print-status Add bookmarks "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" bookmarks); do
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/other/cron
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ _setup-cronjob() {
local cfg_file="${3:?Config file missing}"
local line target name path

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" "cron-${frequency}"; then
return 0
fi

print-status Setup "${frequency}" cron jobs "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" "cron-${frequency}"); do
Expand Down
6 changes: 6 additions & 0 deletions bin/customize/other/local
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
_run() {
local selector="${1:?Selector missing}"
local cfg_dir="${2:?Config dir missing}"
local scripts

scripts=$(run-parts --test "${cfg_dir}")
if [[ -z "${scripts}" ]]; then
return 0
fi

print-header Run local scripts "[${selector}]..."
(
Expand Down
26 changes: 20 additions & 6 deletions bin/customize/packages/apt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _parse-install-packages() {
local cfg_file="${2:?Config file missing}"
local line package repo

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" apt-install; then
return 0
fi

print-status Parse packages to install "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" apt-install); do
Expand All @@ -40,6 +45,11 @@ _parse-remove-packages() {
local cfg_file="${2:?Config file missing}"
local package

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" apt-remove; then
return 0
fi

print-status Parse packages to remove "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for package in $(cfg-read "${cfg_file}" apt-remove); do
Expand Down Expand Up @@ -86,13 +96,17 @@ print-header Update apt cache...
sudo apt-get update
print-finish

print-header Install "${packages_install[*]}..."
sudo apt-get install --yes --no-install-recommends "${packages_install[@]}"
print-finish
if [[ -n "${packages_install[*]}" ]]; then
print-header Install "${packages_install[*]}..."
sudo apt-get install --yes --no-install-recommends "${packages_install[@]}"
print-finish
fi

print-header Remove "${packages_remove[*]}..."
sudo apt-get remove --yes --purge --autoremove "${packages_remove[@]}"
print-finish
if [[ -n "${packages_remove[*]}" ]]; then
print-header Remove "${packages_remove[*]}..."
sudo apt-get remove --yes --purge --autoremove "${packages_remove[@]}"
print-finish
fi

print-header Upgrade packages...
sudo apt-get upgrade --yes
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/packages/bin
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _install() {
local cfg_file="${2:?Config file missing}"
local line name url checksum hash tmp_file

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" bin; then
return 0
fi

print-header Install vendor shell programs "[${selector}]..."
sudo mkdir -p "${bin_global}"
# shellcheck disable=SC2310,SC2311
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/packages/node
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _install() {
local cfg_file="${2:?Config file missing}"
local line package

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" node; then
return 0
fi

print-header Install node modules "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" node); do
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/packages/snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _install() {
local cfg_file="${2:?Config file missing}"
local snaps_installed line package mode options

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" snap; then
return 0
fi

print-header Install snaps "[${selector}]..."
snaps_installed=$(snap list --color=never --unicode=never)
# shellcheck disable=SC2310,SC2311
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/services/apache
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _install-module() {
local cfg_file="${2:?Config file missing}"
local module modules=()

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" apache-module; then
return 0
fi

print-header Install Apache modules "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for module in $(cfg-read "${cfg_file}" apache-module); do
Expand Down
11 changes: 11 additions & 0 deletions bin/customize/system/dirs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _dirs-create() {
local cfg_file="${2:?Config file missing}"
local line path owner

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" dirs-create; then
return 0
fi

print-status Create dirs "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" dirs-create); do
Expand All @@ -43,6 +48,11 @@ _dirs-remove() {
local cfg_file="${2:?Config file missing}"
local line

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" dirs-remove; then
return 0
fi

print-status Remove dirs "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" dirs-remove); do
Expand Down Expand Up @@ -79,6 +89,7 @@ if file=$(cfg-get "${profile}" system/local.cfg); then
_dirs-remove local "${file}"
cfg-eval "${file}" perms
fi
[[ -z "${perm_home}" ]] && exit 1

print-status Set permission on "/home/${USER}..."
sudo chown "${USER}:${USER}" ~
Expand Down
10 changes: 10 additions & 0 deletions bin/customize/system/locale
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _install-locale() {
local cfg_file="${2:?Config file missing}"
local locale

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" locales; then
return 0
fi

print-header Install locale "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for locale in $(cfg-read "${cfg_file}" locales); do
Expand All @@ -38,6 +43,11 @@ _set-locale() {
local cfg_file="${2:?Config file missing}"
local line category locale

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" locale; then
return 0
fi

print-status Set locales "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" locale); do
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/system/users
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _create-user() {
local cfg_file="${2:?Config file missing}"
local existent_users user type existent_groups groups group options

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" users; then
return 0
fi

existent_users=$(getent passwd | cut -d: -f1)
existent_groups=$(getent group | cut -d: -f1)

Expand Down
5 changes: 5 additions & 0 deletions bin/customize/tools/git
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ _config() {
local cfg_file="${2:?Config file missing}"
local line cfg_loc cfg_name cfg_value

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" git; then
return 0
fi

print-status Config git "[${selector}]..."
# shellcheck disable=SC2310,SC2311
for line in $(cfg-read "${cfg_file}" git); do
Expand Down
5 changes: 5 additions & 0 deletions bin/customize/tools/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ _known-hosts() {
local cfg_file="${2:?Config file missing}"
local line

# shellcheck disable=SC2310
if is-empty-section "${cfg_file}" ssh-known; then
return 0
fi

print-status Setup known hosts "[${selector}]..."
mkdir -p ~/.ssh
touch ~/.ssh/known_hosts
Expand Down
14 changes: 14 additions & 0 deletions bin/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ cfg-read() {
sed -r -e '/^\s*\[/ d' <<<"${contents}"
}

## Check section is defined and not empty in config file
##
## @param $1 Config File
## @param $2 Section
########################################################
is-empty-section() {
local file="${1:?File missing}"
local section="${2:?Section missing}"
local contents

contents=$(cfg-read "${cfg_file}" "${section}")
[[ -z "${contents}" ]]
}

## Eval config file
##
## @param $1 Config File
Expand Down
18 changes: 9 additions & 9 deletions example/default/system/global.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ mok_key_subject="/O=ES-Progress/OU=HeadQuarters/CN=Zephyr Machine Owner Key"
# Perms on $HOME (non-recursive)
perm_home=o-rwx

## Users
##
## Format:
## user_name [type] [groups]
############################
[users]
$USER normal users,www-data,nonexistent-group
zephyr system

## Locales to install
##
##
Expand All @@ -76,3 +67,12 @@ hu_HU.UTF-8
[locale]
LANG en_GB.UTF-8
LC_NUMERIC hu_HU.UTF-8

## Users
##
## Format:
## user_name [type] [groups]
############################
[users]
$USER normal users,www-data,nonexistent-group
zephyr system
Loading