Skip to content

Commit

Permalink
refactor(#39): update meatbox scripts to be fully posix compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
meatwallace committed May 18, 2019
1 parent fd3e17a commit b88002f
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 64 deletions.
68 changes: 29 additions & 39 deletions bin/meatbox
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,53 @@ log_message() {
}

meatbox_run_script() {
directory="$1"
script="$2"
ctx="$1"
cmd="$2"

(cd "$MEATBOX_SCRIPTS_DIR/$directory" && "./$script")
}

meatbox_run_universal_script() {
script="$1"

meatbox_run_script "universal" "$script"
}

meatbox_run_os_script() {
script="$1"
os="$(uname -s | lowercase)"

if [ -f "$MEATBOX_SCRIPTS_DIR/$os/$script" ]; then
meatbox_run_script "$os" "$script"
if [ -f "$MEATBOX_SCRIPTS_DIR/$ctx/$cmd.sh" ]; then
(cd "$MEATBOX_SCRIPTS_DIR/$ctx" && "./$cmd.sh")
fi
}

meatbox_help() {
usage
}
meatbox_run() {
meatbox_run_script "$kernel" "$cmd"

if [ "$kernel" = "linux" ]; then
distro=""

meatbox_bootstrap() {
start-sudo-loop "$MEATBOX_PASSWORD"
# cat /etc/*release

meatbox_run_os_script "bootstrap.sh"
meatbox_run_universal_script "bootstrap.sh"
}
# ID=alpine
# NAME="Alpine Linux"

if [ "$1" = "bootstrap" ]; then
meatbox_bootstrap
# ID=antergos
# ID_LIKE=archlinux
# NAME="Antergos Linux"
# PRETTY_NAME="Antergos Linux"

exit 0
fi
# DISTRIB_ID=Arch
# NAME="ArchBang Linux"
# ID=arch
# PRETTY_NAME="ArchBang Linux"

meatbox_setup() {
start-sudo-loop "$MEATBOX_PASSWORD"
meatbox_run_script "$distro" "$cmd"
fi

meatbox_run_os_script "setup.sh"
meatbox_run_universal_script "setup.sh"
meatbox_run_script "agnostic" "$cmd"
}

meatbox_update() {
start-sudo-loop "$MEATBOX_PASSWORD"

meatbox_run_os_script "update.sh"
meatbox_run_universal_script "update.sh"
meatbox_help() {
usage
}

meatbox() {
cmd="$1"

case "$cmd" in
bootstrap|setup|update) "meatbox_$cmd" ;;
bootstrap|setup|update)
start-sudo-loop "$MEATBOX_PASSWORD"
meatbox_run "$cmd"
;;
*) meatbox_help ;;
esac
}
Expand Down
2 changes: 1 addition & 1 deletion bin/pacfast
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ download_packages() {
--dir="$cache_dir"

rm "$dl_list_file"
}
}

# if we have unfinished jobs from a previous run, complete them
if [ -f "$dl_list_file" ]; then
Expand Down
4 changes: 2 additions & 2 deletions scripts/agnostic/install_or_update_python_packages.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

pip install --user --upgrade \
pip \
Expand Down
4 changes: 2 additions & 2 deletions scripts/agnostic/install_or_update_zplugin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

sh -c "$(curl -fsSL https://raw.githubusercontent.com/meatwallace/zplugin/master/doc/install.sh)"
4 changes: 2 additions & 2 deletions scripts/agnostic/load_zsh.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

# fire up zsh to trigger zplugin initialization
zsh
2 changes: 1 addition & 1 deletion scripts/agnostic/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

