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 19, 2019
1 parent fd3e17a commit 1b3bf66
Show file tree
Hide file tree
Showing 49 changed files with 299 additions and 189 deletions.
8 changes: 4 additions & 4 deletions .bash_profile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# if [[ $- == *i* ]]; then
# shellcheck source=.bashrc
. "$HOME/.bashrc"
# fi
if [[ $- == *i* ]]; then
# shellcheck source=.bashrc
. "$HOME/.bashrc"
fi
2 changes: 1 addition & 1 deletion .bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ asdf_dir="$MEATBOX_LIBS_DIR/asdf"

# load `asdf`, our version manager
if [ -d "$asdf_dir" ]; then
# shellcheck source=.meatbox/libs/asdf/asdf.sh
# shellcheck source=libs/asdf/asdf.sh
. "$asdf_dir/asdf.sh"
fi

Expand Down
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
name: "Build Dockerfile"
command: |
apk add --no-cache git >/dev/null 2>&1
cd scripts/linux/alpine
cd ./scripts/alpine
GIT_COMMIT_SHA1=$CIRCLE_SHA1 ./build.sh
no_output_timeout: 30m

Expand All @@ -46,7 +46,7 @@ jobs:
name: "Build Dockerfile"
command: |
apk add --no-cache git >/dev/null 2>&1
cd scripts/linux/arch
cd ./scripts/arch
GIT_COMMIT_SHA1=$CIRCLE_SHA1 ./build.sh
no_output_timeout: 30m

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
libs/*
!libs/.gitkeep
node_modules
.undodir/
2 changes: 1 addition & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# yarn lockfile v1


lastUpdateCheck 1557472997682
lastUpdateCheck 1558255608083
4 changes: 0 additions & 4 deletions .zprofile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ if (( $#commands[(i)lesspipe(|.sh)] )); then
export LESSOPEN="| /usr/bin/env $commands[(i)lesspipe(|.sh)] %s 2>&-"
fi

# }}}

#: tmp directory {{{

# if we don't have a TMPDIR variable set or it's empty, export it
if [ -z "${TMPDIR}" ]; then
export TMPDIR="/tmp/zsh-${UID}"
Expand Down
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,32 @@

my personal configuration for both Arch Linux based & Mac systems, available as
both an Antergos (Arch) Linux and Alpine Linux based docker image, or can be
installed via the setup script hosted via the URL below.
installed via the setup script hosted via pulling it from the URL as described
below.

i recommend **not** using this, but feel free to take a gander or a gamble.

## Overview

an over-engineered system configuration and related tooling that aims to be
pragmatic for me to use, but is built upon needless complexity, change, and
technology; it serves as a personal playground to facilitate my day to day as
well as ongoing learning & mastery of various workflows & tools.

- `.vimrc`, a new and ongoing venture into the world of `(neo)vim`
- `.zshrc` and associated config files, using `zplugin` for plugin management
- `.config/` with my setup for `awesome`, `rofi`, `compton`, etc. for a full
desktop environment for Linux based systems, aiming for a complete yet
no-frills getting-shit-done workflow orientated around the terminal
- `.zfuncs/` and `bin/`, containing an array of ZSH and POSIX `sh` functions,
respectively
- `scripts/`, containing all of the setup scripts, cooirdinated by `meatbox`,
a simplistic CLI for managing setup & upgrades of the configuration
- `projects/meatlab`, a work in progress config for my home media server,
currently a whopping 2 containers glued together with `docker-compose`
- automatic linting, testing, and building of the config into various docker
images via CircleCI

## Usage

to boot into latest docker image with simple terminal access:
Expand Down Expand Up @@ -56,27 +78,3 @@ x11docker \
meatwallace/meatbox-arch:latest /usr/bin/xinitrcsession-helper
```

## Overview

this repository contains an over-engineered system configuration that aims to
be pragmatic for me to use, but is built upon needless complexity, prone to
changing, and a mix of technologies; it serves as a personal playground for
my learning & mastery of a variety of workflows, tools, languages, and just
generally, sharpening the saw.

some of what you'll find:

- `.vimrc`, a new and ongoing venture into the world of `(neo)vim`
- `.zshrc` and associated config files, using `zplugin` for plugin management
- `.config/` with my setup for `awesome`, `rofi`, `compton`, etc. for a full
desktop environment for Linux based systems, aiming for a complete yet
no-frills getting shit done workflow orientated around the terminal
- `.zfuncs/` and `bin/`, containing an array of ZSH and POSIX `sh` functions,
respectively
- `scripts/`, containing all of the setup scripts, cooirdinated by `meatbox`,
a simplistic CLI for managing setup & upgrades of the configuration
- `projects/meatlab`, a work in progress config for my home media server,
currently a whopping 2 containers glued together with `docker-compose`
- automatic linting, testing, and building of the config into various docker
images via CircleCI

14 changes: 8 additions & 6 deletions bin/git-clone-or-update
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

git_clone_or_update() {
local repo_url="$1"
local repo_dir="$2"
repo_url="$1"
repo_dir="$2"

# use the repository's name as the directory if we didn't explicitly pass one
if is empty "$repo_dir"; then
if [ -z "$repo_dir" ]; then
repo_dir="${repo_dir%.git}"
fi

if is not a directory "$repo_dir"; then
if [ ! -d "$repo_dir" ]; then
mkdir -p "$repo_dir"

git clone "$repo_url" "$repo_dir" >/dev/null
else
(
Expand Down
70 changes: 30 additions & 40 deletions bin/meatbox
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -e
set -ex

usage() {
cat << HEREDOC
Expand All @@ -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() {
kernel="$(uname -s | lowercase)"

meatbox_bootstrap() {
start-sudo-loop "$MEATBOX_PASSWORD"
meatbox_run_script "$kernel" "$cmd"

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

meatbox_run_os_script "bootstrap.sh"
meatbox_run_universal_script "bootstrap.sh"
}
# cat /etc/*release

if [ "$1" = "bootstrap" ]; then
meatbox_bootstrap
# ID=alpine
# NAME="Alpine Linux"

exit 0
fi
# ID=antergos
# ID_LIKE=archlinux
# NAME="Antergos Linux"

meatbox_setup() {
start-sudo-loop "$MEATBOX_PASSWORD"
# DISTRIB_ID=Arch
# NAME="ArchBang Linux"
# ID=arch

meatbox_run_os_script "setup.sh"
meatbox_run_universal_script "setup.sh"
}
meatbox_run_script "$distro" "$cmd"
fi

meatbox_update() {
start-sudo-loop "$MEATBOX_PASSWORD"
meatbox_run_script "agnostic" "$cmd"
}

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
27 changes: 27 additions & 0 deletions bin/meatman
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

set -eu

# TODO: requires much smarter implementation w/ handling of various managers,
# operations, and flags
meatman() {
cmd="$1"
packages="$2"

if [ ! "$cmd" = "add" ]; then
echo "command unsupported"
exit 1
fi

# TODO: handle flags
if [ -x "$(command -v pacman)" ]; then
sudo pacman -Sy --config "$HOME/.config/pacman/pacman.conf" --noconfirm --needed $packages
elif [ -x "$(command -v apk)" ]; then
sudo apk add --no-cache $packages
else
echo "unsupported distro"
exit 1
fi
}

meatman "$@"
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
6 changes: 3 additions & 3 deletions bin/start-sudo-loop
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#!/bin/sh

set -eo pipefail
set -e

start_sudo_loop() {
local password="$1"
password="$1"

if [ -n "$password" ]; then
echo "$password" | sudo -Sv
Expand Down
13 changes: 8 additions & 5 deletions index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ export MEATBOX_SCRIPTS_DIR="$MEATBOX_DIR/scripts"
cd "$HOME"

# ensure the user has a /bin directory, and add it to the path
mkdir "$MEATBOX_BIN_DIR"
if [ ! -d "$MEATBOX_BIN_DIR" ]; then
mkdir "$MEATBOX_BIN_DIR"
fi

export PATH="$MEATBOX_BIN_DIR:$PATH"

# pull down `yadm` and symlink it into our user's /bin
YADM_DIR="$MEATBOX_LIBS_DIR/yadm"
yadm_dir="$MEATBOX_LIBS_DIR/yadm"

if [ ! -d "$YADM_DIR" ]; then
git clone https://github.com/TheLocehiliosan/yadm.git "$YADM_DIR" >/dev/null
if [ ! -d "$yadm_dir" ]; then
git clone https://github.com/thelocehiliosan/yadm.git "$yadm_dir" >/dev/null

ln -fs "$YADM_DIR/yadm" "$MEATBOX_BIN_DIR/yadm"
ln -fs "$yadm_dir/yadm" "$MEATBOX_BIN_DIR/yadm"
fi

# clone our system config and update origin to use SSL in the future
yadm clone -f https://github.com/meatwallace/dotfiles >/dev/null
yadm remote set-url origin "git@github.com:meatwallace/dotfiles.git"

# check out a specific commit if it's been specified e.g. CI pull request
if [ -n "$MEATBOX_CHECKOUT_SHA1" ]; then
yadm checkout "$MEATBOX_CHECKOUT_SHA1"
fi
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@meatwallace/meatbox",
"version": "1.0.0",
"description": "personal configuration for both Arch Linux & Mac systems",
"description": "personal configuration for both Linux & Mac systems",
"repository": "https://github.com/meatwallace/meatbox",
"author": "@meatwallace",
"license": "The Unlicense",
Expand Down
5 changes: 3 additions & 2 deletions scripts/agnostic/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
set -eu

scripts="
install_or_update_asdf.sh
install_or_update_asdf.sh
install_yarn.sh
"

bootstrap() {
Expand All @@ -12,4 +13,4 @@ bootstrap() {
done
}

bootstrap "$@"
bootstrap
Loading

0 comments on commit 1b3bf66

Please sign in to comment.