2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								#!/bin/bash
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								set  -e
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-22 00:50:54 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								DIR = " $( cd  " $( dirname " $0 " ) "  &&  pwd ) " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								source  $DIR /common.sh
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-18 17:55:29 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								set  +o noglob
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-18 15:07:19 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								usage = $' Please set  hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for  hostname, because Harbor needs to be accessed by external clients.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Please set  --with-notary if  needs enable  Notary in Harbor, and set  ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https. 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-23 10:30:37 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Please set  --with-trivy if  needs enable  Trivy in Harbor
							 
						 
					
						
							
								
									
										
										
										
											2018-08-09 14:55:31 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Please set  --with-chartmuseum if  needs enable  Chartmuseum in Harbor' 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								item = 0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-09 19:02:44 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# notary is not enabled by default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								with_notary = $false 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-09 19:36:17 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# clair is deprecated 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								with_clair = $false 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-10 23:46:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# trivy is not enabled by default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								with_trivy = $false 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-19 16:47:05 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# chartmuseum is not enabled by default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								with_chartmuseum = $false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								while  [  $#  -gt 0  ] ;  do 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        case  $1  in
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            --help) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            note " $usage " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            exit  0; ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-09 19:02:44 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            --with-notary) 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-13 17:13:24 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            with_notary = true; ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-09 19:36:17 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            --with-clair) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            with_clair = true; ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-10 23:46:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            --with-trivy) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            with_trivy = true; ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            --with-chartmuseum) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            with_chartmuseum = true; ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								            *) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            note " $usage " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            exit  1; ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        esac 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        shift  ||  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								done 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-09 19:36:17 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  $with_clair  ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    error "Clair is deprecated please remove it from installation arguments !!!" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    exit  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								workdir = " $(  cd  " $(  dirname " ${ BASH_SOURCE [0] } "  ) "  &&  pwd  ) " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								cd  $workdir 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								h2 " [Step  $item ]: checking if docker is installed ... " ;  let  item += 1 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								check_docker
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								h2 " [Step  $item ]: checking docker-compose is installed ... " ;  let  item += 1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								check_dockercompose
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-05 11:22:30 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  -f harbor*.tar.gz ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    h2 " [Step  $item ]: loading Harbor images ... " ;  let  item += 1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    docker load -i ./harbor*.tar.gz
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								h2 " [Step  $item ]: preparing environment ... " ;   let  item += 1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								if  [  -n " $host "  ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    sed " s/^hostname: .*/hostname:  $host /g "  -i ./harbor.yml
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								h2 " [Step  $item ]: preparing harbor configs ... " ;   let  item += 1 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-13 17:13:24 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								prepare_para = 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-27 18:24:21 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  $with_notary  ]  
							 
						 
					
						
							
								
									
										
										
										
											2017-03-09 19:02:44 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    prepare_para = " ${ prepare_para }  --with-notary " 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-09 19:02:44 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-10 23:46:26 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  $with_trivy  ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    prepare_para = " ${ prepare_para }  --with-trivy " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-19 16:47:05 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  $with_chartmuseum  ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    prepare_para = " ${ prepare_para }  --with-chartmuseum " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-13 17:13:24 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								./prepare $prepare_para 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if  [  -n " $( docker-compose ps -q) "   ] 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								then 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    note "stopping existing Harbor instance ..."  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    docker-compose down -v
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								fi 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								echo  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								h2 " [Step  $item ]: starting Harbor ... " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								docker-compose up -d
							 
						 
					
						
							
								
									
										
										
										
											2016-10-19 14:32:00 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-23 14:08:15 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								success $"----Harbor has been installed and started successfully.----"