#!/bin/bash

# archypr:summary=Update Omarchy and system packages
# archypr:args=[-y]
# archypr:examples=omarchy update | omarchy update -y
# archypr:requires-sudo=true

set -e

# Run the update inside a PTY so pacman/yay keep showing download progress
# while still logging the full session for later analysis.
if [[ -z $ARCHYPR_UPDATE_LOGGED ]]; then
  script_command=$(printf '%q ' "$0" "$@")
  exec env ARCHYPR_UPDATE_LOGGED=1 script -qefc "$script_command" "/tmp/archypr-pdate.log"
fi

trap 'echo ""; echo -e "\033[0;31mSomething went wrong during the update!\n\nPlease review the output above carefully, correct the error, and retry the update.\n\nIf you need assistance, get help from the community at https://omarchy.org/discord\033[0m"' ERR

if [[ $1 == "-y" ]] || archypr-update-confirm; then
  archypr-snapshot create || (($? == 127))
  archypr-update-git
  archypr-update-perform
fi