declare scripts="
scripts="
install_or_update_asdf.sh
install_or_update_node_modules.sh
install_or_update_python_packages.sh
Expand Down
2 changes: 1 addition & 1 deletion scripts/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN \
# add a temporary sudo config file allowing our user to use pacman & make without
# a password so our setup script doesn't require a custom `askpass` just for
# docker
echo "${MEATBOX_USER} ALL=NOPASSWD: /bin/sh, /bin/ln, /sbin/apk, /usr/sbin/addgroup, /sbin/rc-update, /sbin/rc-service" >> "/etc/sudoers.d/${MEATBOX_SETUP_SUDOERS_FILE}" && \
echo "${MEATBOX_USER} ALL=NOPASSWD: /bin/sh, /bin/ln, /sbin/apk, /usr/bin/tee, /usr/sbin/addgroup, /sbin/rc-update, /sbin/rc-service" >> "/etc/sudoers.d/${MEATBOX_SETUP_SUDOERS_FILE}" && \
chmod 0440 "/etc/sudoers.d/${MEATBOX_SETUP_SUDOERS_FILE}" && \
apk update && \
apk add --no-cache curl
Expand Down
6 changes: 3 additions & 3 deletions scripts/alpine/add_edge_repositories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -eu

sudo echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories
sudo echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
sudo echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/main" | sudo tee -a /etc/apk/repositories
echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" | sudo tee -a /etc/apk/repositories
echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" | sudo tee -a /etc/apk/repositories
2 changes: 0 additions & 2 deletions scripts/alpine/enable_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -eu

username="$(id -u -n)"

# lightdm
# libvirtd
# virtlogd
Expand Down
1 change: 1 addition & 0 deletions scripts/alpine/install_or_update_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ set -eu

packages="$(grep -v '^\#' ./APKFile | grep .)"

# shellcheck disable=SC2086
apk add --no-cache $packages
7 changes: 7 additions & 0 deletions scripts/alpine/install_pciutils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -eu

if [ ! -x "$(command -v lspci)" ]; then
apk add --no-cache pciutils
fi
2 changes: 1 addition & 1 deletion scripts/arch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN \
# add a temporary sudo config file allowing our user to use pacman & make without
# a password so our setup script doesn't require a custom `askpass` just for
# docker
echo "${MEATBOX_USER} ALL=NOPASSWD: /usr/bin/bash, /usr/bin/ln, /usr/bin/make, /usr/bin/nvidia-xconfig, /usr/bin/pacman, /usr/bin/pacman-key, /usr/bin/systemctl, /usr/bin/usermod, /home/${MEATBOX_USER}/bin/pacfast" >> "/etc/sudoers.d/${MEATBOX_SETUP_SUDOERS_FILE}" && \
echo "${MEATBOX_USER} ALL=NOPASSWD: /usr/bin/sh, /usr/bin/bash, /usr/bin/ln, /usr/bin/make, /usr/bin/nvidia-xconfig, /usr/bin/pacman, /usr/bin/pacman-key, /usr/bin/systemctl, /usr/bin/usermod, /home/${MEATBOX_USER}/bin/pacfast" >> "/etc/sudoers.d/${MEATBOX_SETUP_SUDOERS_FILE}" && \
chmod 0440 "/etc/sudoers.d/${MEATBOX_SETUP_SUDOERS_FILE}"

# swap into our user account
Expand Down
4 changes: 3 additions & 1 deletion scripts/arch/add_pacman_repo_keys.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
#!/bin/sh

set -eu

# andontie-aur
sudo pacman-key --recv-key EA50C866329648EE >/dev/null
Expand Down
4 changes: 2 additions & 2 deletions scripts/arch/install_pciutils.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

if [ ! -x "$(command -v lspci)" ]; then
yay -S --noconfirm "pciutils" >/dev/null
Expand Down
4 changes: 2 additions & 2 deletions scripts/arch/install_yay.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

# install `yay` if it's unavalable, a `pacman` wrapper that integrates the AUR
if [ ! -x "$(command -v yay)" ]; then
Expand Down
4 changes: 2 additions & 2 deletions scripts/arch/update_package_configuration.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu
4 changes: 3 additions & 1 deletion scripts/arch/update_system_packages.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
#!/bin/sh

set -eu

# upgrade our system packages
yay -Su --noconfirm >/dev/null
4 changes: 2 additions & 2 deletions scripts/linux/install_or_update_x11docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
#!/bin/sh

set -eo pipefail
set -e

curl -fsSl https://raw.githubusercontent.com/mviereck/x11docker/master/x11docker | sudo bash -s -- --update >/dev/null

0 comments on commit b88002f

Please sign in to comment.