nextboot: minimize and reduce repitition
This commit is contained in:
		
							parent
							
								
									692c361290
								
							
						
					
					
						commit
						28288670a5
					
				
							
								
								
									
										53
									
								
								bin/nextboot
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								bin/nextboot
									
									
									
									
									
								
							@ -73,66 +73,75 @@ while getopts ":en" opt; do
 | 
				
			|||||||
	esac
 | 
						esac
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# If -e wasn't set, and systemd-boot isn't installed, fail over to efimode anyways
 | 
					# If -e wasn't set, and systemd-boot isn't installed, fail over to efimode anyways
 | 
				
			||||||
if [[ ! -v efimode && ! -v sdboot ]]; then
 | 
					if [[ ! -v efimode && ! -v sdboot ]]; then
 | 
				
			||||||
	echo "W: systemd-boot not installed. Choosing EFI boot entries instead..."
 | 
						echo "W: systemd-boot not installed. Choosing EFI boot entries instead..."
 | 
				
			||||||
	efimode=1
 | 
						efimode=1
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# If we're in EFI mode
 | 
					# If we're in EFI mode
 | 
				
			||||||
if [[ -v efimode ]]; then
 | 
					if [[ -v efimode ]]; then
 | 
				
			||||||
	title="Pick EFI boot entry"
 | 
						title="Pick EFI boot entry"
 | 
				
			||||||
	prompt="Entry"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if [[ -v noreboot ]]; then 
 | 
					# If we're in systemd-boot mode
 | 
				
			||||||
		prompt="$prompt for next boot:"
 | 
					elif [[ ! -v efimode ]]; then
 | 
				
			||||||
	elif [[ ! -v noreboot ]]; then
 | 
						title="Pick systemd-boot entry config"
 | 
				
			||||||
		prompt="$prompt to boot IMMEDIATELY:"
 | 
					
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	echo "E: idk how you got here..."
 | 
						echo "E: idk how you got here..."
 | 
				
			||||||
	exit 1
 | 
						exit 1
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Prompt for the user's choice
 | 
					 | 
				
			||||||
	choice="$(selectentry "$title" "$prompt")"
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	# A special case to boot into firmware interface
 | 
					 | 
				
			||||||
	if [[ "$choice" == "$biosname" ]]; then
 | 
					 | 
				
			||||||
		sudo bootctl reboot-to-firmware true
 | 
					 | 
				
			||||||
	elif [[ "$choice" != "$biosname" ]]; then
 | 
					 | 
				
			||||||
		sudo efibootmgr -q --bootnext "$choice"
 | 
					 | 
				
			||||||
	fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# If we're in systemd-boot mode
 | 
					 | 
				
			||||||
elif [[ ! -v efimode ]]; then
 | 
					 | 
				
			||||||
	title="Pick systemd-boot entry config"
 | 
					 | 
				
			||||||
	prompt="Entry"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Specialize prompt for reboot mode
 | 
				
			||||||
if [[ -v noreboot ]]; then
 | 
					if [[ -v noreboot ]]; then
 | 
				
			||||||
		prompt="$prompt for next boot:"
 | 
						prompt="Entry for next boot:"
 | 
				
			||||||
elif [[ ! -v noreboot ]]; then
 | 
					elif [[ ! -v noreboot ]]; then
 | 
				
			||||||
		prompt="$prompt to boot IMMEDIATELY:"
 | 
						prompt="Entry to boot IMMEDIATELY:"
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
	echo "E: idk how you got here either..."
 | 
						echo "E: idk how you got here either..."
 | 
				
			||||||
	exit 1
 | 
						exit 1
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Prompt for the user's choice
 | 
					# Prompt for the user's choice
 | 
				
			||||||
choice="$(selectentry "$title" "$prompt")"
 | 
					choice="$(selectentry "$title" "$prompt")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# A special case to boot into firmware interface
 | 
					# A special case to boot into firmware interface
 | 
				
			||||||
if [[ "$choice" == "$biosname" ]]; then
 | 
					if [[ "$choice" == "$biosname" ]]; then
 | 
				
			||||||
	sudo bootctl reboot-to-firmware true
 | 
						sudo bootctl reboot-to-firmware true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# For all other entry selections
 | 
				
			||||||
elif [[ "$choice" != "$biosname" ]]; then
 | 
					elif [[ "$choice" != "$biosname" ]]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# If we're in EFI mode
 | 
				
			||||||
 | 
						if [[ -v efimode ]]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							# Set bootnext in nvram
 | 
				
			||||||
 | 
							sudo efibootmgr -q --bootnext "$choice"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# If we're in systemd-boot mode
 | 
				
			||||||
 | 
						elif [[ ! -v efimode ]]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							# Set default boot entry only for next boot
 | 
				
			||||||
		sudo bootctl set-oneshot "$choice"
 | 
							sudo bootctl set-oneshot "$choice"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# Add an option to speed past the boot menu, since we've already 
 | 
							# Add an option to speed past the boot menu, since we've already 
 | 
				
			||||||
		#  chosen the desired entry.
 | 
							#  chosen the desired entry.
 | 
				
			||||||
		rebootopts+=("--boot-loader-menu=1")
 | 
							rebootopts+=("--boot-loader-menu=1")
 | 
				
			||||||
	fi
 | 
					
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		echo "E: you DEFINITELY don't belong here..."
 | 
							echo "E: you DEFINITELY don't belong here..."
 | 
				
			||||||
		exit 1
 | 
							exit 1
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						echo "E: must you insist on breaking my things?"
 | 
				
			||||||
 | 
						exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Reboot if necessary
 | 
				
			||||||
[[ ! -v noreboot ]] && sudo systemctl reboot "${rebootopts[@]}"
 | 
					[[ ! -v noreboot ]] && sudo systemctl reboot "${rebootopts[@]}"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user