@@ -134,6 +134,7 @@ case "$COMMAND" in
134134 activate)
135135 [[ ${# ARGS[@]} -eq 0 ]] && { echo " ERROR: Specify generation to activate" >&2 ; exit 1; }
136136 gen_id=" ${ARGS[0]} "
137+ acquire_lock
137138 # Validate gen_id format
138139 if [[ ! " $gen_id " =~ ^[0-9]{8}-[0-9]{6}(-.+)? $ ]]; then
139140 echo " ERROR: Invalid generation ID format: ${gen_id} " >&2
@@ -144,18 +145,23 @@ case "$COMMAND" in
144145 echo " Generation ${gen_id} is already active"
145146 exit 0
146147 fi
147- # Check if UKI exists
148- if [[ ! -f " ${ESP} /EFI/Linux/arch-${gen_id} .efi" ]]; then
148+ # Check if UKI exists (regular or active)
149+ if [[ ! -f " ${ESP} /EFI/Linux/arch-${gen_id} .efi" ]] && \
150+ [[ ! -f " ${ESP} /EFI/Linux/0-active-arch-${gen_id} .efi" ]] && \
151+ [[ ! -d " ${BTRFS_MOUNT} /root-${gen_id} " ]]; then
149152 echo " ERROR: Generation not found: ${gen_id} " >&2
150153 exit 1
151154 fi
152155 # Rename to add active prefix
153- mv " ${ESP} /EFI/Linux/arch-${gen_id} .efi" " ${ESP} /EFI/Linux/0-active-arch-${gen_id} .efi"
156+ if [[ -f " ${ESP} /EFI/Linux/arch-${gen_id} .efi" ]]; then
157+ mv " ${ESP} /EFI/Linux/arch-${gen_id} .efi" " ${ESP} /EFI/Linux/0-active-arch-${gen_id} .efi"
158+ fi
154159 echo " Activated: ${gen_id} (will boot first)"
155160 ;;
156161 deactivate)
157162 [[ ${# ARGS[@]} -eq 0 ]] && { echo " ERROR: Specify generation to deactivate" >&2 ; exit 1; }
158163 gen_id=" ${ARGS[0]} "
164+ acquire_lock
159165 # Validate gen_id format
160166 if [[ ! " $gen_id " =~ ^[0-9]{8}-[0-9]{6}(-.+)? $ ]]; then
161167 echo " ERROR: Invalid generation ID format: ${gen_id} " >&2
@@ -173,6 +179,7 @@ case "$COMMAND" in
173179 protect)
174180 [[ ${# ARGS[@]} -eq 0 ]] && { echo " ERROR: Specify generation to protect" >&2 ; exit 1; }
175181 gen_id=" ${ARGS[0]} "
182+ acquire_lock
176183 # Validate gen_id format
177184 if [[ ! " $gen_id " =~ ^[0-9]{8}-[0-9]{6}(-.+)? $ ]]; then
178185 echo " ERROR: Invalid generation ID format: ${gen_id} " >&2
@@ -185,7 +192,8 @@ case "$COMMAND" in
185192 fi
186193 # Check if UKI exists (could be active or regular)
187194 if [[ -f " ${ESP} /EFI/Linux/arch-${gen_id} .efi" ]] || \
188- [[ -f " ${ESP} /EFI/Linux/0-active-arch-${gen_id} .efi" ]]; then
195+ [[ -f " ${ESP} /EFI/Linux/0-active-arch-${gen_id} .efi" ]] || \
196+ [[ -d " ${BTRFS_MOUNT} /root-${gen_id} " ]]; then
189197 touch " ${ESP} /EFI/Linux/arch-${gen_id} .efi.protected"
190198 echo " Protected: ${gen_id} (won't be garbage collected)"
191199 else
@@ -196,6 +204,7 @@ case "$COMMAND" in
196204 unprotect)
197205 [[ ${# ARGS[@]} -eq 0 ]] && { echo " ERROR: Specify generation to unprotect" >&2 ; exit 1; }
198206 gen_id=" ${ARGS[0]} "
207+ acquire_lock
199208 # Validate gen_id format
200209 if [[ ! " $gen_id " =~ ^[0-9]{8}-[0-9]{6}(-.+)? $ ]]; then
201210 echo " ERROR: Invalid generation ID format: ${gen_id} " >&2
0 commit comments