diff --git a/setup b/setup index f0909a2..5e2d030 100755 --- a/setup +++ b/setup @@ -72,17 +72,14 @@ setup_new() { echo -e "${BOLD}Setting up first device...${NC}" echo "" - # Ask for grapho repo URL and branch - echo -n "Your grapho flake repo URL (e.g., https://github.com/you/grapho): " - read -r grapho_url - [[ -z "$grapho_url" ]] && { err "Repo URL is required"; exit 1; } + # Ask for config repo URL (Tier 2: personal config/secrets) + echo "Where should your personal config be stored? (private git repo)" + echo -n "Config repo URL (e.g., git@github.com:you/my-config.git): " + read -r config_url echo -n "Branch [master]: " - read -r grapho_branch - grapho_branch="${grapho_branch:-master}" - - # Build nix run command - local nix_run_cmd="nix run 'git+${grapho_url}?ref=${grapho_branch}'" + read -r config_branch + config_branch="${config_branch:-master}" echo "" mkdir -p "$USYNC_DIR" @@ -124,16 +121,19 @@ EOF git -C "$config_dir" commit -q --no-gpg-sign -m "Initial setup" fi + # Set up remote if URL provided + if [[ -n "$config_url" ]]; then + step "Setting up git remote..." + git -C "$config_dir" remote remove origin 2>/dev/null || true + git -C "$config_dir" remote add origin "$config_url" + git -C "$config_dir" branch -M "$config_branch" + fi + local age_key age_key=$(grep 'AGE-SECRET-KEY' "$AGE_KEY_FILE") - # Build instructions - local instructions - instructions="# On other devices, run: -${nix_run_cmd} -- '${age_key}' - -# To pair mobile: -${nix_run_cmd} -- mobile" + # Build join command for other devices + local join_cmd="nix run '' -- '${config_url}' '${age_key}'" # Summary echo "" @@ -146,29 +146,41 @@ ${nix_run_cmd} -- mobile" echo "Device ID: ${device_id:0:20}..." fi echo "" - echo "Next steps:" - echo " 1. Push config to git server:" - echo " cd $config_dir && git remote add origin && git push -u origin main" + if [[ -n "$config_url" ]]; then + echo "Next steps:" + echo " 1. Push config:" + echo " cd $config_dir && git push -u origin $config_branch" + echo "" + echo " 2. On other devices, run this flake and choose 'Join':" + echo " Config URL: ${config_url}" + echo " Age key: ${age_key}" + else + echo "Next steps:" + echo " 1. Create a private git repo and push config:" + echo " cd $config_dir" + echo " git remote add origin " + echo " git push -u origin $config_branch" + fi echo "" - echo " 2. On other devices, run:" - echo " ${nix_run_cmd} -- " - echo "" - echo " 3. To pair mobile:" - echo " ${nix_run_cmd} -- mobile" + echo "To pair mobile: run this flake and choose 'mobile'" - # Copy to clipboard if possible - if has xclip; then - echo "$instructions" | xclip -selection clipboard - echo "" - ok "Instructions copied to clipboard!" - elif has wl-copy; then - echo "$instructions" | wl-copy - echo "" - ok "Instructions copied to clipboard!" - elif has pbcopy; then - echo "$instructions" | pbcopy - echo "" - ok "Instructions copied to clipboard!" + # Copy join info to clipboard if URL provided + if [[ -n "$config_url" ]]; then + local clipboard_text="Config URL: ${config_url} +Age key: ${age_key}" + if has xclip; then + echo "$clipboard_text" | xclip -selection clipboard + echo "" + ok "Config URL and age key copied to clipboard!" + elif has wl-copy; then + echo "$clipboard_text" | wl-copy + echo "" + ok "Config URL and age key copied to clipboard!" + elif has pbcopy; then + echo "$clipboard_text" | pbcopy + echo "" + ok "Config URL and age key copied to clipboard!" + fi fi } @@ -183,18 +195,6 @@ setup_join() { echo -e "${BOLD}Joining existing setup...${NC}" echo "" - # Ask for grapho repo URL and branch - echo -n "Your grapho flake repo URL (e.g., https://github.com/you/grapho): " - read -r grapho_url - [[ -z "$grapho_url" ]] && { err "Repo URL is required"; exit 1; } - - echo -n "Branch [master]: " - read -r grapho_branch - grapho_branch="${grapho_branch:-master}" - - local nix_run_cmd="nix run 'git+${grapho_url}?ref=${grapho_branch}'" - - echo "" mkdir -p "$USYNC_DIR" # Handle @file syntax @@ -235,40 +235,36 @@ setup_join() { local devices_file="$USYNC_DIR/devices.json" echo "{\"devices\":{\"$(hostname)\":{\"id\":\"$device_id\",\"added\":\"$(date -Iseconds)\"}}}" > "$devices_file" - # Build instructions - local instructions - instructions="# Add this device on your other machines: -${nix_run_cmd} -- add $device_id $(hostname) - -# To pair mobile: -${nix_run_cmd} -- mobile" - echo "" echo -e "${G}=== Joined! ===${NC}" echo "" if [[ -n "$device_id" ]]; then echo "This device: ${device_id:0:20}..." echo "" - echo "Add this device on your other machines:" - echo -e " ${BOLD}${nix_run_cmd} -- add $device_id $(hostname)${NC}" + echo "Run 'add' on other machines to connect this device:" + echo -e " ${BOLD}Device ID: $device_id${NC}" + echo -e " ${BOLD}Name: $(hostname)${NC}" fi echo "" - echo "To pair mobile: ${nix_run_cmd} -- mobile" - echo "To sync: ./scripts/usync" + echo "To pair mobile: run this flake with 'mobile' option" - # Copy to clipboard if possible - if has xclip; then - echo "$instructions" | xclip -selection clipboard - echo "" - ok "Instructions copied to clipboard!" - elif has wl-copy; then - echo "$instructions" | wl-copy - echo "" - ok "Instructions copied to clipboard!" - elif has pbcopy; then - echo "$instructions" | pbcopy - echo "" - ok "Instructions copied to clipboard!" + # Copy device info to clipboard + if [[ -n "$device_id" ]]; then + local clipboard_text="Device ID: $device_id +Name: $(hostname)" + if has xclip; then + echo "$clipboard_text" | xclip -selection clipboard + echo "" + ok "Device info copied to clipboard!" + elif has wl-copy; then + echo "$clipboard_text" | wl-copy + echo "" + ok "Device info copied to clipboard!" + elif has pbcopy; then + echo "$clipboard_text" | pbcopy + echo "" + ok "Device info copied to clipboard!" + fi fi }