`sudo -S` reads the password from stdin. The way it was it was executing the deploy script with the password as the stdin of the pipe. Now, when password is passed as an argument we aquire a sudo session executing a command that always work and then prefixing the installation with sudo.
		
			
				
	
	
		
			39 lines
		
	
	
		
			748 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			748 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/bash -e
 | 
						|
 | 
						|
[[ "$1" == "--sudo" ]] && prefix="sudo " && shift
 | 
						|
[[ "$1" == "--password" ]] && shift && prefix="echo \"$1\" | sudo -S true && sudo " && shift
 | 
						|
 | 
						|
target=$1
 | 
						|
[ "$target" ] || echo "Please, provide an ssh target"
 | 
						|
shift
 | 
						|
 | 
						|
[ "$DEBUG" ] && debug="-x"
 | 
						|
 | 
						|
kickstart compile "$@"
 | 
						|
 | 
						|
copy_command=$(
 | 
						|
cat <<CMD
 | 
						|
{
 | 
						|
  deploy_folder=\$(mktemp -d -t kickstart.XXXXX)
 | 
						|
  mkdir -p "\$deploy_folder"
 | 
						|
  cd "\$deploy_folder"
 | 
						|
  tar xz
 | 
						|
  echo "\$deploy_folder"
 | 
						|
}
 | 
						|
CMD
 | 
						|
)
 | 
						|
deploy_folder=$(tar chz -C compile . | ssh $target "bash -c '$copy_command'")
 | 
						|
 | 
						|
execute_command=$(
 | 
						|
cat <<CMD
 | 
						|
{
 | 
						|
  cd $deploy_folder
 | 
						|
  exit_status=0
 | 
						|
  $prefix bash $debug install.sh || exit_status=\$?
 | 
						|
  rm -rf "$deploy_folder"
 | 
						|
  exit \$exit_status
 | 
						|
}
 | 
						|
CMD
 | 
						|
)
 | 
						|
ssh $target "bash -c '$execute_command'"
 |