You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							50 lines
						
					
					
						
							1020 B
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							50 lines
						
					
					
						
							1020 B
						
					
					
				
								#!/bin/bash
							 | 
						|
								
							 | 
						|
								##
							 | 
						|
								# return 0 (true) if array (passed by name) contains element
							 | 
						|
								# usage:
							 | 
						|
								#   ARRAY=( a b c )
							 | 
						|
								#   containsElement ARRAY 'a' => 0
							 | 
						|
								function containsElement {
							 | 
						|
								  isArray "$1" || (echo >&2 "ERROR: <$1> not an array!" && return 2)
							 | 
						|
								  array_inter="$1[@]"
							 | 
						|
								  array=("${!array_inter}")
							 | 
						|
								  for i in "${array[@]}"; do [[ "$i" == "$2" ]] && return 0; done
							 | 
						|
								  return 1
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								## return 0 (true) if arg1 (passed by name) is an array
							 | 
						|
								function isArray {
							 | 
						|
								  [[ "$(declare -p "$1" 2>/dev/null)" =~ "declare -a" ]] || return 1
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								function isDebian {
							 | 
						|
								  grep ^ID=debian /etc/os-release
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								function isArch {
							 | 
						|
								  grep ^ID=arch /etc/os-release
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								function os-release {
							 | 
						|
								  grep ^ID= /etc/os-release | cut -d '=' -f2
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								function askConfirmation {
							 | 
						|
								  case "$1" in
							 | 
						|
								  y | Y | yes | YES)
							 | 
						|
								    QUESTION="(Y/n)?"
							 | 
						|
								    DEFAULT=0
							 | 
						|
								    ;;
							 | 
						|
								  *)
							 | 
						|
								    QUESTION="(y/N)?"
							 | 
						|
								    DEFAULT=1
							 | 
						|
								    ;;
							 | 
						|
								  esac
							 | 
						|
								  read -rp "$QUESTION : " choice
							 | 
						|
								  case "$choice" in
							 | 
						|
								  y | Y | yes | YES) return 0 ;; #true
							 | 
						|
								  n | no | N | NO) return 1 ;;   #false
							 | 
						|
								  *) return $DEFAULT ;;
							 | 
						|
								  esac
							 | 
						|
								}
							 |