66 lines
1.4 KiB
Bash
Executable File
66 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Run pending Omarchy migrations for the current user.
|
|
# omarchy:args=[--pending]
|
|
|
|
set -euo pipefail
|
|
|
|
mode="run"
|
|
while (($#)); do
|
|
case "$1" in
|
|
--pending|--check)
|
|
mode="pending"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
echo "Usage: omarchy-migrate-user [--pending]"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}"
|
|
STATE_DIR="${OMARCHY_USER_MIGRATION_STATE:-$HOME/.local/state/omarchy/migrations/user}"
|
|
MIGRATIONS_DIR="$OMARCHY_PATH/migrations/user"
|
|
|
|
pending_migrations() {
|
|
[[ -d $MIGRATIONS_DIR ]] || return 0
|
|
|
|
for file in "$MIGRATIONS_DIR"/*.sh; do
|
|
[[ -f $file ]] || continue
|
|
filename=$(basename "$file")
|
|
|
|
if [[ ! -f $STATE_DIR/$filename ]]; then
|
|
printf '%s\n' "$filename"
|
|
fi
|
|
done
|
|
}
|
|
|
|
if [[ $mode == "pending" ]]; then
|
|
pending_output=$(pending_migrations)
|
|
if [[ -n $pending_output ]]; then
|
|
printf '%s\n' "$pending_output"
|
|
exit 0
|
|
else
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
mkdir -p "$STATE_DIR"
|
|
[[ -d $MIGRATIONS_DIR ]] || exit 0
|
|
|
|
for file in "$MIGRATIONS_DIR"/*.sh; do
|
|
[[ -f $file ]] || continue
|
|
filename=$(basename "$file")
|
|
|
|
if [[ ! -f $STATE_DIR/$filename ]]; then
|
|
echo -e "\e[32m\nRunning user migration (${filename%.sh})\e[0m"
|
|
OMARCHY_PATH="$OMARCHY_PATH" bash -euo pipefail "$file"
|
|
touch "$STATE_DIR/$filename"
|
|
fi
|
|
done
|