wip: further cleanup

This commit is contained in:
Andrejus
2021-04-16 00:26:07 +01:00
parent 18689abd73
commit e5223a45db
48 changed files with 405 additions and 361 deletions

View File

@@ -1,78 +1,67 @@
#!/usr/bin/env bash
function apt_update {
sudo apt-get update
}
# Utility functions for common tasks
# @arg $1 debian package to install if not present
function apt_install {
if ! dpkg -s $1; then
sudo apt-get install -y $1
fi
}
# ---------------------------------------------------------------------------- #
# Helper functions
# ---------------------------------------------------------------------------- #
clean() {
sudo apt-get clean
}
update() {
apt_update
}
# @arg $1 packages to install
install() {
apt_install $1
refresh
}
# @arg $1 package list file to install
install_file() {
sudo apt-get install -qqyf $(cat $1)
refresh
}
# @arg $1 repository to add
add_ppa() {
sudo add-apt-repository -y ppa:$1
}
# @arg $1 url to add
# @arg $2 keyring to add to
add_key() {
curl -fsSL $1 \
| sudo gpg --no-default-keyring --keyring $2 --import -
# @arg $1 URL to download
# @arg $2 Path to file
function download_file {
curl \
--silent \
--show-error \
--location \
--output $2 \
$1
}
# @arg $1 URL to run
# @arg $2 binary to use
run() {
curl -fsSL $1 | $2
}
# Symlink contents of source folder to target
#
# @arg $1 source folder
# @arg $2 target folder
link_folder() {
mkdir -p $2
cp -srf $1/. $2
function download_run {
file=$(mktemp)
download_file $1 $file
cat $file | $2
}
# @arg $1 binary to test
not_installed() {
! [ -x "$(command -v $1)" ]
function bin_in_path {
command -v $1
}
# Refreshes PATH
refresh() {
hash -r
# @arg $1 apt package to test
function apt_installed {
dpkg --status $1
}
# Add to PATH and refresh
# @arg $1 path to add to PATH
add_path() {
export PATH="$1:$PATH"
refresh
function clean {
sudo apt-get clean -qq
}
function update {
sudo apt-get update -qq
}
# @arg $1 apt package to install if not present
function install {
if ! apt_installed $1; then
sudo apt-get install -qq $1
fi
}
# Add apt repository
# @arg $1 JSON object containing the following keys
# * repository - apt repository
# * signingKey - gpg signing key url
# * components - apt components
function add_repository {
repository=$(jq -r ".repository" <<<"$1")
if ! grep -q "^deb .*${repository}" /etc/apt/sources.list; then
signingKey=$(jq -r ".signingKey" <<<"$1")
components=$(jq -r ".components" <<<"$1")
curl -fsSL $signingKey | sudo apt-key add -
source="deb [arch=$(dpkg --print-architecture)] ${repository} ${components}"
sudo add-apt-repository --yes "$source"
fi
}
# @arg $1 package list file to install
function install_file {
sudo apt-get install -qqf $(cat $1)
}