irongit

feat: uds and udz for updates and cron for caching if updates are available

huncholanehuncholaneauthored
parent 4356bc6commit 86084612c4d319ba134fd4b40f7d90c175e8c64dBrowse files

6 files changed, +67 -33

+2-2.zshrc
@@ -7,8 +7,8 @@ fpath=("${ZDOTDIR}/.zfunc" $fpath)
77 source "$ZDOTDIR/precomp.sh"
88 autoload -Uz compinit && compinit
99
10-# Check for updates
11-source "${ZDOTDIR}/updates.sh"
10+# Update checks and functions
11+source "$ZDOTDIR/update_functions.sh"
1212
1313 # Post compinit setups. Good for overriding plugins.
1414 source "$ZDOTDIR"/env.sh
+1-0config.sh
@@ -27,5 +27,6 @@ if command -v tmux &>/dev/null; then
2727 tmux set -g pane-border-format " #{pane_index} | #{pane_current_command} | $(whoami)@#[bold]$(hostname)#[nobold]:#{pane_current_path} " &>/dev/null
2828 fi
2929
30+
3031 # Use powerlevel10k
3132 [[ ! -f ~/.config/zsh/.p10k.zsh ]] || source ~/.config/zsh/.p10k.zsh
+7-0install.sh
@@ -70,6 +70,13 @@ if [[ "$yn" == "y" ]]; then
7070 fi
7171 fi
7272
73+# Register update check cron job (every 6 hours)
74+CRON_CMD="0 */6 * * * $HOME/.config/zsh/updates.sh # dotzsh-update-check"
75+if ! crontab -l 2>/dev/null | grep -q "dotzsh/monitor_updates.sh"; then
76+ (crontab -l 2>/dev/null; echo "$CRON_CMD") | crontab -
77+ echo "Registered update check cron job"
78+fi
79+
7380 # Arch specific installations
7481 if [ -f /etc/arch-release ]; then
7582 echo "Arch detected"
+27-0monitor_updates.sh
@@ -0,0 +1,27 @@
1+#!/bin/bash
2+
3+# Run by cron every 6 hours. Caches update status for shell startup to read.
4+
5+CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/dotzsh"
6+mkdir -p "$CACHE_DIR"
7+
8+# Check for system updates
9+if command -v paru &>/dev/null; then
10+ paru -Qu > "$CACHE_DIR/system_updates" 2>/dev/null
11+elif command -v pacman &>/dev/null; then
12+ pacman -Qu > "$CACHE_DIR/system_updates" 2>/dev/null
13+elif command -v apt &>/dev/null; then
14+ apt list --upgradeable 2>/dev/null | tail -n +2 > "$CACHE_DIR/system_updates"
15+elif command -v dnf &>/dev/null; then
16+ dnf check-update 2>/dev/null > "$CACHE_DIR/system_updates"
17+fi
18+
19+# Check for dotzsh updates
20+ZDOTDIR="${ZDOTDIR:-$HOME/.config/zsh}"
21+if (cd "$ZDOTDIR" && git fetch origin &>/dev/null); then
22+ if (cd "$ZDOTDIR" && [ "$(git rev-parse HEAD)" != "$(git rev-parse '@{u}' 2>/dev/null)" ]); then
23+ echo "1" > "$CACHE_DIR/dotzsh_update"
24+ else
25+ rm -f "$CACHE_DIR/dotzsh_update"
26+ fi
27+fi
+30-0update_functions.sh
@@ -0,0 +1,30 @@
1+# Check for updates (reads from cache, no network)
2+_dotzsh_cache="${XDG_CACHE_HOME:-$HOME/.cache}/dotzsh"
3+if [[ -s "$_dotzsh_cache/system_updates" ]]; then
4+ printf "\e[33mSystem updates available. Run uds to update.\e[0m\n"
5+fi
6+if [[ -f "$_dotzsh_cache/dotzsh_update" ]]; then
7+ printf "\e[34mdotzsh update available. Run udz to apply.\e[0m\n"
8+fi
9+unset _dotzsh_cache
10+
11+# Update system
12+uds() {
13+ if command -v paru &>/dev/null; then
14+ paru -Syu
15+ elif command -v pacman &>/dev/null; then
16+ sudo pacman -Syu
17+ elif command -v apt &>/dev/null; then
18+ sudo apt update && sudo apt upgrade
19+ elif command -v dnf &>/dev/null; then
20+ sudo dnf upgrade
21+ fi
22+ rm -f "${XDG_CACHE_HOME:-$HOME/.cache}/dotzsh/system_updates"
23+}
24+
25+# Update dotzsh
26+udz() {
27+ printf "\e[34mUpdating dotzsh\e[0m\n"
28+ (cd "$ZDOTDIR" && git pull --rebase)
29+ rm -f "${XDG_CACHE_HOME:-$HOME/.cache}/dotzsh/dotzsh_update"
30+}
+0-31updates.sh
@@ -1,31 +0,0 @@
1-#!/usr/bin/bash
2-
3-# Check for system updates
4-ue() {
5- printf "\e[33mWARNING: System is outdated\e[0m\n"
6-}
7-
8-if command -v paru &>/dev/null; then
9- paru -Qu &>/dev/null && ue
10-elif command -v apt; then
11- apt list --upgradeable &>/dev/null && ue
12-elif command -v dnf; then
13- dnf check-update &>/dev/null && ue
14-fi
15-
16-unfunction ue
17-
18-# Check updates for dotzsh
19-(
20- cd "$ZDOTDIR" && git fetch origin && if [ "$(git rev-parse HEAD)" != "$(git rev-parse '@{u}')" ]; then
21- printf "\e[34mdotzsh update available. Run udz to apply.\e[0m\n"
22- fi
23-)
24-
25-# Update dotzsh
26-udz() {
27- printf "\e[34mUpdating dotzsh\e[0m\n"
28- (
29- cd "$ZDOTDIR" && git pull --rebase
30- )
31-}