rice

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3a266fe2bcbfa1630b110e937fd51adcf2743bef
parent 7fa5c1b5a1713200592a20730350936b962e74b4
Author: Mark Feller <mfeller@recurly.com>
Date:   Wed, 15 Jan 2020 13:49:50 -0700

more script cleanup

Signed-off-by: Mark Feller <mfeller@recurly.com>

Diffstat:
Minstall | 64+++++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 13 deletions(-)

diff --git a/install b/install @@ -1,13 +1,34 @@ #!/bin/sh # # Auto installer for Fedora packages and dot files -dotrepo=${dotrepo:-"https://gitlab.com/mark.feller/rice.git"} -pkgfile=${pkgfile:-"https://gitlab.com/mark.feller/rice/raw/master/pkgs/fedora/packages"} -logfile=${logfile:-"/var/log/rice.log"} -log() { printf '\033[1;33m%s \033[m%s\033[m %s\n' "->" "${2:+}$1${2:+}" "$2" | tee "$logfile"; } -die() { log "$2"; exit 1; } -try() { "$@" || die "Cannot $*"; } +log() { + # Print a message prettily. + # + # This function uses the literal escape character (Ctrl+V+Escape) as + # a simple way of *safely* bypassing the escape sequence restrictions + # on 'printf %s'. Cheeky, I know. + # + # '\033[1;32m' Set text to color '2' and make it bold. + # '\033[m': Reset text formatting. + # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. + # '${2:+[1;3Xm}': If the 2nd argument exists, set the text style of '$1'. + # '$((${#1}%5+1))': Color the package name based on its length. + # '${2:+[m}': If the 2nd argument exists, reset text formatting. + printf '\033[1;33m%s \033[m%s\033[m %s\n' \ + "${3:-->}" "${2:+}$1${2:+}" "$2" | tee "$logfile" +} + +die() { + # Print a message and exit with '1' (error). + log "$1" "$2" "!>" >&2 + exit 1 +} + +try() { + # Attemped to run the command and exit on error + "$@" || die "Fatal: $*" +} trim_string() { # Usage: trim_string " example string " @@ -18,7 +39,6 @@ trim_string() { pre_install() { # Run any preinstall setup necessary - log "Enabling RPM Fustion" try dnf install -y \ https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-"$(rpm -E %fedora)".noarch.rpm \ @@ -34,7 +54,6 @@ pre_install() { install_package() { # Install a single package $1 based on its flags $2 - case $2 in G) log "Installing go package $1" @@ -64,14 +83,33 @@ EOF install_dots() { # Clone and install dot files - log "Fetching dot files" git clone "$dotrepo" ~/.config/rice >> "$logfile" || log "Dots have already been cloned" (cd ~/.config/rice && stow --target="$HOME" --ignore='gitignore' dots) } +cleanup() { + # Cleanup on exit or error. + die "Aborting auto rice" +} + +main() { + # Set the git repo location for downloading dotfiles. This can be overridden + # to install custom dotfiles. + dotrepo=${dotrepo:-"https://gitlab.com/mark.feller/rice.git"} + + # Set the package list file that contains all packages to be installed. + pkgfile=${pkgfile:-"https://gitlab.com/mark.feller/rice/raw/master/pkgs/fedora/packages"} + + # Set the log output file + logfile=${logfile:-"/var/log/rice.log"} + + trap cleanup INT + + log "Running installer for Fedora" + pre_install + install_packages + install_dots +} -log "Running installer for Fedora" -pre_install -install_packages -install_dots +main