cloudron-support: add --patch

This commit is contained in:
Girish Ramakrishnan
2024-07-12 11:03:56 +02:00
parent 0bab0ed748
commit bf34b13b7f

View File

@@ -21,6 +21,7 @@ readonly HELP_MESSAGE="
Options:
--disable-dnssec Disable DNSSEC
--enable-remote-access Enable SSH Remote Access for the Cloudron support team
--patch Apply a patch from git. WARNING: Do not use unless you know what you are doing!
--recreate-containers Deletes all existing containers and recreates them without loss of data
--recreate-docker Deletes docker storage (containers and images) and recreates it without loss of data
--send-diagnostics Collects server diagnostics and uploads it to ${PASTEBIN}
@@ -623,9 +624,41 @@ function recreate_docker() {
rm "${stagefile}"
}
function apply_patch() {
commit_id="$1"
patch_file="/tmp/${commit_id}.patch"
# gitlab will return 404 if it looks like a valid commit id but doesn't exist. it returns login page with invalid commit id
if ! curl -s "https://git.cloudron.io/cloudron/box/-/commit/${commit_id}.patch" -D /tmp/headers -o "${patch_file}"; then
echo "Could not connect to git"
exit 1
fi
if ! grep -q "content-type: text/plain" /tmp/headers; then
echo "Not a valid commit"
exit 1
fi
echo "This will apply ${commit_id} (${patch_file}) from git and restart the box code."
warn "Do not proceed unless you know what you are doing."
read -p "Do you want to apply the patch ? (y/N) " -n 1 -r choice
echo -e "\n"
[[ ! $choice =~ ^[Yy]$ ]] && exit 1
if ! patch --force --dry-run -d /home/yellowtent/box -p1 -i "${patch_file}"; then
echo "Patch does not apply cleanly"
exit 1
fi
patch -d /home/yellowtent/box -p1 -i "${patch_file}"
systemctl restart box
echo "Patch applied"
}
check_disk_space
args=$(getopt -o "" -l "admin-login,disable-dnssec,enable-ssh,enable-remote-access,help,owner-login,recreate-containers,recreate-docker,send-diagnostics,use-external-dns,troubleshoot" -n "$0" -- "$@")
args=$(getopt -o "" -l "admin-login,disable-dnssec,enable-ssh,enable-remote-access,help,owner-login,patch:,recreate-containers,recreate-docker,send-diagnostics,use-external-dns,troubleshoot" -n "$0" -- "$@")
eval set -- "${args}"
while true; do
@@ -644,6 +677,7 @@ while true; do
--use-external-dns) use_external_dns; exit 0;;
--recreate-containers) recreate_containers; exit 0;;
--recreate-docker) recreate_docker; exit 0;;
--patch) apply_patch "$2"; exit 0;;
--help) break;;
--) break;;
*) echo "Unknown option $1"; exit 1;;