Skip to content

Commit

Permalink
feat(package-management): add installation script for SNAP packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed May 24, 2023
1 parent b0760bd commit 96c6a89
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
5 changes: 2 additions & 3 deletions chezmoi/.chezmoidata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,14 @@ packages:
- name: microk8s
brew: true
snap: true
post_install: id -nG "${USER}" | grep -qw microk8s || sudo usermod -a -G microk8s "${USER}"
scope: optional
- name: mypy
pipx: true
check_installed: command -v dmypy &>/dev/null
scope: optional
- name: ngrok
snap: true
apt: true
gpg_key_file: ngrok.asc
gpg_key_url: https://ngrok-agent.s3.amazonaws.com/ngrok.asc
source_list_file: ngrok.list
Expand Down Expand Up @@ -292,7 +293,6 @@ packages:
brew: true
scope: optional
- name: rust
snap: true
script: true
script_cmd: "curl https://sh.rustup.rs -sSf | sh -s -- -y --profile=minimal"
check_installed: "command -v rustup &> /dev/null"
Expand Down Expand Up @@ -346,7 +346,6 @@ packages:
scope: gui
- name: yq
brew: true
snap: true
script: true
script_cmd: install-yq
scope: minimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ else
log_info "No missing packages to install with APT"
fi

log_green "✅ APT packages installed successfully. ✨ 🌟 ✨"
# {{ end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ for package in "${wanted_cask_packages[@]}"; do
fi
done

log_green "✅ BREW packages installed successfully. ✨ 🌟 ✨"
# {{ end -}}
47 changes: 47 additions & 0 deletions chezmoi/dot_local/bin/executable_dotfiles-install-snap-pkgs.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# shellcheck disable=SC1083
# {{ if and (eq .chezmoi.os "linux") .system.is_sudoer }}
# {{ template "scripts-library" }}
log_task "Installing SNAP packages"

# shellcheck source=/dev/null
source "${HOME}/.config/shrc/05-package-list"

USER=${USER-:$(whoami)}
DOTFILES_PKGS_SNAP=${DOTFILES_PKGS_SNAP:-()}
DOTFILES_PKGS_TO_INSTALL=${DOTFILES_PKGS_TO_INSTALL:-()}

wanted_packages=()
for package in "${DOTFILES_PKGS_SNAP[@]}"; do
if is_item_in_array "${package}" "${DOTFILES_PKGS_TO_INSTALL[@]}"; then
wanted_packages+=("${package}")
fi
done
log_info "Wanted packages: ${wanted_packages[*]}"

missing_packages=()

for package in "${wanted_packages[@]}"; do
if ! is_snap_package_installed "${package}"; then
missing_packages+=("${package}")
fi
done

if [[ ${#missing_packages[@]} -gt 0 ]]; then
log_task "Installing missing packages with SNAP: ${missing_packages[*]}"

# This script also gets called when running rootmoi
if [ "$USER" = "root" ]; then
snap_command=(snap)
else
snap_command=(sudo snap)
fi
for package in "${missing_packages[@]}"; do
c "${snap_command[@]}" install "${package}" --classic
done
else
log_info "No missing packages to install with SNAP"
fi

log_green "✅ SNAP packages installed successfully. ✨ 🌟 ✨"
# {{ end -}}

0 comments on commit 96c6a89

Please sign in to comment.