#!/bin/bash if [ -n "$1" ]; then recipe="$1" else echo "Pick the recipe for which you want to upgrade the apps:" recipe=$(abra recipe ls -m | ./bin/jq '.[].name' -r | ./bin/gum choose) echo "$recipe" fi echo "Pick which apps to upgrade" apps_to_upgrade=$(abra app ls -r $recipe -m | ./bin/jq '.[].apps[].appName' -r | ./bin/gum choose --no-limit) echo -e "\n\nthe following apps will be upgraded:\n$apps_to_upgrade" ./bin/gum confirm "Do you want to continue?" || exit 0 tmate_socket=$(echo $TMUX | awk -F "," '{print $1}') if [ -z "$tmate_socket" ]; then tmate_socket=$(tmate new -P -F "#{socket_path}" -s cc-upgrades -d) echo "tmate socket location is $tmate_socket. If you drop out of it just run tmate -S $tmate_socket attach" sleep 3 tmux -S "$tmate_socket" send-keys C-m tmate -S "$tmate_socket" show-messages | grep session ran_from_tmux=0 else ./bin/gum confirm "It seems like you're running this script in tmux/tmate. Would you like to append new windows to this session or quit the program?" --affirmative "append" --negative "quit" || exit 0 ran_from_tmux=1 fi for app in $apps_to_upgrade; do app_sanitized=$(echo $app | sed 's/\./_/g') tmux -S "$tmate_socket" new-window tmux -S "$tmate_socket" rename-window "$app_sanitized" tmux -S "$tmate_socket" send-keys "abra app upgrade --no-input $app" C-m done if [ "$ran_from_tmux" = "0" ]; then tmux -S "$tmate_socket" attach fi