#!/bin/bash # # Purpose : Install what an item needs from Pop!_OS' and Ubuntu's apt # repositories, and from Flathub. Source this file; it uses # confirm_yes from configure. # # Pop!_OS comes with less than CoreDesktop installs up front, so each item # installs what it needs the first time you set it up, after asking. is_pop() { [ "$(. /etc/os-release 2> /dev/null && echo "$ID")" = pop ] } os_name() { (. /etc/os-release 2> /dev/null && echo "${PRETTY_NAME:-$ID}") || uname -s } # True if every package named is installed pkg_installed() { local pkg for pkg in "$@"; do [ "$(dpkg-query -W -f '${db:Status-Status}' "$pkg" 2> /dev/null)" = installed ] || return 1 done } # pkg_ensure ...: offer to install the packages # that are missing. Fails if any is still missing. pkg_ensure() { local why="$1" pkg missing=() shift for pkg in "$@"; do pkg_installed "$pkg" || missing+=("$pkg") done [ ${#missing[@]} -eq 0 ] && return 0 echo "$why needs: ${missing[*]}" confirm_yes "Install them now (with apt; asks for your password)?" || return 1 pkg_install "${missing[@]}" } # Install packages without asking. apt's lists may be old on a new install, # so they're refreshed once per run if the install fails. pkg_install() { sudo apt-get install -y "$@" && return 0 [ -n "$PKG_UPDATED" ] && return 1 PKG_UPDATED=1 sudo apt-get update && sudo apt-get install -y "$@" } # Flatpak apps come from Flathub, as in the COSMIC Store flatpak_installed() { flatpak info "$1" &> /dev/null } # flatpak_ensure flatpak_ensure() { flatpak_installed "$1" && return 0 echo "$2 isn't installed. $3" confirm_yes "Install $2 from Flathub?" || return 1 flatpak install -y --noninteractive flathub "$1" }