#!/bin/bash # # Purpose : Install coredesktop-dev (run by CoreDesktop's `sibling add`). Safe to # re-run: that's how to change the working copy or repair the install. set -e SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" COREDESKTOP="$HOME/.local/share/coredesktop" if [ ! -f "$COREDESKTOP/utils.sh" ]; then echo "CoreDesktop isn't installed in $COREDESKTOP; install it first." exit 1 fi source "$COREDESKTOP/utils.sh" source "$SELF/lib/common.sh" load_config default="${WORKING_COPY:-$HOME/Projects/coredesktop}" # Ask until the answer is a CoreDesktop clone, or a folder to clone one into while true; do if ! read -rp "Your working copy of CoreDesktop, where you make changes [$default]: " answer; then echo die "No answer; run this again in a terminal: bash $SELF/install.sh" fi dir="${answer:-$default}" dir="${dir/#\~/$HOME}" dir="$(realpath -m "$dir")" if is_deployed_copy "$dir"; then echo "$dir is the deployed copy, which update keeps current. Changing it stops" echo "update from pulling. Choose another folder, e.g. ~/Projects/coredesktop." continue fi if is_coredesktop_clone "$dir"; then origin="$(git -C "$dir" remote get-url origin 2> /dev/null || true)" if [[ "$origin" != *coredesktop* ]]; then echo "Note: $dir's origin ($origin) doesn't look like CoreDesktop's repo." fi break fi if [ -e "$dir" ] && [ -n "$(ls -A "$dir" 2> /dev/null)" ]; then echo "$dir isn't a clone of CoreDesktop, and isn't empty. Choose another folder." continue fi url="$(git -C "$COREDESKTOP" remote get-url origin)" read -rp "Clone CoreDesktop from $url into $dir? [Y/n] " answer || answer=n if [[ "$answer" != [nN]* ]]; then git clone "$url" "$dir" break fi done save_config "$dir" WORKING_COPY="$dir" echo "Working copy: $dir (saved in $CONFIG)" bash "$SELF/update.sh" source "$SELF/lib/hooks.sh" if ! hook_is_ours "$(hook_path)"; then echo echo "A pre-push hook can run coredesktop-dev check before each git push from" echo "$dir, and stop the push if it fails." if confirm "Install it?"; then "$HOME/.local/bin/coredesktop-dev" hooks install || true fi fi echo "$HOME/.local/bin/coredesktop-dev" doctor || true echo echo "coredesktop-dev installed. Run coredesktop-dev --help to see what it does."