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.

82 lines
1.9 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 {
local parent_target
parent_target=$(dirname "$target")
if ! sudo -u nobody -g sudo test -x "$parent_target"; then
cat >&2 <<EOF
MIAOU ERROR: development mode unreachable for folder: $parent_target
quick fix:
sudo chgrp sudo $parent_target
sudo chmod g+rx $parent_target
EOF
return 20
fi
}
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
}
function fetch_target {
local name
name=$(echo "$GIT_URL" | cut -d/ -f2)
name="${name%.git}"
target="$PWD/$name"
echo "development mode target: $target"
}
# Main
source "$MIAOU_BASH_DIR"/lib/functions.bash
assert_normal_user
assert_devmode_available
assert_credentials
fetch_target
assert_reachable_target
_confirm_destructive "target directory will be: ${target}"
dev_mode