MIAOU-BASH is a collection of scripts and configurations designed to enhance your terminal experience. As the name suggests, it is built on Bash and is designed to work on most modern GNU/Linux systems.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

#!/usr/bin/env miaou-bash
# Constants
GIT_URL=git@git.artcode.re:miaou/miaou-bash.git
# Functions
function assert_normal_user {
[[ "$UID" -eq 0 ]] && echo 'normal user expected' && return 1
true
}
function assert_credentials {
echo "check for credentials"
local base_url
base_url=$(echo "$GIT_URL" | cut -d: -f1)
if ! ssh -T "${base_url}"; then
>&2 echo "MIAOU ERROR: development mode unavailable because your credentials are missing: $base_url"
builtin exit 2
fi
}
function dev_mode {
git clone "$GIT_URL"
sudo rm "$MIAOU_BASH_DIR" -rf
sudo ln -s "$target" "$MIAOU_BASH_DIR"
sudo -E miaou-bash "$MIAOU_BASH_DIR"/lib/devmode.bash
}
function assert_reachable_target {
sudo -u nobody -g sudo test -x "$(dirname "$target")"
}
function assert_devmode_available {
fetch_mode
if [[ "$MIAOU_BASH_MODE" == development ]]; then
local realpath
realpath=$(realpath "$MIAOU_BASH_DIR"/) # / is required to get real target
if [[ "$MIAOU_BASH_MODE_OWNER" == "$USER" ]]; then
echo "you are already in development mode, check for: $realpath"
return 10
else
>&2 echo "MIAOU ERROR: already in develoment mode, but owned by: $MIAOU_BASH_MODE_OWNER"
return 11
fi
elif [[ "$MIAOU_BASH_MODE" = hosted ]]; then
>&2 echo "MIAOU ERROR: hosted mode detected"
return 12
fi
}
# Main
source "$MIAOU_BASH_DIR"/lib/functions.bash
assert_normal_user
assert_devmode_available
assert_credentials
name=$(echo "$GIT_URL" | cut -d/ -f2)
name="${name%.git}"
target="$PWD/$name"
_confirm_destructive "target directory will be: ${target}"
assert_reachable_target
dev_mode