Skip to content

Instantly share code, notes, and snippets.

@Stewie410
Created October 19, 2019 01:45
Show Gist options
  • Select an option

  • Save Stewie410/d8a38159cb05b3882fa7ae444915fd52 to your computer and use it in GitHub Desktop.

Select an option

Save Stewie410/d8a38159cb05b3882fa7ae444915fd52 to your computer and use it in GitHub Desktop.
My "rewrite" of u/brunomiguel's bootstrap script
#!/bin/env bash
#
# bootstrap.sh
# Author: u/stewie410
# Date: 2019-10-18
#
# Rewrite for u/brunomiguel
# https://www.reddit.com/r/bash/comments/djcop0/asking_feedback_on_a_bootstrap_script
# ##----------------------------##
# #| Traps |#
# ##----------------------------##
# Always run usv() function when exiting
trap usv EXIT
# ##------------------------------------##
# #| Functions |#
# ##------------------------------------##
# Cleanup
usv() { unset _path_file_pacman _pkg_groups _url_repo_user; }
# Ask user a Yes/No Question, default to Yes -- Args: $1: Prompt
askUser() {
# Prompt user for input
local _ans; read -p "${1}? (Y/n): " _ans
# If the answer, in lowercae, matches "n" or "no", return false; otherwise return true
if [[ "${_ans,,}" =~ ^no? ]]; then return 1; else return 0; fi
}
# Add User Repository
addUserRepo() {
# Ask user to add user repository
if ! askUser "Continue adding User Repository"; then return 1; fi
# Add User Repository to pacman configuration
sudo tee -a "${_path_file_pacman}" <(printf '%s\n' "[userrepository]" "Server = ${_url_repo_user}" "SigLevel = Optional TrustAll")
}
# Install requested groups
groupInstall() {
# Ask user to install package groups
if ! askUser "Continue adding requested groups"; then return 0; fi
# Install package groups
sudo pacman -Syuv "${_pkg_groups[@]}"
}
# Build Meta Package
buildMeta() {
# Ask user to build metapackage
if ! askUser "Continue building metapackage"; then return 0; fi
# Build Metapackage
makepkg -Ccdfi
}
# ##------------------------------------##
# #| Variables |#
# ##------------------------------------##
# Paths -- Files
_path_file_pacman="/etc/pacman.conf"
# Packages to install
_pkg_groups=("base-devel")
# URLs
_url_repo_user="https://userrepository.eu"
# ##----------------------------##
# #| Run |#
# ##----------------------------##
# Add user repository
if ! addUserRepo; then exit 1; fi
# Refresh Mirrors && Install updates
sudo pacman -Syyuv --noconfirm
# Install requested groups
if ! groupInstall; then exit 1; fi
# Build metapackage
if ! buildMeta; then exit 1; fi
# Finish
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment