PackageChanger 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/PackageChanger.gemspec +44 -0
- data/README.md +26 -0
- data/Rakefile +10 -0
- data/bin/PackageChanger +151 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/data/packagechanger.conf.example +20 -0
- data/lib/PackageChanger.rb +5 -0
- data/lib/PackageChanger/config.rb +90 -0
- data/lib/PackageChanger/connection.rb +63 -0
- data/lib/PackageChanger/foundation.rb +6 -0
- data/lib/PackageChanger/log.rb +28 -0
- data/lib/PackageChanger/messages.rb +51 -0
- data/lib/PackageChanger/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2d2f7c832e92ce661bdfb8c674cd225389617b1c
|
|
4
|
+
data.tar.gz: 872b1ef82b5972f97dd065ce4d77e37e381c6000
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fb1e68e7399a25358ad683503f7a310e4722007ed076ca053bc3d152bf5a75dc6069262d6e45f0a053fd4c37b2f9526b8d318c70771c4f9acf6cce453a7b2d0a
|
|
7
|
+
data.tar.gz: f4cec6c57c452d4534e98de28c7aa01a245f421f5d92076ff247a3c0bc7974faf2fb5e293551557ca2af3c9adca705f7b7de205b52f125a7e5cdb34b1689d45b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 bprieto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "PackageChanger/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "PackageChanger"
|
|
8
|
+
spec.version = PackageChanger::VERSION
|
|
9
|
+
spec.authors = ["Bernardo Prieto"]
|
|
10
|
+
spec.email = ["bernardo.prieto.curiel@zalando.de"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Uses the API to list or replace a package in all JSS policies in which it appears.}
|
|
13
|
+
spec.description = %q{With the help or Ruby JSS, uses the API to list all the policies in which a package appears
|
|
14
|
+
and gives the ability to replace the package in all these policies.}
|
|
15
|
+
spec.homepage = "https://github.com/Bearzooka/PackageChanger"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
20
|
+
if spec.respond_to?(:metadata)
|
|
21
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
|
22
|
+
|
|
23
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
24
|
+
spec.metadata["source_code_uri"] = "https://github.com/Bearzooka/PackageChanger"
|
|
25
|
+
else
|
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
27
|
+
"public gem pushes."
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
34
|
+
end
|
|
35
|
+
spec.bindir = "exe"
|
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
37
|
+
spec.require_paths = ["lib"]
|
|
38
|
+
|
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
41
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
42
|
+
spec.add_development_dependency 'ruby-jss', '~> 1.0', '>= 1.0.2'
|
|
43
|
+
spec.add_runtime_dependency 'ruby-jss', '~> 1.0', '>= 1.0.2'
|
|
44
|
+
end
|
data/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# PackageChanger
|
|
2
|
+
|
|
3
|
+
Using Ruby-JSS to work with the JSS API, PackageChange lists the policies in which a package is used and gives the ability to change this package for a new one.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
$ gem install PackageChanger
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Once installed, create a configuration file in /etc/packagechanger.conf
|
|
12
|
+
|
|
13
|
+
You can copy a sample file from the data folder inside the installation path of *PackageChanger* and fill the JSS URL, User and Password.
|
|
14
|
+
|
|
15
|
+
Once configured, you can use it:
|
|
16
|
+
|
|
17
|
+
```packagechanger [--silent] --old OldPackageName --new NewPackageName || --list ListedPackage```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Bearzooka/PackageChanger.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/PackageChanger
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'getoptlong'
|
|
6
|
+
require_relative '../lib/PackageChanger/config'
|
|
7
|
+
require_relative '../lib/PackageChanger/connection'
|
|
8
|
+
require_relative '../lib/PackageChanger/messages'
|
|
9
|
+
require_relative '../lib/PackageChanger/log'
|
|
10
|
+
|
|
11
|
+
old_package = nil
|
|
12
|
+
new_package = nil
|
|
13
|
+
list_package = nil
|
|
14
|
+
mode = nil
|
|
15
|
+
result_array = []
|
|
16
|
+
silent = false
|
|
17
|
+
|
|
18
|
+
# The CLI options for GetoptLong
|
|
19
|
+
OPTS = GetoptLong.new(
|
|
20
|
+
['--old', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
|
21
|
+
['--new', '-n', GetoptLong::REQUIRED_ARGUMENT],
|
|
22
|
+
['--list', '-l', GetoptLong::REQUIRED_ARGUMENT],
|
|
23
|
+
['--silent', '-s', GetoptLong::NO_ARGUMENT]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
logger = PackageChanger::Log.new
|
|
27
|
+
|
|
28
|
+
OPTS.each do |opt, arg|
|
|
29
|
+
case opt
|
|
30
|
+
when '--old'
|
|
31
|
+
if arg == ''
|
|
32
|
+
puts PackageChanger::USAGE
|
|
33
|
+
logger.write('Missing arguments.')
|
|
34
|
+
exit 1
|
|
35
|
+
else
|
|
36
|
+
old_package = arg
|
|
37
|
+
mode = 'change'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
when '--new'
|
|
41
|
+
if arg == ''
|
|
42
|
+
puts PackageChanger::USAGE
|
|
43
|
+
logger.write('Missing arguments.')
|
|
44
|
+
exit 1
|
|
45
|
+
else
|
|
46
|
+
new_package = arg
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
when '--list'
|
|
50
|
+
if arg == ''
|
|
51
|
+
puts PackageChanger::USAGE
|
|
52
|
+
logger.write('Missing arguments.')
|
|
53
|
+
exit 1
|
|
54
|
+
else
|
|
55
|
+
list_package = arg
|
|
56
|
+
mode = "list"
|
|
57
|
+
end
|
|
58
|
+
when '--silent'
|
|
59
|
+
silent = true
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
unless (old_package and new_package) or list_package
|
|
65
|
+
puts PackageChanger::USAGE
|
|
66
|
+
logger.write('Missing package names')
|
|
67
|
+
exit 1
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
begin
|
|
71
|
+
|
|
72
|
+
if PackageChanger::Configuration::DEFAULT_CONF_FILE.file?
|
|
73
|
+
@config_src = PackageChanger::Configuration::DEFAULT_CONF_FILE.to_s
|
|
74
|
+
elsif PackageChanger::Configuration::SAMPLE_CONF_FILE.file?
|
|
75
|
+
puts PackageChanger::CONFIG_ERROR
|
|
76
|
+
logger.write('Missing configuration file.')
|
|
77
|
+
exit 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
PackageChanger.connect_to_jss
|
|
81
|
+
|
|
82
|
+
if mode == 'list'
|
|
83
|
+
unless JSS::Package.valid_id list_package
|
|
84
|
+
logger.write("#{list_package} does not exist")
|
|
85
|
+
puts PackageChanger::MISSSING_LIST_PACKAGE
|
|
86
|
+
exit 1
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
result_array = PackageChanger.get_policies_with(list_package, silent)
|
|
90
|
+
|
|
91
|
+
if result_array.count > 0
|
|
92
|
+
puts "The package #{list_package} is used on the following policies: "
|
|
93
|
+
result_array.each do |result|
|
|
94
|
+
puts "\t#{result[:id]} - #{result[:name]}"
|
|
95
|
+
end
|
|
96
|
+
else
|
|
97
|
+
puts PackageChanger::NO_RESULTS_LIST
|
|
98
|
+
exit 0
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
elsif mode == "change"
|
|
102
|
+
unless JSS::Package.valid_id old_package and JSS::Package.valid_id new_package
|
|
103
|
+
logger.write("Either #{old_package} or #{new_package} do not exist")
|
|
104
|
+
puts PackageChanger::MISSSING_PACKAGE
|
|
105
|
+
exit 1
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
result_array = PackageChanger.get_policies_with(old_package, silent)
|
|
109
|
+
|
|
110
|
+
if result_array.count > 0
|
|
111
|
+
puts "The package #{old_package} will be replaced with #{new_package}: "
|
|
112
|
+
logger.write("The package #{old_package} will be replaced with #{new_package}")
|
|
113
|
+
result_array.each do |result|
|
|
114
|
+
puts "\t#{result[:id]} - #{result[:name]}"
|
|
115
|
+
logger.write("\t#{result[:id]} - #{result[:name]}")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
confirmation = ''
|
|
119
|
+
|
|
120
|
+
while confirmation !~ (/[yn]/i)
|
|
121
|
+
puts 'Please confirm [y/n]:'
|
|
122
|
+
confirmation = gets.chomp.downcase
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
case confirmation
|
|
126
|
+
when 'y'
|
|
127
|
+
puts 'Processing changes.' unless silent
|
|
128
|
+
logger.write('Starting changes.')
|
|
129
|
+
PackageChanger.replace_packages(result_array, old_package, new_package, silent, logger)
|
|
130
|
+
puts 'Finished changing packages.' unless silent
|
|
131
|
+
logger.write('Finished changing.')
|
|
132
|
+
exit 0
|
|
133
|
+
when 'n'
|
|
134
|
+
puts 'Cancelling changes.'
|
|
135
|
+
logger.write('User cancelled.')
|
|
136
|
+
exit 0
|
|
137
|
+
else
|
|
138
|
+
puts PackageChanger::ERROR
|
|
139
|
+
logger.write(PackageChanger::ERROR)
|
|
140
|
+
exit 1
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
else
|
|
144
|
+
puts PackageChanger::NO_RESULTS_CHANGE
|
|
145
|
+
logger.write(PackageChanger::NO_RESULTS_CHANGE)
|
|
146
|
+
exit 0
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "PackageChanger"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#################
|
|
2
|
+
# This config file uses default settings.
|
|
3
|
+
#
|
|
4
|
+
# Each setting is defined on one line like so:
|
|
5
|
+
#
|
|
6
|
+
# key: value
|
|
7
|
+
#
|
|
8
|
+
# Values may have spaces.
|
|
9
|
+
#
|
|
10
|
+
# Blank lines and those starting with # are ignored.
|
|
11
|
+
|
|
12
|
+
jamf_server:
|
|
13
|
+
|
|
14
|
+
jamf_port:
|
|
15
|
+
|
|
16
|
+
jamf_use_ssl:
|
|
17
|
+
|
|
18
|
+
jamf_user:
|
|
19
|
+
|
|
20
|
+
jamf_password:
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
require 'singleton'
|
|
3
|
+
require 'pathname'
|
|
4
|
+
|
|
5
|
+
module PackageChanger
|
|
6
|
+
|
|
7
|
+
silent = false
|
|
8
|
+
|
|
9
|
+
class Configuration
|
|
10
|
+
include ::Singleton
|
|
11
|
+
|
|
12
|
+
# The location of the default config file
|
|
13
|
+
DEFAULT_CONF_FILE = Pathname.new '/etc/packagechanger.conf'
|
|
14
|
+
|
|
15
|
+
SAMPLE_CONF_FILE = Pathname.new(__FILE__).parent.parent.parent + 'data/packagechanger.conf.example'
|
|
16
|
+
|
|
17
|
+
CONF_KEYS = {
|
|
18
|
+
jamf_server: nil,
|
|
19
|
+
jamf_port: :to_i,
|
|
20
|
+
jamf_use_ssl: nil,
|
|
21
|
+
jamf_user: nil,
|
|
22
|
+
jamf_password: nil
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
# automatically create accessors for all the CONF_KEYS
|
|
26
|
+
CONF_KEYS.keys.each { |k| attr_accessor k }
|
|
27
|
+
|
|
28
|
+
# Initialize!
|
|
29
|
+
#
|
|
30
|
+
def initialize
|
|
31
|
+
read_global
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def read_global
|
|
35
|
+
return false unless DEFAULT_CONF_FILE.file? && DEFAULT_CONF_FILE.readable?
|
|
36
|
+
|
|
37
|
+
read DEFAULT_CONF_FILE
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def print
|
|
41
|
+
CONF_KEYS.keys.sort.each { |k| puts "#{k}: #{send k}" }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def read(file)
|
|
47
|
+
available_conf_keys = CONF_KEYS.keys
|
|
48
|
+
|
|
49
|
+
puts file
|
|
50
|
+
Pathname.new(file).read.each_line do |line|
|
|
51
|
+
# skip blank lines and those starting with #
|
|
52
|
+
next if line =~ /^\s*(#|$)/
|
|
53
|
+
|
|
54
|
+
line.strip =~ /^(\w+?):\s*(\S.*)$/
|
|
55
|
+
key = Regexp.last_match(1)
|
|
56
|
+
next unless key
|
|
57
|
+
|
|
58
|
+
attr = key.to_sym
|
|
59
|
+
next unless available_conf_keys.include? attr
|
|
60
|
+
|
|
61
|
+
setter = "#{key}=".to_sym
|
|
62
|
+
value = Regexp.last_match(2).strip
|
|
63
|
+
|
|
64
|
+
# convert the string value read from the file
|
|
65
|
+
# to the correct class
|
|
66
|
+
value &&= case CONF_KEYS[attr]
|
|
67
|
+
when Proc
|
|
68
|
+
# If its a proc, pass it to the proc
|
|
69
|
+
CONF_KEYS[attr].call value
|
|
70
|
+
|
|
71
|
+
when Symbol
|
|
72
|
+
# otherwise its a symbol method name to call on the string
|
|
73
|
+
value.send(CONF_KEYS[attr])
|
|
74
|
+
|
|
75
|
+
else
|
|
76
|
+
value
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
send(setter, value)
|
|
81
|
+
end # do line
|
|
82
|
+
true
|
|
83
|
+
end # read file
|
|
84
|
+
end # class Configuration
|
|
85
|
+
|
|
86
|
+
# The single instance of Configuration
|
|
87
|
+
def self.config
|
|
88
|
+
PackageChanger::Configuration.instance
|
|
89
|
+
end
|
|
90
|
+
end # module
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'ruby-jss'
|
|
2
|
+
require_relative 'config'
|
|
3
|
+
|
|
4
|
+
module PackageChanger
|
|
5
|
+
|
|
6
|
+
def self.connect_to_jss
|
|
7
|
+
# JSS Connection info
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
JSS.api.connect user: PackageChanger.config.jamf_user,
|
|
11
|
+
pw: PackageChanger.config.jamf_password,
|
|
12
|
+
server: PackageChanger.config.jamf_server,
|
|
13
|
+
verify_cert: false
|
|
14
|
+
|
|
15
|
+
puts 'Connected to the JSS.'
|
|
16
|
+
rescue
|
|
17
|
+
puts 'Could not connect to JSS. Please check the configuration.'
|
|
18
|
+
# abort
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.replace_packages(policies, old_package, new_package, silent, logger)
|
|
23
|
+
puts 'Starting replacement process' unless silent
|
|
24
|
+
|
|
25
|
+
policies.each do |policy|
|
|
26
|
+
puts "Changing #{policy[:name]}" unless silent
|
|
27
|
+
logger.write("Changing #{policy[:name]}")
|
|
28
|
+
begin
|
|
29
|
+
changed_pol = JSS::Policy.fetch :id => policy[:id]
|
|
30
|
+
changed_pol.remove_package(old_package)
|
|
31
|
+
changed_pol.add_package(new_package)
|
|
32
|
+
changed_pol.update
|
|
33
|
+
rescue StandardError => e
|
|
34
|
+
puts "Changed failed due to error: #{e.message}"
|
|
35
|
+
logger.write("Changed on #{policy} failed due to error: #{e.message}")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.get_policies_with(list_package, silent)
|
|
41
|
+
result_array = []
|
|
42
|
+
all_policies = JSS::Policy.all.select { |p|
|
|
43
|
+
!(p[:name].include? '[SelfService]') &&
|
|
44
|
+
!(p[:name].include? '1 Computer')
|
|
45
|
+
}
|
|
46
|
+
puts "There are #{all_policies.count} policies in your JSS…" unless silent
|
|
47
|
+
pol_count = 1
|
|
48
|
+
all_policies.each do |policy|
|
|
49
|
+
puts "\r#{pol_count} policies checked" unless silent
|
|
50
|
+
one_result = {}
|
|
51
|
+
fetched_policy = JSS::Policy.fetch(:id => policy[:id])
|
|
52
|
+
if fetched_policy.packages.any? {|package| package[:name] == list_package}
|
|
53
|
+
one_result[:id] = fetched_policy.id
|
|
54
|
+
one_result[:name] = fetched_policy.name
|
|
55
|
+
result_array.push(one_result)
|
|
56
|
+
end
|
|
57
|
+
#end
|
|
58
|
+
pol_count += 1
|
|
59
|
+
end
|
|
60
|
+
return result_array
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end # PackageChanger
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
module PackageChanger
|
|
3
|
+
|
|
4
|
+
class Log
|
|
5
|
+
|
|
6
|
+
DEFAULT_FILE = Pathname.new '/var/log/packagechanger.log'
|
|
7
|
+
|
|
8
|
+
# date and line format
|
|
9
|
+
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
unless DEFAULT_FILE.file? && DEFAULT_FILE.writable?
|
|
13
|
+
File.write(DEFAULT_FILE, "≈≈≈ PackageChanger ≈≈≈\n", mode: 'a')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def write(message)
|
|
18
|
+
File.write(DEFAULT_FILE, "#{Time.now.strftime(DATE_FORMAT)} - #{message}\n", mode: 'a')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def putsandlog(message)
|
|
22
|
+
puts message
|
|
23
|
+
write message
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end # Class Log
|
|
27
|
+
|
|
28
|
+
end # MOdule
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PackageChanger
|
|
4
|
+
USAGE = "
|
|
5
|
+
|
|
6
|
+
≈≈≈ PackageChanger ≈≈≈
|
|
7
|
+
|
|
8
|
+
Usage: packagechanger [--silent] --old OldPackageName --new NewPackageName || --list ListedPackage
|
|
9
|
+
"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
CONFIG_ERROR = "
|
|
13
|
+
|
|
14
|
+
≈≈≈ PackageChanger ≈≈≈
|
|
15
|
+
|
|
16
|
+
[ERROR] The configuration file is missing in /etc/packagechanger.conf
|
|
17
|
+
|
|
18
|
+
You can copy a sample file from the data folder inside the installation path of PackageChanger and
|
|
19
|
+
fill the JSS URL, User and Password.
|
|
20
|
+
|
|
21
|
+
"
|
|
22
|
+
|
|
23
|
+
MISSSING_PACKAGE = "
|
|
24
|
+
|
|
25
|
+
≈≈≈ PackageChanger ≈≈≈
|
|
26
|
+
|
|
27
|
+
Missing packages: One or both of the provided packages do not exist. Please verify.
|
|
28
|
+
"
|
|
29
|
+
|
|
30
|
+
MISSSING_LIST_PACKAGE = "
|
|
31
|
+
|
|
32
|
+
≈≈≈ PackageChanger ≈≈≈
|
|
33
|
+
|
|
34
|
+
Missing package: The provided package does not exist. Please verify.
|
|
35
|
+
"
|
|
36
|
+
|
|
37
|
+
NO_RESULTS_LIST = "
|
|
38
|
+
|
|
39
|
+
There are no policies using the provided package.
|
|
40
|
+
"
|
|
41
|
+
|
|
42
|
+
NO_RESULTS_CHANGE = "
|
|
43
|
+
|
|
44
|
+
There are no policies using the package you intend to change.
|
|
45
|
+
"
|
|
46
|
+
|
|
47
|
+
ERROR = "
|
|
48
|
+
|
|
49
|
+
Execution error.
|
|
50
|
+
"
|
|
51
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: PackageChanger
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bernardo Prieto
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: ruby-jss
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.0'
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: 1.0.2
|
|
65
|
+
type: :development
|
|
66
|
+
prerelease: false
|
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - "~>"
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '1.0'
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 1.0.2
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: ruby-jss
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.0'
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: 1.0.2
|
|
85
|
+
type: :runtime
|
|
86
|
+
prerelease: false
|
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - "~>"
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: '1.0'
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: 1.0.2
|
|
95
|
+
description: |-
|
|
96
|
+
With the help or Ruby JSS, uses the API to list all the policies in which a package appears
|
|
97
|
+
and gives the ability to replace the package in all these policies.
|
|
98
|
+
email:
|
|
99
|
+
- bernardo.prieto.curiel@zalando.de
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".DS_Store"
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".idea/.rakeTasks"
|
|
107
|
+
- ".idea/PackageChanger.iml"
|
|
108
|
+
- ".idea/misc.xml"
|
|
109
|
+
- ".idea/modules.xml"
|
|
110
|
+
- ".idea/vcs.xml"
|
|
111
|
+
- ".idea/workspace.xml"
|
|
112
|
+
- ".travis.yml"
|
|
113
|
+
- Gemfile
|
|
114
|
+
- LICENSE.txt
|
|
115
|
+
- PackageChanger.gemspec
|
|
116
|
+
- README.md
|
|
117
|
+
- Rakefile
|
|
118
|
+
- bin/PackageChanger
|
|
119
|
+
- bin/console
|
|
120
|
+
- bin/setup
|
|
121
|
+
- data/packagechanger.conf.example
|
|
122
|
+
- lib/.DS_Store
|
|
123
|
+
- lib/PackageChanger.rb
|
|
124
|
+
- lib/PackageChanger/config.rb
|
|
125
|
+
- lib/PackageChanger/connection.rb
|
|
126
|
+
- lib/PackageChanger/foundation.rb
|
|
127
|
+
- lib/PackageChanger/log.rb
|
|
128
|
+
- lib/PackageChanger/messages.rb
|
|
129
|
+
- lib/PackageChanger/version.rb
|
|
130
|
+
homepage: https://github.com/Bearzooka/PackageChanger
|
|
131
|
+
licenses:
|
|
132
|
+
- MIT
|
|
133
|
+
metadata:
|
|
134
|
+
allowed_push_host: https://rubygems.org/
|
|
135
|
+
homepage_uri: https://github.com/Bearzooka/PackageChanger
|
|
136
|
+
source_code_uri: https://github.com/Bearzooka/PackageChanger
|
|
137
|
+
post_install_message:
|
|
138
|
+
rdoc_options: []
|
|
139
|
+
require_paths:
|
|
140
|
+
- lib
|
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
|
+
requirements:
|
|
148
|
+
- - ">="
|
|
149
|
+
- !ruby/object:Gem::Version
|
|
150
|
+
version: '0'
|
|
151
|
+
requirements: []
|
|
152
|
+
rubyforge_project:
|
|
153
|
+
rubygems_version: 2.5.2.3
|
|
154
|
+
signing_key:
|
|
155
|
+
specification_version: 4
|
|
156
|
+
summary: Uses the API to list or replace a package in all JSS policies in which it
|
|
157
|
+
appears.
|
|
158
|
+
test_files: []
|