5656 def usage
5757 print <<EOF
5858
59- install [--sanity-check] [--proxy http://hostname:port] <package-type>
59+ update [--sanity-check] [--proxy http://hostname:port] [--upgrade|--downgrade ] <package-type>
6060 --sanity-check [optional]
6161 --proxy [optional]
62+ --upgrade | --downgrade [optional]
6263 package-type: #{ VALID_TYPES . to_a . join ( ', ' ) } , or auto
6364
6465Installs fetches the latest package version of the specified type and
@@ -80,6 +81,12 @@ to check for a running agent.
8081To use a HTTP proxy, specify --proxy followed by the proxy server
8182defined by http://hostname:port
8283
84+ If --upgrade is specified, the script will only update the agent if a newer version is available.
85+ Downgrades will not be respected.
86+
87+ If --downgrade is specified, the script will only update the agent if an older version of the
88+ agent is marked as current. Upgrades will be ignored.
89+
8390This install script needs Ruby version 2.x installed as a prerequisite.
8491Currently recommanded Ruby versions are 2.0.0, 2.1.8, 2.2.4 and 2.3.0, and 2.4.0.
8592If multiple Ruby versions are installed, the default ruby version will be used.
138145 @sanity_check = false
139146 @reexeced = false
140147 @http_proxy = nil
148+ @downgrade = false
149+ @upgrade = false
141150
142151 @args = Array . new ( ARGV )
143- opts = GetoptLong . new ( [ '--sanity-check' , GetoptLong ::NO_ARGUMENT ] , [ '--help' , GetoptLong ::NO_ARGUMENT ] , [ '--re-execed' , GetoptLong ::NO_ARGUMENT ] , [ '--proxy' , GetoptLong ::OPTIONAL_ARGUMENT ] )
152+ opts = GetoptLong . new ( [ '--sanity-check' , GetoptLong ::NO_ARGUMENT ] , [ '--help' , GetoptLong ::NO_ARGUMENT ] ,
153+ [ '--re-execed' , GetoptLong ::NO_ARGUMENT ] , [ '--proxy' , GetoptLong ::OPTIONAL_ARGUMENT ] ,
154+ [ '--downgrade' , GetoptLong ::NO_ARGUMENT ] , [ '--upgrade' , GetoptLong ::NO_ARGUMENT ] )
144155 opts . each do |opt , args |
145156 case opt
146157 when '--sanity-check'
@@ -149,12 +160,28 @@ EOF
149160 usage
150161 when '--re-execed'
151162 @reexeced = true
163+ when '--downgrade'
164+ @downgrade = true
165+ when '--upgrade'
166+ @upgrade = true
152167 when '--proxy'
153168 if ( args != '' )
154169 @http_proxy = args
155170 end
156171 end
157172 end
173+
174+ if ( @upgrade and @downgrade )
175+ usage
176+ @log . error ( 'Cannot provide both --upgrade and --downgrade' )
177+ exit ( 1 )
178+ elsif ( !@upgrade and !@downgrade )
179+ #Default to allowing both if one if neither is specified
180+ @upgrade = true
181+ @downgrade = true
182+ end
183+
184+
158185 if ( ARGV . length < 1 )
159186 usage
160187 @log . error ( 'Expected package type as argument.' )
532559 @log . info ( "Running version, #{ running_version } , matches target version, #{ target_version } , skipping install" )
533560 else
534561 if upgrade_or_install_required? ( target_version , running_version )
535- @log . info ( "Running version, #{ running_version } , less than target version, #{ target_version } , updating agent" )
562+ if @upgrade
563+ @log . info ( "Running version, #{ running_version } , less than target version, #{ target_version } , updating agent" )
564+ else
565+ @log . info ( "New version available but only checking for downgrades. Skipping install." )
566+ exit 0 ;
567+ end
536568 else
537- @log . info ( "Running version, #{ running_version } , greater than target version, #{ target_version } , rolling back agent" )
569+ if @downgrade
570+ @log . info ( "Running version, #{ running_version } , greater than target version, #{ target_version } , rolling back agent" )
571+ else
572+ @log . info ( "Older version available but only checking for upgrades. Skipping install." )
573+ exit 0 ;
574+ end
538575 end
539576
540577 pre_installation_steps ( @type , running_version )
0 commit comments