| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | #!/usr/bin/bash | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | TEXT_STATUS=${TEXT_STATUS:=/media/shared/status} | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | CONFIG=${CONFIG:=/etc/pve/nodes/pve/config} | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | # NOTE: since proxmox monitors files, it is better modify the file in  | 
					
						
							|  |  |  | #		one go but since checking can not be done in an instant we write  | 
					
						
							|  |  |  | #		the check results to $TMP_RESULTS and when done will swap it with | 
					
						
							|  |  |  | #		$CONFIG... | 
					
						
							|  |  |  | # XXX move this to /tmp??? | 
					
						
							|  |  |  | TMP_RESULTS=${TMP_RESULTS:=${CONFIG}.live} | 
					
						
							| 
									
										
										
										
											2023-06-27 12:52:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-30 16:26:13 +03:00
										 |  |  | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | source .pct-helpers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2023-06-27 13:00:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | DATE=`date +'%Y-%m-%d %H:%M'`  | 
					
						
							| 
									
										
										
										
											2023-06-27 13:00:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | if [ -e $TMP_RESULTS ] ; then | 
					
						
							|  |  |  | 	rm -f $TMP_RESULTS | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | if [ -e $TEXT_STATUS ] ; then | 
					
						
							|  |  |  | 	mv -f $TEXT_STATUS{,.old} | 
					
						
							|  |  |  | 	echo $DATE > $TEXT_STATUS | 
					
						
							| 
									
										
										
										
											2023-06-27 12:52:27 +03:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | 	TEXT_STATUS=/dev/null | 
					
						
							| 
									
										
										
										
											2023-06-27 12:52:27 +03:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | # read the sites from the status section in $CONFIG... | 
					
						
							| 
									
										
										
										
											2023-06-30 16:26:13 +03:00
										 |  |  | readarray -t lines <<<$(\ | 
					
						
							|  |  |  | 	sed -n '/STATUS BEGIN/,/STATUS END/p' "$CONFIG" \ | 
					
						
							|  |  |  | 		| sed \ | 
					
						
							|  |  |  | 			-e '1d;$d' \ | 
					
						
							|  |  |  | 			-e 's/^#//' \ | 
					
						
							|  |  |  | 			-e 's/%3A/:/g' \ | 
					
						
							|  |  |  | 			-e 's/ : \(OK\|**ERROR\).*//') | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | # fill the status section -> $TMP_RESULTS... | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | cp -f "$CONFIG" "$CONFIG".bak | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	echo '#<!-- STATUS BEGIN -->' | 
					
						
							| 
									
										
										
										
											2023-06-30 16:26:13 +03:00
										 |  |  | 	for line in "${lines[@]}" ; do | 
					
						
							|  |  |  | 		# empty lines... | 
					
						
							|  |  |  | 		if [[ "$line" =~ ^[[:space:]]*$ ]] ; then | 
					
						
							|  |  |  | 			echo "#" | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		# skip check date... | 
					
						
							|  |  |  | 		elif [[ "$line" =~ ^_\(checked[[:blank:]]on:[[:blank:]].*\)_$ ]] ; then | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		./check-status "$line" \ | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | 			| tee -a $TEXT_STATUS \ | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 			| sed \ | 
					
						
							| 
									
										
										
										
											2023-07-14 20:29:07 +03:00
										 |  |  | 				-e 's/^\(.*\)\(ERROR.*$\)/\1**\2**/' \ | 
					
						
							| 
									
										
										
										
											2023-06-30 16:26:13 +03:00
										 |  |  | 				-e 's/^/#/' | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 	done | 
					
						
							| 
									
										
										
										
											2023-06-27 13:00:42 +03:00
										 |  |  | 	echo "#_(checked on: ${DATE})_" | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 	echo '#<!-- STATUS END -->' | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | } \ | 
					
						
							|  |  |  | 	| fillsection -r STATUS ${CONFIG} \ | 
					
						
							|  |  |  | 	> "$TMP_RESULTS" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-28 14:22:55 +03:00
										 |  |  | # replace $TMP_RESULTS -> $CONFIG | 
					
						
							|  |  |  | if [ -e $TMP_RESULTS ] ; then | 
					
						
							|  |  |  | 	mv -f "$TMP_RESULTS" "$CONFIG" | 
					
						
							| 
									
										
										
										
											2023-06-26 21:53:39 +03:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # vim:set ts=4 sw=4 nowrap : |