Set a main function
This commit is contained in:
		
							parent
							
								
									8376bd355e
								
							
						
					
					
						commit
						16e1324b2a
					
				
							
								
								
									
										42
									
								
								winboot
								
								
								
								
							
							
						
						
									
										42
									
								
								winboot
								
								
								
								
							|  | @ -1,31 +1,47 @@ | ||||||
| #!/bin/sh | #!/bin/sh | ||||||
| 
 | 
 | ||||||
| GRUB_DEFAULT_PATH='/etc/default/grub' | # This script set a specific grub entry (winLOOSE…) for the next boot. | ||||||
| GRUB_DEFAULT_DIR='/etc/default/grub.d' | # Then reboot the host | ||||||
| WIN_GRUB="2" |  | ||||||
| 
 | 
 | ||||||
| # First check in Grub default dir if saved mode is set | # Vars {{{ | ||||||
| if grep -q -E -R -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_DIR}" | readonly PROGNAME=$(basename "${0}") | ||||||
| then | readonly PROGDIR=$(readlink -m $(dirname "${0}")) | ||||||
|  | readonly ARGS="${*}" | ||||||
|  | readonly NBARGS="${#}" | ||||||
|  | 
 | ||||||
|  | readonly GRUB_DEFAULT_PATH='/etc/default/grub' | ||||||
|  | readonly GRUB_DEFAULT_DIR='/etc/default/grub.d' | ||||||
|  | readonly WIN_GRUB="2" | ||||||
|  | # }}} | ||||||
|  | 
 | ||||||
|  | main() {                                                        # {{{ | ||||||
|  | 
 | ||||||
|  | 	# First check in Grub default dir if saved mode is set | ||||||
|  | 	if grep -q -E -R -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_DIR}" | ||||||
|  | 	then | ||||||
| 		printf '%b' "Reboot to windaube partition\\n" | 		printf '%b' "Reboot to windaube partition\\n" | ||||||
| 		sudo grub-reboot "${WIN_GRUB}" | 		sudo grub-reboot "${WIN_GRUB}" | ||||||
| 		sudo systemctl reboot | 		sudo systemctl reboot | ||||||
| fi | 	fi | ||||||
| 
 | 
 | ||||||
| # Otherwise check the default grub file | 	# Otherwise check the default grub file | ||||||
| if grep -q -E -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_PATH}" | 	if grep -q -E -- "^GRUB_DEFAULT=saved" "${GRUB_DEFAULT_PATH}" | ||||||
| then | 	then | ||||||
| 		printf '%b' "Reboot to windaube partition\\n" | 		printf '%b' "Reboot to windaube partition\\n" | ||||||
| 		sudo grub-reboot "${WIN_GRUB}" | 		sudo grub-reboot "${WIN_GRUB}" | ||||||
| 		sudo systemctl reboot | 		sudo systemctl reboot | ||||||
| else | 	else | ||||||
| 
 | 
 | ||||||
| 		printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\\n" | 		printf '%b' "GRUB_DEFAULT is not set in 'saved' mode\\n" | ||||||
| 		sudo sed -i 's/\(^GRUB_DEFAULT.*\)/#\1\nGRUB_DEFAULT=saved/' "${GRUB_DEFAULT_PATH}" | 		sudo sed -i 's/\(^GRUB_DEFAULT.*\)/#\1\nGRUB_DEFAULT=saved/' "${GRUB_DEFAULT_PATH}" | ||||||
| 		GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2) | 		GRUB_DEFAULT_ENTRY=$(grep -E -- "#GRUB_DEFAULT=" "${GRUB_DEFAULT_PATH}" | cut -d"=" -f2) | ||||||
| 		sudo grub-set-default "${GRUB_DEFAULT_ENTRY}" | 		sudo grub-set-default "${GRUB_DEFAULT_ENTRY}" | ||||||
| 		sudo update-grub | 		sudo update-grub | ||||||
| 	printf '%b' "Please launch this script once again.\\n" | 		printf '%b' "Please launch this script (${PROGDIR}/${PROGNAME} ${ARGS}) once again.\\n" | ||||||
| fi | 	fi | ||||||
|  | } | ||||||
|  | # }}} | ||||||
|  | 
 | ||||||
|  | main | ||||||
| 
 | 
 | ||||||
| exit 0 | exit 0 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue