Initial dump of scripts

This commit is contained in:
2025-09-09 16:49:56 +01:00
parent b828eb88c2
commit 3f9466f287
4 changed files with 186 additions and 0 deletions

39
cc-upgrade-no-confirm Executable file
View File

@ -0,0 +1,39 @@
#!/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

39
cc-upgrades Executable file
View File

@ -0,0 +1,39 @@
#!/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 $app" C-m
done
if [ "$ran_from_tmux" = "0" ]; then
tmux -S "$tmate_socket" attach
fi

94
cc-upgrades-check Executable file
View File

@ -0,0 +1,94 @@
#!/bin/bash
function usage() {
echo "$0 <recipes|apps>: check for co-op cloud recipes"
echo
echo "OPTIONS"
echo "-s|--servers <SERVER_FILE> provide a file with servers"
}
while [[ $# -gt 0 ]]; do
case $1 in
-s|--servers)
server_file="$2"
shift # past argument
shift # past value
;;
recipes)
action="recipes"
shift # past argument
shift # past value
;;
apps)
action="apps"
shift # past argument
shift # past value
;;
-h|--help)
usage
exit 1
;;
*)
echo "Unknown argument"
usage
exit 1
;;
esac
done
if [ -z "$action" ]; then
usage
exit 1
fi
if [ -n "$server_file" ]; then
readarray -t servers < "$server_file"
else
readarray -t servers < <(./bin/gum choose --no-limit < infrastructure-data/coopcloud-servers)
fi
log_file=$(mktemp)
echo "$(tput setaf 7)Logging to $log_file $(tput sgr0)"
echo
if [ "$action" = "recipes" ]; then
readarray -t recipes < <(for server in "${servers[@]}"; do
abra app ls -s "$server" -m | jq -r ".\"$server\".apps[].recipe"
done | sort -u)
for recipe in "${recipes[@]}"; do
echo "$(tput setaf 2)$recipe $(tput sgr0)"
readarray -t line < <(abra recipe upgrade -n -m "$recipe" 2>>"$log_file" | jq -r '. | keys[] as $k | .[$k].service, (.[$k].upgrades | length), (.[$k].upgrades[0])')
if [ "${#line[@]}" = 0 ]; then
echo "$(tput setaf 3)No updates for $recipe $(tput sgr0)"
else
for (( i = 0; i < $(("${#line[@]}" / 3)); i++ )); do
echo "${line[$((i * 3))]} has ${line[$((i * 3 + 1))]} available update(s), latest is ${line[$((i * 3 + 2))]}"
done
fi
echo
done
echo
elif [ "$action" == "apps" ]; then
for server in "${servers[@]}"; do
echo "$(tput setaf 2)Server: $server$(tput sgr0)"
OLDIFS="$IFS"
IFS=$'\n'
for app_data in $(abra app ls -s "$server" -S -m | jq -c ".\"$server\".apps[]"); do
IFS="|" read recipe appName version upgrade < <(echo "$app_data" | jq -r '[.recipe, .appName, .version, .upgrade] | join("|")')
if [ ! "$upgrade" = "latest" ]; then echo -n "$(tput setaf 3)"; fi
if [ "$upgrade" = "unknown" ]; then echo -n "$(tput setaf 1)"; fi
echo "$appName ($recipe): $version → $upgrade"
echo -n "$(tput sgr0)"
done
IFS="$OLDIFS"
echo
done
fi
echo "$(tput setaf 3)Errors and warnings: $(tput sgr0)"
grep -v "no new versions available for" "$log_file"
rm "$log_file"

14
cc-vulnerabilites Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
recipeList=$(curl https://recipes.coopcloud.tech/recipes.json | jq -r '.[].name' | sed 's/-/ /g')
recipe=$(./bin/gum choose $recipeList)
echo $recipe
vulnlist=$(curl "https://services.nvd.nist.gov/rest/json/cves/2.0?keywordSearch=$recipe&keywordExactMatch")
echo $vulnList | jq -r \
'["date", "id", "description", "score"],
(.vulnerabilities[-10:] | reverse | .[].cve | [
.published,
.id,
(.descriptions[] | select(.lang == "en") | .value),
(.metrics.cvssMetricV31[] | select(.source == "nvd@nist.gov") | .cvssData.baseScore)
]) | @csv' | ./bin/gum table --widths=23,14,60