diff --git a/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl b/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl index bc14d08f..50a4c567 100644 --- a/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl +++ b/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl @@ -9,16 +9,23 @@ {{- $additionalPackages := splitList " " (includeTemplate "archlinux/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Print dependency list logg 'Installing common dependencies using `pacman`' logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' +### Install packages if they are not already present for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do - logg info 'Installing `'"$PACKAGE"'`' - sudo pacman -Sy --noconfirm --needed "$PACKAGE" || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via pacman' - logg info 'Proceeding with installation..' - unset EXIT_CODE + logg info 'Checking for presence of `'"$PACKAGE"'`' + if pacman -Qs "$PACKAGE" > /dev/null; then + logg info 'The '"$PACKAGE"' package is already installed' + else + logg info 'Installing `'"$PACKAGE"'`' + sudo pacman -Sy --noconfirm --needed "$PACKAGE" || EXIT_CODE=$? + if [ -n "$EXIT_CODE" ]; then + logg error 'Error installing `'"$PACKAGE"'` via pacman' + logg info 'Proceeding with installation..' + unset EXIT_CODE + fi fi done diff --git a/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl b/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl index ffdfd8fa..d4ea4e57 100644 --- a/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl +++ b/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl @@ -9,30 +9,29 @@ {{- $additionalPackages := splitList " " (includeTemplate "centos/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Detect package manager if command -v dnf > /dev/null; then - logg 'Installing common dependencies using `dnf`' - logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' - - for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do - logg info 'Installing `'"$PACKAGE"'`' - sudo dnf install -y "$PACKAGE" || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via dnf' - logg info 'Proceeding with installation..' - unset EXIT_CODE - fi - done + PKG_MANAGER='dnf' else - logg 'Installing common dependencies using `yum`' - logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' + PKG_MANAGER='yum' +fi - for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do +### Print dependency list +logg 'Installing common dependencies using `'"$PKG_MANAGER"'`' +logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' + +### Install packages if they are not already present +for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do + logg info 'Checking for presence of `'"$PACKAGE"'`' + if rpm -qa | grep "$PACKAGE" > /dev/null; then + logg info 'The '"$PACKAGE"' package is already installed' + else logg info 'Installing `'"$PACKAGE"'`' - sudo yum install -y "$PACKAGE" || EXIT_CODE=$? + sudo "$PKG_MANAGER" install -y "$PACKAGE" || EXIT_CODE=$? if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via yum' + logg error 'Error installing `'"$PACKAGE"'` via `'"$PKG_MANAGER"'`' logg info 'Proceeding with installation..' unset EXIT_CODE fi - done -fi \ No newline at end of file + fi +done diff --git a/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl b/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl index 24c71296..18982c4b 100644 --- a/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl +++ b/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl @@ -9,17 +9,26 @@ {{- $additionalPackages := splitList " " (includeTemplate "debian/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Print dependency list logg 'Installing common dependencies using `apt-get`' logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' +### Update apt-get cache logg info 'Running `sudo apt-get update`' sudo apt-get update + +### Install packages if they are not already present for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do - logg info 'Installing `'"$PACKAGE"'`' - sudo apt-get install -y --no-install-recommends "$PACKAGE" || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via apt-get' - logg info 'Proceeding with installation..' - unset EXIT_CODE + logg info 'Checking for presence of `'"$PACKAGE"'`' + if dpkg -l "$PACKAGE" | grep -E '^ii' > /dev/null; then + logg info 'The '"$PACKAGE"' package is already installed' + else + logg info 'Installing `'"$PACKAGE"'`' + sudo apt-get install -y --no-install-recommends "$PACKAGE" || EXIT_CODE=$? + if [ -n "$EXIT_CODE" ]; then + logg error 'Error installing `'"$PACKAGE"'` via apt-get' + logg info 'Proceeding with installation..' + unset EXIT_CODE + fi fi done diff --git a/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl b/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl index ed1028d6..d4a198d9 100644 --- a/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl +++ b/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl @@ -9,15 +9,22 @@ {{- $additionalPackages := splitList " " (includeTemplate "fedora/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Print dependency list logg 'Installing common dependencies using `dnf`' logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' +### Install packages if they are not already present for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do - logg info 'Installing `'"$PACKAGE"'`' - sudo dnf install -y "$PACKAGE" || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via dnf' - logg info 'Proceeding with installation..' - unset EXIT_CODE + logg info 'Checking for presence of `'"$PACKAGE"'`' + if rpm -qa | grep "$PACKAGE" > /dev/null; then + logg info 'The '"$PACKAGE"' package is already installed' + else + logg info 'Installing `'"$PACKAGE"'`' + sudo dnf install -y "$PACKAGE" || EXIT_CODE=$? + if [ -n "$EXIT_CODE" ]; then + logg error 'Error installing `'"$PACKAGE"'` via dnf' + logg info 'Proceeding with installation..' + unset EXIT_CODE + fi fi done diff --git a/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl b/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl index fe055e4a..7a2f6e81 100644 --- a/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl +++ b/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl @@ -9,6 +9,7 @@ {{- $additionalPackages := splitList " " (includeTemplate "freebsd/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Print dependency list logg 'Installing common dependencies using `pkg`' logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' diff --git a/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl b/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl index 26149e60..b6d0fb2a 100644 --- a/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl +++ b/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl @@ -9,6 +9,7 @@ {{- $additionalPackages := splitList " " (includeTemplate "opensuse/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Print dependency list logg 'Installing common dependencies using `zypper`' logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' @@ -16,13 +17,18 @@ logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' logg info 'Installing base_devel pattern with `sudo zypper install -t pattern devel_basis`' sudo zypper install -t pattern devel_basis -### Install base dependencies +### Install packages if they are not already present for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do - logg info 'Installing `'"$PACKAGE"'`' - sudo zypper install -y "$PACKAGE" || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via zypper' - logg info 'Proceeding with installation..' - unset EXIT_CODE + logg info 'Checking for presence of `'"$PACKAGE"'`' + if rpm -qa | grep "$PACKAGE" > /dev/null; then + logg info 'The '"$PACKAGE"' package is already installed' + else + logg info 'Installing `'"$PACKAGE"'`' + sudo zypper install -y "$PACKAGE" || EXIT_CODE=$? + if [ -n "$EXIT_CODE" ]; then + logg error 'Error installing `'"$PACKAGE"'` via zypper' + logg info 'Proceeding with installation..' + unset EXIT_CODE + fi fi done diff --git a/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl b/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl index f2119584..decd5441 100644 --- a/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl +++ b/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl @@ -9,17 +9,26 @@ {{- $additionalPackages := splitList " " (includeTemplate "ubuntu/common-dependencies" .) -}} {{- $packages = concat $packages $additionalPackages -}} +### Print dependency list logg 'Installing common dependencies using `apt-get`' logg info 'Dependencies: {{ $packages | sortAlpha | uniq | join " " -}}' +### Update apt-get cache logg info 'Running `sudo apt-get update`' sudo apt-get update + +### Install packages if they are not already present for PACKAGE in {{ $packages | sortAlpha | uniq | join " " -}}; do - logg info 'Installing `'"$PACKAGE"'`' - sudo apt-get install -y --no-install-recommends "$PACKAGE" || EXIT_CODE=$? - if [ -n "$EXIT_CODE" ]; then - logg error 'Error installing `'"$PACKAGE"'` via apt-get' - logg info 'Proceeding with installation..' - unset EXIT_CODE + logg info 'Checking for presence of `'"$PACKAGE"'`' + if dpkg -l "$PACKAGE" | grep -E '^ii' > /dev/null; then + logg info 'The '"$PACKAGE"' package is already installed' + else + logg info 'Installing `'"$PACKAGE"'`' + sudo apt-get install -y --no-install-recommends "$PACKAGE" || EXIT_CODE=$? + if [ -n "$EXIT_CODE" ]; then + logg error 'Error installing `'"$PACKAGE"'` via apt-get' + logg info 'Proceeding with installation..' + unset EXIT_CODE + fi fi done