A push over script that doesn't hardcode tokens.
This commit is contained in:
		
							parent
							
								
									f167ebb4a1
								
							
						
					
					
						commit
						5f28729298
					
				
							
								
								
									
										44
									
								
								zsh/modules/bin/tellme
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										44
									
								
								zsh/modules/bin/tellme
									
									
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,44 @@
 | 
				
			||||||
 | 
					#! /bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Load config file if it exist.
 | 
				
			||||||
 | 
					export CONFIG=${XDG_CONFIG_HOME:-~/.config}/tellme/creds
 | 
				
			||||||
 | 
					[ -f $CONFIG ] && export $(grep -v '^#' $CONFIG | xargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					usage(){
 | 
				
			||||||
 | 
					  echo "You have to tell me something"
 | 
				
			||||||
 | 
					  exit -1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					setup(){
 | 
				
			||||||
 | 
					  echo "It doesn't look like I've been setup yet. I will need the Application & User tokens."
 | 
				
			||||||
 | 
					  read -r -p "  Application Token: " APPLICATION_TOKEN
 | 
				
			||||||
 | 
					  read -r -p "  User Token: " USER_TOKEN
 | 
				
			||||||
 | 
					  mkdir -p $(dirname $CONFIG)
 | 
				
			||||||
 | 
					  cat <<-EOF > $CONFIG
 | 
				
			||||||
 | 
						application_token=$APPLICATION_TOKEN
 | 
				
			||||||
 | 
						user_token=$USER_TOKEN
 | 
				
			||||||
 | 
						EOF
 | 
				
			||||||
 | 
					  chmod 600 $CONFIG
 | 
				
			||||||
 | 
					  echo "Config setup at $CONFIG"
 | 
				
			||||||
 | 
					  echo
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ -z $application_token || -z $user_token ]] ; then
 | 
				
			||||||
 | 
					  setup
 | 
				
			||||||
 | 
					  export $(grep -v '^#' $CONFIG | xargs)
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ $# -eq 0 ]] ; then
 | 
				
			||||||
 | 
					  usage
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					message=$@
 | 
				
			||||||
 | 
					curl -s \
 | 
				
			||||||
 | 
					  --form-string "token=$application_token" \
 | 
				
			||||||
 | 
					  --form-string  "user=$user_token" \
 | 
				
			||||||
 | 
					  --form-string  "message=$message" \
 | 
				
			||||||
 | 
					  https://api.pushover.net/1/messages.json 1>/dev/null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[ $? -eq 0 ]] && echo "message sent" || echo "ERROR SENDING NOTIFICATION"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					printf '\a' #Rings bell
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user