more reliable cleanup on exit
This commit is contained in:
		@@ -138,8 +138,7 @@ scan(){
 | 
				
			|||||||
		wait
 | 
							wait
 | 
				
			||||||
	done
 | 
						done
 | 
				
			||||||
	tac "$TMP_URLFILE" > "$URLFILE"
 | 
						tac "$TMP_URLFILE" > "$URLFILE"
 | 
				
			||||||
	rm "$TMP_URLFILE"
 | 
						cleanup
 | 
				
			||||||
	rm /tmp/threadwatcher.lock
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
prune(){
 | 
					prune(){
 | 
				
			||||||
@@ -150,12 +149,12 @@ prune(){
 | 
				
			|||||||
	done
 | 
						done
 | 
				
			||||||
	#Create lock file to stop override of URLFILE
 | 
						#Create lock file to stop override of URLFILE
 | 
				
			||||||
	touch /tmp/threadwatcher.lock
 | 
						touch /tmp/threadwatcher.lock
 | 
				
			||||||
	ping -q -c 1 4channel.org > /dev/null|| { echo "Cannot connect to 4chan."; exit 1;}
 | 
						ping -q -c 1 4channel.org > /dev/null|| { echo "Cannot connect to 4chan."; cleanup && exit 1;}
 | 
				
			||||||
	if [ "$(wc -l < "$URLFILE")" -gt 0 ]; then
 | 
						if [ "$(wc -l < "$URLFILE")" -gt 0 ]; then
 | 
				
			||||||
		echo "Pruning threads..."
 | 
							echo "Pruning threads..."
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		echo "No threads to prune."
 | 
							echo "No threads to prune."
 | 
				
			||||||
		exit
 | 
							cleanup && exit
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#tac used to prioritze newly added threads.
 | 
						#tac used to prioritze newly added threads.
 | 
				
			||||||
@@ -176,7 +175,7 @@ prune(){
 | 
				
			|||||||
				notify-send "threadwatcher" "Thread downloading to $(echo "$dl_location" | sed "s|$HOME|~|") is complete now."
 | 
									notify-send "threadwatcher" "Thread downloading to $(echo "$dl_location" | sed "s|$HOME|~|") is complete now."
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
				echo "Cannot connect to 4chan."
 | 
									echo "Cannot connect to 4chan."
 | 
				
			||||||
				exit 1
 | 
									cleanup && exit 1
 | 
				
			||||||
			fi
 | 
								fi
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
@@ -186,9 +185,7 @@ prune(){
 | 
				
			|||||||
		rm /tmp/content$$
 | 
							rm /tmp/content$$
 | 
				
			||||||
	done
 | 
						done
 | 
				
			||||||
	tac "$TMP_URLFILE" > "$URLFILE"
 | 
						tac "$TMP_URLFILE" > "$URLFILE"
 | 
				
			||||||
	rm "$TMP_URLFILE"
 | 
						cleanup
 | 
				
			||||||
	rm /tmp/threadwatcher.lock
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add() {
 | 
					add() {
 | 
				
			||||||
@@ -248,6 +245,11 @@ add() {
 | 
				
			|||||||
		fi
 | 
							fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cleanup(){
 | 
				
			||||||
 | 
						rm -f /tmp/threadwatcher.lock
 | 
				
			||||||
 | 
						rm -f "$TMP_URLFILE"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
case "$1" in
 | 
					case "$1" in
 | 
				
			||||||
	"add") 	add "$2" "$3"
 | 
						"add") 	add "$2" "$3"
 | 
				
			||||||
		scan;;
 | 
							scan;;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user