#!/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" } function assert_reachable_target { local parent_target parent_target=$(dirname "$target") if ! sudo -u nobody -g sudo test -x "$parent_target"; then cat >&2 <&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