simp-rake-helpers 5.11.2 → 5.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +5 -1
- data/README.md +1 -1
- data/lib/simp/command_utils.rb +21 -0
- data/lib/simp/componentinfo.rb +17 -0
- data/lib/simp/local_gpg_signing_key.rb +184 -81
- data/lib/simp/rake.rb +3 -10
- data/lib/simp/rake/build/build.rb +43 -27
- data/lib/simp/rake/build/constants.rb +5 -1
- data/lib/simp/rake/build/pkg.rb +167 -51
- data/lib/simp/rake/build/tar.rb +1 -1
- data/lib/simp/rake/helpers/version.rb +1 -1
- data/lib/simp/rake/pkg.rb +5 -1
- data/lib/simp/rake/pupmod/helpers.rb +2 -0
- data/lib/simp/rake/rubygem.rb +5 -1
- data/lib/simp/relchecks.rb +1 -1
- data/lib/simp/rpm.rb +13 -125
- data/lib/simp/rpm_signer.rb +321 -0
- data/spec/acceptance/00_pkg_rpm_custom_scriptlets_spec.rb +18 -19
- data/spec/acceptance/10_pkg_rpm_spec.rb +46 -48
- data/spec/acceptance/50_local_gpg_signing_key_spec.rb +7 -3
- data/spec/acceptance/55_build_pkg_signing_spec.rb +293 -42
- data/spec/acceptance/files/testpackage/README +8 -0
- data/spec/acceptance/files/testpackage/spec/classes/init_spec.rb +1 -0
- data/spec/acceptance/files/testpackage/spec/files/mock_something.rb +3 -0
- data/spec/acceptance/files/testpackage/utils/convert_v1_to_v2.rb +3 -0
- data/spec/acceptance/nodesets/default.yml +34 -109
- data/spec/acceptance/support/build_project_helpers.rb +32 -8
- data/spec/lib/simp/ci/gitlab_spec.rb +12 -13
- data/spec/lib/simp/command_utils_spec.rb +29 -0
- data/spec/lib/simp/componentinfo_spec.rb +10 -4
- data/spec/lib/simp/local_gpg_signing_key_spec.rb.beaker-only +115 -18
- data/spec/lib/simp/rake/build/helpers_spec.rb +3 -0
- data/spec/lib/simp/rake/build/rpmdeps_spec.rb +1 -2
- data/spec/lib/simp/rake/pupmod/fixtures/othermod/Gemfile +1 -10
- data/spec/lib/simp/rake/pupmod/fixtures/simpmod/README.md +2 -2
- data/spec/lib/simp/rake_spec.rb +2 -1
- data/spec/lib/simp/relchecks_check_rpm_changelog_spec.rb +20 -10
- data/spec/lib/simp/relchecks_compare_latest_tag_spec.rb +18 -18
- data/spec/lib/simp/rpm_signer_spec.rb +98 -0
- data/spec/lib/simp/rpm_spec.rb +1 -7
- data/spec/spec_helper.rb +1 -1
- data/spec/spec_helper_acceptance.rb +16 -3
- metadata +13 -69
- data/.travis.yml +0 -60
- data/spec/acceptance/20_pkg_rpm_upgrade_spec.rb +0 -236
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/build/rpm_metadata/custom/overrides +0 -14
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-2.1/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/build/rpm_metadata/custom/overrides +0 -14
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-new-package-3.0/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-1.0/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.0/metadata.json +0 -33
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/CHANGELOG +0 -2
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/Rakefile +0 -3
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/build/rpm_metadata/custom/overrides +0 -14
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/build/rpm_metadata/requires +0 -1
- data/spec/acceptance/files/custom_scriptlet_triggers/pupmod-old-package-2.2/metadata.json +0 -33
- data/spec/acceptance/files/mock_packages/pupmod-puppetlabs-stdlib.spec +0 -32
- data/spec/acceptance/files/mock_packages/pupmod-simp-foo.spec +0 -32
- data/spec/acceptance/files/mock_packages/pupmod-simp-simplib.spec +0 -32
- data/spec/acceptance/files/mock_packages/rpmbuild.sh +0 -25
- data/spec/acceptance/files/mock_packages/simp-adapter.spec +0 -43
- data/spec/acceptance/files/mock_packages/simp-adapter/etc/simp/adapter_config.yaml +0 -3
- data/spec/acceptance/files/mock_packages/simp-adapter/usr/local/sbin/simp_rpm_helper +0 -495
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/CHANGELOG +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/Rakefile +0 -3
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/build/rpm_metadata/requires +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/data/os/CentOS.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/data/os/RedHat.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/hiera.yaml +0 -14
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/manifests/init.pp +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-1.0/metadata.json +0 -37
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/CHANGELOG +0 -5
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/Rakefile +0 -3
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/build/rpm_metadata/requires +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/data/os/CentOS.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/data/os/RedHat.yaml +0 -2
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/hiera.yaml +0 -14
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/manifests/init.pp +0 -3
- data/spec/acceptance/files/package_upgrades/pupmod-simp-testpackage-2.0/metadata.json +0 -37
- data/spec/lib/simp/ci/files/job_broken_link_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_invalid_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_invalid_suite/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_missing_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/job_missing_suite_and_nodeset/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/no_gitlab_config_with_tests/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/no_gitlab_config_without_tests/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/suite_skeleton_only/spec/acceptance/nodesets/default.yml +0 -1
- data/spec/lib/simp/ci/files/suite_skeleton_only/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/valid_job_nodeset_dir_link/spec/acceptance/suites/default/nodesets +0 -1
- data/spec/lib/simp/ci/files/valid_job_nodeset_link/spec/acceptance/suites/default/nodesets/default.yml +0 -1
- data/spec/lib/simp/files/build/testpackage.spec +0 -1
- data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/acceptance/nodesets/default.yml +0 -1
- data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/acceptance/suites/default/nodesets +0 -1
@@ -1 +0,0 @@
|
|
1
|
-
Requires: pupmod-simp-foo >= 1.2.3
|
@@ -1,33 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "old-package",
|
3
|
-
"version": "2.0.0",
|
4
|
-
"author": "simp",
|
5
|
-
"summary": "A SIMP test module for upgrading obsoleted packages",
|
6
|
-
"license": "Apache-2.0",
|
7
|
-
"source": "https://github.com/simp/rubygem-simp-rake-helpers",
|
8
|
-
"project_page": "https://github.com/simp/rubygem-simp-rake-helpers",
|
9
|
-
"issues_url": "https://simp/project.atlassian.net",
|
10
|
-
"tags": [ "simp", "test", "package"],
|
11
|
-
"dependencies": [
|
12
|
-
{
|
13
|
-
"name": "simp/simplib",
|
14
|
-
"version_requirement": ">= 1.1.0"
|
15
|
-
}
|
16
|
-
],
|
17
|
-
"operatingsystem_support": [
|
18
|
-
{
|
19
|
-
"operatingsystem": "CentOS",
|
20
|
-
"operatingsystemrelease": [
|
21
|
-
"6",
|
22
|
-
"7"
|
23
|
-
]
|
24
|
-
},
|
25
|
-
{
|
26
|
-
"operatingsystem": "RedHat",
|
27
|
-
"operatingsystemrelease": [
|
28
|
-
"6",
|
29
|
-
"7"
|
30
|
-
]
|
31
|
-
}
|
32
|
-
]
|
33
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
%triggerpostun -- pupmod-new-package
|
2
|
-
|
3
|
-
echo
|
4
|
-
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
5
|
-
echo "@@@@@@ Executing SIMP-3895 workaround @@@@@@"
|
6
|
-
echo "@@@@@@ @@@@@@"
|
7
|
-
echo "@@@@@@ upgrading from obsoleted pkg @@@@@@"
|
8
|
-
echo "@@@@@@ 'pupmod-new-package' @@@@@@"
|
9
|
-
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
10
|
-
echo
|
11
|
-
echo "pupmod-old-package: post 1=2 (triggered by: %triggerpostun -- pupmod-new-package)"
|
12
|
-
|
13
|
-
# re-send the 'post' message
|
14
|
-
/usr/local/sbin/simp_rpm_helper --rpm_dir=/usr/share/simp/modules/package --rpm_section='post' --rpm_status=2
|
@@ -1 +0,0 @@
|
|
1
|
-
Obsoletes: pupmod-new-package < 2.2.0
|
@@ -1,33 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "old-package",
|
3
|
-
"version": "2.2.0",
|
4
|
-
"author": "simp",
|
5
|
-
"summary": "A SIMP test module for upgrading obsoleted packages",
|
6
|
-
"license": "Apache-2.0",
|
7
|
-
"source": "https://github.com/simp/rubygem-simp-rake-helpers",
|
8
|
-
"project_page": "https://github.com/simp/rubygem-simp-rake-helpers",
|
9
|
-
"issues_url": "https://simp/project.atlassian.net",
|
10
|
-
"tags": [ "simp", "test", "package"],
|
11
|
-
"dependencies": [
|
12
|
-
{
|
13
|
-
"name": "simp/simplib",
|
14
|
-
"version_requirement": ">= 1.1.0"
|
15
|
-
}
|
16
|
-
],
|
17
|
-
"operatingsystem_support": [
|
18
|
-
{
|
19
|
-
"operatingsystem": "CentOS",
|
20
|
-
"operatingsystemrelease": [
|
21
|
-
"6",
|
22
|
-
"7"
|
23
|
-
]
|
24
|
-
},
|
25
|
-
{
|
26
|
-
"operatingsystem": "RedHat",
|
27
|
-
"operatingsystemrelease": [
|
28
|
-
"6",
|
29
|
-
"7"
|
30
|
-
]
|
31
|
-
}
|
32
|
-
]
|
33
|
-
}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
Name: pupmod-puppetlabs-stdlib
|
2
|
-
Version: 5.9.9
|
3
|
-
Release: 9
|
4
|
-
Summary: mock simplib test package
|
5
|
-
BuildArch: noarch
|
6
|
-
|
7
|
-
License: Apache-2.0
|
8
|
-
URL: http://foo.bar
|
9
|
-
|
10
|
-
%description
|
11
|
-
A mock RPM package used for acceptance tests
|
12
|
-
|
13
|
-
%prep
|
14
|
-
exit 0
|
15
|
-
|
16
|
-
%build
|
17
|
-
exit 0
|
18
|
-
|
19
|
-
|
20
|
-
%install
|
21
|
-
exit 0
|
22
|
-
|
23
|
-
%clean
|
24
|
-
exit 0
|
25
|
-
|
26
|
-
%files
|
27
|
-
%doc
|
28
|
-
|
29
|
-
|
30
|
-
%changelog
|
31
|
-
* Fri Feb 23 2018 nobody
|
32
|
-
- some comment
|
@@ -1,32 +0,0 @@
|
|
1
|
-
Name: pupmod-simp-foo
|
2
|
-
Version: 1.9.9
|
3
|
-
Release: 9
|
4
|
-
Summary: mock foo test package
|
5
|
-
BuildArch: noarch
|
6
|
-
|
7
|
-
License: Apache-2.0
|
8
|
-
URL: http://foo.bar
|
9
|
-
|
10
|
-
%description
|
11
|
-
A mock RPM package used for acceptance tests
|
12
|
-
|
13
|
-
%prep
|
14
|
-
exit 0
|
15
|
-
|
16
|
-
%build
|
17
|
-
exit 0
|
18
|
-
|
19
|
-
|
20
|
-
%install
|
21
|
-
exit 0
|
22
|
-
|
23
|
-
%clean
|
24
|
-
exit 0
|
25
|
-
|
26
|
-
%files
|
27
|
-
%doc
|
28
|
-
|
29
|
-
|
30
|
-
%changelog
|
31
|
-
* Fri Feb 23 2018 nobody
|
32
|
-
- some comment
|
@@ -1,32 +0,0 @@
|
|
1
|
-
Name: pupmod-simp-simplib
|
2
|
-
Version: 1.9.9
|
3
|
-
Release: 9
|
4
|
-
Summary: mock simplib test package
|
5
|
-
BuildArch: noarch
|
6
|
-
|
7
|
-
License: Apache-2.0
|
8
|
-
URL: http://foo.bar
|
9
|
-
|
10
|
-
%description
|
11
|
-
A mock RPM package used for acceptance tests
|
12
|
-
|
13
|
-
%prep
|
14
|
-
exit 0
|
15
|
-
|
16
|
-
%build
|
17
|
-
exit 0
|
18
|
-
|
19
|
-
|
20
|
-
%install
|
21
|
-
exit 0
|
22
|
-
|
23
|
-
%clean
|
24
|
-
exit 0
|
25
|
-
|
26
|
-
%files
|
27
|
-
%doc
|
28
|
-
|
29
|
-
|
30
|
-
%changelog
|
31
|
-
* Fri Feb 23 2018 nobody
|
32
|
-
- some comment
|
@@ -1,25 +0,0 @@
|
|
1
|
-
spec_file=$1
|
2
|
-
|
3
|
-
FAKE_RPM_SRC_DIR=${FAKE_RPM_SRC_DIR:-${PWD}/pkg}
|
4
|
-
FAKE_RPM_BUILD_DIR=${FAKE_RPM_BUILD_DIR:-${FAKE_RPM_SRC_DIR}/rpmbuild}
|
5
|
-
|
6
|
-
# clean up old builds
|
7
|
-
rm -rf "${FAKE_RPM_BUILD_DIR}"/{BUILDROOT,BUILD,SOURCES}/** &> /dev/null :
|
8
|
-
mkdir -p "${FAKE_RPM_BUILD_DIR}"/{BUILDROOT,BUILD,SOURCES}
|
9
|
-
|
10
|
-
|
11
|
-
# if there is a directory with the same name as the spec file, build a tar ball
|
12
|
-
# from it and stage it under SOURCES
|
13
|
-
source_dir=`echo ${spec_file}| sed -e 's/.spec$//'`
|
14
|
-
if [ -d "${source_dir}" ]; then
|
15
|
-
echo "Found a directory named '${source_dir}'; building tarball"
|
16
|
-
pushd "${source_dir}" > /dev/null
|
17
|
-
tar -zcv --exclude=.*.swp -f "${FAKE_RPM_BUILD_DIR}/SOURCES/files.tar.gz" *
|
18
|
-
popd > /dev/null
|
19
|
-
else
|
20
|
-
echo "NOTE: no source directory ar '${source_dir}'"
|
21
|
-
fi
|
22
|
-
|
23
|
-
|
24
|
-
# rpmbuild
|
25
|
-
rpmbuild -D "buildroot ${FAKE_RPM_BUILD_DIR}/BUILDROOT" -D "builddir ${FAKE_RPM_BUILD_DIR}/BUILD" -D "_sourcedir ${FAKE_RPM_BUILD_DIR}/SOURCES" -D "_rpmdir ${FAKE_RPM_SRC_DIR}/dist" -D "_srcrpmdir ${FAKE_RPM_SRC_DIR}/dist" -D "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" -ba $@ "${spec_file}"
|
@@ -1,43 +0,0 @@
|
|
1
|
-
Name: simp-adapter
|
2
|
-
Version: 0.9.9
|
3
|
-
Release: 9
|
4
|
-
Summary: mock simplib test package
|
5
|
-
BuildArch: noarch
|
6
|
-
|
7
|
-
License: Apache-2.0
|
8
|
-
URL: http://foo.bar
|
9
|
-
|
10
|
-
Source0: files.tar.gz
|
11
|
-
|
12
|
-
%description
|
13
|
-
A mock RPM package used for acceptance tests
|
14
|
-
|
15
|
-
%prep
|
16
|
-
echo ================ PWD: $PWD
|
17
|
-
%setup -c
|
18
|
-
|
19
|
-
%build
|
20
|
-
|
21
|
-
|
22
|
-
%install
|
23
|
-
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
|
24
|
-
mkdir -p %{buildroot}/opt/test/puppet/code
|
25
|
-
cp -r $PWD/* %{buildroot}/
|
26
|
-
rm -rf %{buildroot}/**/.*.swp
|
27
|
-
rm -rf %{buildroot}/opt/puppetlabs
|
28
|
-
|
29
|
-
%clean
|
30
|
-
|
31
|
-
%files
|
32
|
-
%defattr(0640,root,root,0755)
|
33
|
-
|
34
|
-
%attr(0750,root,root)/usr/local/sbin/simp_rpm_helper
|
35
|
-
#%attr(0755,root,root)/opt/puppetlabs/puppet/bin/ruby
|
36
|
-
#%attr(0755,root,root)/opt/puppetlabs/bin/puppet
|
37
|
-
%attr(0644,root,root)/etc/simp/adapter_config.yaml
|
38
|
-
%dir /opt/test/puppet/code
|
39
|
-
|
40
|
-
|
41
|
-
%changelog
|
42
|
-
* Fri Feb 23 2018 nobody
|
43
|
-
- some comment
|
@@ -1,495 +0,0 @@
|
|
1
|
-
#!/opt/puppetlabs/puppet/bin/ruby
|
2
|
-
#
|
3
|
-
# Purpose
|
4
|
-
# -------
|
5
|
-
#
|
6
|
-
# This script is meant to be called by the %preun and %postttrans sections of
|
7
|
-
# the various SIMP Puppet module RPMs.
|
8
|
-
#
|
9
|
-
# The purpose of the script is to provide helper methods that correctly
|
10
|
-
# scaffold the system in such a way that all SIMP Puppet Modules can be
|
11
|
-
# installed via RPM to a single location and subsequently can be copied into
|
12
|
-
# the standard SIMP installation location based on the version of Puppet that
|
13
|
-
# is installed.
|
14
|
-
#
|
15
|
-
# Care is taken that, should the target directory be managed via 'git', this
|
16
|
-
# script will do nothing to harm the managed installation in any way. This
|
17
|
-
# ensures that the SIMP modules have maximum compatibility with the widest
|
18
|
-
# possible range of Puppet module best practices for management while ensuring
|
19
|
-
# that the RPM installations and upgrades can proceed in a seamless fashion
|
20
|
-
# over time.
|
21
|
-
#
|
22
|
-
# Should the 'simp' environment not be found, the script will simply exit
|
23
|
-
# without copying any files.
|
24
|
-
#
|
25
|
-
# Configuration
|
26
|
-
# -------------
|
27
|
-
#
|
28
|
-
# A configuration file may be placed at /etc/simp/adapter_config.yaml. The
|
29
|
-
# file must consist of proper YAML as demonstrated in the example below which
|
30
|
-
# lists the default options.
|
31
|
-
#
|
32
|
-
# Any configuration options that are not understood will be ignored.
|
33
|
-
#
|
34
|
-
# ```yaml
|
35
|
-
# ---
|
36
|
-
# # Target directory
|
37
|
-
# # May be set to a fully qualified path or 'auto'
|
38
|
-
# # If set to 'auto', the directory will be determined from puppet itself
|
39
|
-
#
|
40
|
-
# target_directory : 'auto'
|
41
|
-
#
|
42
|
-
# # Copy the RPM data to the target directory
|
43
|
-
#
|
44
|
-
# copy_rpm_data : false
|
45
|
-
#
|
46
|
-
# ```
|
47
|
-
#
|
48
|
-
|
49
|
-
require 'facter'
|
50
|
-
require 'fileutils'
|
51
|
-
require 'yaml'
|
52
|
-
require 'optparse'
|
53
|
-
require 'ostruct'
|
54
|
-
require 'find'
|
55
|
-
|
56
|
-
# Make sure we can find the Puppet executables
|
57
|
-
ENV['PATH'] += ':/opt/puppetlabs/bin'
|
58
|
-
|
59
|
-
class SimpRpmHelper
|
60
|
-
def initialize
|
61
|
-
@program_name = File.basename(__FILE__)
|
62
|
-
|
63
|
-
# A list of modules that should never be touched once installed
|
64
|
-
@safe_modules = ['site']
|
65
|
-
end
|
66
|
-
|
67
|
-
def debug(msg)
|
68
|
-
# SIMP RPMs do not enable debug when they call this script. So, if
|
69
|
-
# you want to debug an RPM problem with this script, comment out
|
70
|
-
# the line below.
|
71
|
-
return unless @options.debug
|
72
|
-
msg.split("\n").each do |line|
|
73
|
-
puts ">>>#{@program_name} DEBUG: #{line}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def info(msg)
|
78
|
-
# When these messages get written out in an RPM upgrade, name of program
|
79
|
-
# is helpful to end user
|
80
|
-
puts "#{@program_name}: #{msg}"
|
81
|
-
end
|
82
|
-
|
83
|
-
# Get the Puppet configuration parameters currently in use
|
84
|
-
def get_puppet_config
|
85
|
-
system_config = %x{puppet config --section master print}
|
86
|
-
|
87
|
-
config_hash = Hash.new
|
88
|
-
|
89
|
-
system_config.each_line do |line|
|
90
|
-
k,v = line.split('=')
|
91
|
-
config_hash[k.strip] = v.strip
|
92
|
-
end
|
93
|
-
|
94
|
-
return config_hash
|
95
|
-
end
|
96
|
-
|
97
|
-
# Determine whether the passed path is under management by git or svn
|
98
|
-
def is_managed?(path)
|
99
|
-
# Short circuit if the directory is not present
|
100
|
-
return false unless File.directory?(path)
|
101
|
-
|
102
|
-
git = Facter::Core::Execution.which('git')
|
103
|
-
svn = Facter::Core::Execution.which('svn')
|
104
|
-
|
105
|
-
Dir.chdir(path) do
|
106
|
-
if git
|
107
|
-
%x{#{git} ls-files . --error-unmatch &> /dev/null}
|
108
|
-
|
109
|
-
return true if $?.success?
|
110
|
-
end
|
111
|
-
|
112
|
-
if svn
|
113
|
-
%x{#{svn} info &> /dev/null}
|
114
|
-
|
115
|
-
return true if $?.success?
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
return false
|
120
|
-
end
|
121
|
-
|
122
|
-
def parse_options(args)
|
123
|
-
|
124
|
-
@options = OpenStruct.new
|
125
|
-
@options.config_file = '/etc/simp/adapter_config.yaml'
|
126
|
-
@options.preserve = false
|
127
|
-
|
128
|
-
all_opts = OptionParser.new do |opts|
|
129
|
-
opts.banner = "Usage: #{@program_name} [options]"
|
130
|
-
|
131
|
-
opts.separator ''
|
132
|
-
|
133
|
-
opts.on(
|
134
|
-
'--rpm_dir PATH',
|
135
|
-
'The directory into which the RPM source material is installed'
|
136
|
-
) do |arg|
|
137
|
-
@options.rpm_dir = arg.strip
|
138
|
-
@options.module_name = File.basename(@options.rpm_dir)
|
139
|
-
end
|
140
|
-
|
141
|
-
opts.on(
|
142
|
-
'--rpm_section SECTION',
|
143
|
-
'The section of the RPM from which the script is being called.',
|
144
|
-
" Must be one of 'pre', 'preun', 'postun', 'posttrans'"
|
145
|
-
) do |arg|
|
146
|
-
@options.rpm_section = arg.strip
|
147
|
-
end
|
148
|
-
|
149
|
-
opts.on(
|
150
|
-
'--rpm_status STATUS',
|
151
|
-
'The status code passed to the RPM section'
|
152
|
-
) do |arg|
|
153
|
-
@options.rpm_status = arg.strip
|
154
|
-
end
|
155
|
-
|
156
|
-
opts.on(
|
157
|
-
'-f CONFIG_FILE',
|
158
|
-
'--config CONFIG_FILE',
|
159
|
-
'The configuration file to use.',
|
160
|
-
" Default: #{@options.config_file}"
|
161
|
-
) do |arg|
|
162
|
-
@options.config_file = arg.strip
|
163
|
-
end
|
164
|
-
|
165
|
-
opts.on(
|
166
|
-
'-p',
|
167
|
-
'--preserve',
|
168
|
-
"Preserve material in 'target_dir' that is not in 'rpm_dir'"
|
169
|
-
) do |arg|
|
170
|
-
@options.preserve = true
|
171
|
-
end
|
172
|
-
|
173
|
-
opts.on(
|
174
|
-
'-e',
|
175
|
-
'--enforce',
|
176
|
-
'If set, enforce the copy, regardless of the setting in the config file',
|
177
|
-
' Default: false'
|
178
|
-
) do |arg|
|
179
|
-
@options.copy_rpm_data = true
|
180
|
-
end
|
181
|
-
|
182
|
-
opts.on(
|
183
|
-
'-t DIR',
|
184
|
-
'--target_dir DIR',
|
185
|
-
"The subdirectory of #{simp_target_dir('')}",
|
186
|
-
'into which to copy the materials.',
|
187
|
-
" Default: #{simp_target_dir.gsub(/#{simp_target_dir('')}/,'')}"
|
188
|
-
) do |arg|
|
189
|
-
@options.target_dir = simp_target_dir(arg.strip)
|
190
|
-
end
|
191
|
-
|
192
|
-
opts.on(
|
193
|
-
'-v',
|
194
|
-
'--verbose',
|
195
|
-
'Print out debug info when processing.'
|
196
|
-
) do
|
197
|
-
@options.debug = true
|
198
|
-
end
|
199
|
-
|
200
|
-
opts.on(
|
201
|
-
'-h',
|
202
|
-
'--help',
|
203
|
-
'Help Message'
|
204
|
-
) do
|
205
|
-
puts opts
|
206
|
-
@options.help_requested = true
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
begin
|
211
|
-
all_opts.parse!(args)
|
212
|
-
rescue OptionParser::ParseError => e
|
213
|
-
msg = "Error: #{e}\n\n#{all_opts}"
|
214
|
-
raise(msg)
|
215
|
-
end
|
216
|
-
|
217
|
-
validate_options(all_opts.to_s)
|
218
|
-
end
|
219
|
-
|
220
|
-
# Process the config, validate the entries and do some munging
|
221
|
-
# Sets @options hash.
|
222
|
-
def process_config
|
223
|
-
# Defaults
|
224
|
-
config = {
|
225
|
-
'target_directory' => 'auto',
|
226
|
-
'copy_rpm_data' => false
|
227
|
-
}
|
228
|
-
|
229
|
-
if File.exist?(@options.config_file)
|
230
|
-
begin
|
231
|
-
system_config = YAML.load_file(@options.config_file)
|
232
|
-
if system_config
|
233
|
-
config.merge!(system_config)
|
234
|
-
end
|
235
|
-
rescue
|
236
|
-
raise("Error: Config file '#{@options.config_file}' could not be processed")
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
if @options.copy_rpm_data.nil?
|
241
|
-
@options.copy_rpm_data = (config['copy_rpm_data'].to_s == 'true')
|
242
|
-
end
|
243
|
-
|
244
|
-
if @options.target_dir.nil? && config['target_directory']
|
245
|
-
if config['target_directory'] == 'auto'
|
246
|
-
@options.target_dir = simp_target_dir
|
247
|
-
else
|
248
|
-
unless config['target_directory'][0].chr == '/'
|
249
|
-
raise("Error: 'target_directory' in '#{@options.config_file}' must be an absolute path")
|
250
|
-
end
|
251
|
-
|
252
|
-
@options.target_dir = config['target_directory'].strip
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
def puppet_codedir
|
258
|
-
# Figure out where the Puppet code should go
|
259
|
-
# Puppet 4+
|
260
|
-
code_dir = puppet_config['codedir']
|
261
|
-
if !code_dir || code_dir.empty?
|
262
|
-
code_dir = puppet_config['confdir']
|
263
|
-
end
|
264
|
-
|
265
|
-
return code_dir
|
266
|
-
end
|
267
|
-
|
268
|
-
def puppet_config
|
269
|
-
unless @puppet_config
|
270
|
-
@puppet_config = get_puppet_config
|
271
|
-
end
|
272
|
-
@puppet_config
|
273
|
-
end
|
274
|
-
|
275
|
-
|
276
|
-
def puppet_group
|
277
|
-
puppet_config['group']
|
278
|
-
end
|
279
|
-
|
280
|
-
# Return the target installation directory
|
281
|
-
def simp_target_dir(subdir=File.join('simp','modules'))
|
282
|
-
install_target = puppet_codedir
|
283
|
-
|
284
|
-
if install_target.empty?
|
285
|
-
raise('Error: Could not find a Puppet code directory for installation')
|
286
|
-
end
|
287
|
-
|
288
|
-
install_target = File.join(install_target,'environments', subdir)
|
289
|
-
|
290
|
-
return install_target
|
291
|
-
end
|
292
|
-
|
293
|
-
# Input Validation
|
294
|
-
def validate_options(usage)
|
295
|
-
return if @options.help_requested
|
296
|
-
|
297
|
-
unless @options.rpm_dir
|
298
|
-
raise("Error: 'rpm_dir' is required\n#{usage}")
|
299
|
-
end
|
300
|
-
|
301
|
-
unless @options.rpm_status
|
302
|
-
raise("Error: 'rpm_status' is required\n#{usage}")
|
303
|
-
end
|
304
|
-
|
305
|
-
unless @options.rpm_section
|
306
|
-
raise("Error: 'rpm_section' is required\n#{usage}")
|
307
|
-
end
|
308
|
-
|
309
|
-
# We allow 'post' for backward compatibility with SIMP RPMs that use
|
310
|
-
# this, but copying over files in the 'post' during an upgrade is
|
311
|
-
# problematic. If the old package has files that are not in the new
|
312
|
-
# package, these files will not be removed in the destination directory.
|
313
|
-
# This is because during %post, the old package files have not yet
|
314
|
-
# been removed from the source directory by RPM. So, the 'rsync'
|
315
|
-
# operation copies over the OBE files from the old package.
|
316
|
-
valid_rpm_sections = ['pre','post','preun','postun', 'posttrans']
|
317
|
-
|
318
|
-
unless valid_rpm_sections.include?(@options.rpm_section)
|
319
|
-
raise("Error: 'rpm_section' must be one of '#{valid_rpm_sections.join("', '")}'\n#{usage}")
|
320
|
-
end
|
321
|
-
|
322
|
-
if (@options.rpm_section == 'posttrans') || (@options.rpm_section == 'preun') || (@options.rpm_section == 'post')
|
323
|
-
unless File.directory?(@options.rpm_dir)
|
324
|
-
raise("Error: Could not find 'rpm_dir': '#{@options.rpm_dir}'")
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
unless @options.rpm_status =~ /^\d+$/
|
329
|
-
raise("Error: 'rpm_status' must be an integer\n#{usage}")
|
330
|
-
end
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
|
-
def handle_install
|
335
|
-
debug("Processing install, upgrade, or downgrade of #{@options.module_name}")
|
336
|
-
if @safe_modules.include?(@options.module_name)
|
337
|
-
# Make sure that we preserve anything in the safe modules on installation
|
338
|
-
@options.preserve = true
|
339
|
-
|
340
|
-
if @options.rpm_status == '2'
|
341
|
-
# Short circuit on upgrading safe modules, just don't touch them!
|
342
|
-
target_module_dir = File.join(@options.target_dir, @options.module_name)
|
343
|
-
if File.directory?(target_module_dir)
|
344
|
-
debug("Skipping upgrade of 'safe' module directory #{target_module_dir}")
|
345
|
-
return
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
raise('Error: Could not determine puppet group') if puppet_group.empty?
|
351
|
-
rsync = Facter::Core::Execution.which('rsync')
|
352
|
-
raise("Error: Could not find 'rsync' command!") unless rsync
|
353
|
-
|
354
|
-
# Create the directories, with the proper mode, all the way down
|
355
|
-
dir_paths = @options.target_dir.split(File::SEPARATOR).reject(&:empty?)
|
356
|
-
top_dir = File::SEPARATOR + dir_paths.shift
|
357
|
-
unless File.directory?(top_dir)
|
358
|
-
FileUtils.mkdir(top_dir, :mode => 0750)
|
359
|
-
FileUtils.chown('root', puppet_group, top_dir)
|
360
|
-
end
|
361
|
-
|
362
|
-
orig_dir = Dir.pwd
|
363
|
-
Dir.chdir(top_dir)
|
364
|
-
dir_paths.each do |dir|
|
365
|
-
unless File.directory?(dir)
|
366
|
-
FileUtils.mkdir(dir, :mode => 0750)
|
367
|
-
FileUtils.chown('root', puppet_group, dir)
|
368
|
-
end
|
369
|
-
|
370
|
-
Dir.chdir(dir)
|
371
|
-
end
|
372
|
-
Dir.chdir(orig_dir)
|
373
|
-
|
374
|
-
cmd = %(#{rsync} -a --force)
|
375
|
-
|
376
|
-
if @options.preserve
|
377
|
-
cmd += %( --ignore-existing)
|
378
|
-
else
|
379
|
-
cmd += %( --delete)
|
380
|
-
end
|
381
|
-
|
382
|
-
cmd += %( --verbose) if @options.debug
|
383
|
-
|
384
|
-
cmd += %( #{@options.rpm_dir} #{@options.target_dir})
|
385
|
-
cmd += %( 2>&1)
|
386
|
-
|
387
|
-
info("Copying '#{@options.module_name}' files into '#{@options.target_dir}'")
|
388
|
-
debug("Executing: #{cmd}")
|
389
|
-
output = %x{#{cmd}}
|
390
|
-
debug("Output:\n#{output}")
|
391
|
-
unless $?.success?
|
392
|
-
raise(%(Error: Copy of '#{@options.module_name}' into '#{@options.target_dir}' using '#{cmd}' failed with the following error:\n #{output.gsub("\n","\n ")}))
|
393
|
-
end
|
394
|
-
|
395
|
-
FileUtils.chown_R(nil, "#{puppet_group}", @options.target_dir)
|
396
|
-
end
|
397
|
-
|
398
|
-
def handle_uninstall
|
399
|
-
debug("Processing uninstall of #{@options.module_name}")
|
400
|
-
# Play it safe, this needs to have at least 'environments/simp' in it!
|
401
|
-
if @options.target_dir.split(File::SEPARATOR).reject(&:empty?).size < 3
|
402
|
-
raise("Error: Not removing directory '#{@options.target_dir}' for safety")
|
403
|
-
end
|
404
|
-
|
405
|
-
if @safe_modules.include?(@options.module_name)
|
406
|
-
target_module_dir = File.join(@options.target_dir, @options.module_name)
|
407
|
-
debug("Skipping removal of 'safe' module directory #{target_module_dir}")
|
408
|
-
return
|
409
|
-
end
|
410
|
-
|
411
|
-
info("Removing '#{@options.module_name}' files from '#{@options.target_dir}'")
|
412
|
-
|
413
|
-
# Find out what we have
|
414
|
-
ref_list = []
|
415
|
-
Dir.chdir(@options.rpm_dir) do
|
416
|
-
Find.find('.').each do |file|
|
417
|
-
if File.symlink?(file)
|
418
|
-
ref_list << file
|
419
|
-
Find.prune
|
420
|
-
end
|
421
|
-
|
422
|
-
ref_list << file
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
# Delete from the bottom up to clear out the directories first
|
427
|
-
# before removing them
|
428
|
-
ref_list.reverse!
|
429
|
-
ref_list.map{|x| x.sub!(/^./, @options.module_name)}
|
430
|
-
|
431
|
-
# Only delete items that are in the reference repo
|
432
|
-
Dir.chdir(@options.target_dir) do
|
433
|
-
ref_list.each do |to_rm|
|
434
|
-
if File.symlink?(to_rm)
|
435
|
-
debug("Removing symlink #{to_rm}")
|
436
|
-
FileUtils.rm_f(to_rm)
|
437
|
-
elsif File.directory?(to_rm) && (Dir.entries(to_rm).delete_if {|dir|
|
438
|
-
dir == '.' || dir == '..'}.size == 0)
|
439
|
-
debug("Removing directory #{to_rm}")
|
440
|
-
FileUtils.rmdir(to_rm)
|
441
|
-
elsif File.exist?(to_rm)
|
442
|
-
debug("Removing file #{to_rm}")
|
443
|
-
FileUtils.rm_f(to_rm)
|
444
|
-
end
|
445
|
-
end
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
def run(args)
|
450
|
-
parse_options(args)
|
451
|
-
return 0 if @options.help_requested
|
452
|
-
|
453
|
-
process_config
|
454
|
-
debug("Running with config=#{@options.to_s}")
|
455
|
-
|
456
|
-
# If the target directory is managed, we're done
|
457
|
-
target_module_dir = File.join(@options.target_dir, @options.module_name)
|
458
|
-
unless is_managed?(target_module_dir) || !@options.copy_rpm_data
|
459
|
-
|
460
|
-
debug("Processing unmanaged target directory #{target_module_dir}")
|
461
|
-
|
462
|
-
if (@options.rpm_section == 'posttrans') || (@options.rpm_section == 'post')
|
463
|
-
# A regular installation, upgrade or downgrade
|
464
|
-
# This *should* happen in the RPM %posttrans, but we allow this to
|
465
|
-
# occur in the %post for backward compatibility with SIMP RPMs that
|
466
|
-
# erroneously try to affect a copy in the %post. (Copying over the
|
467
|
-
# files in the RPM %post during an upgrade/downgrade is problematic.
|
468
|
-
# If the old package has files that are not in the new package,
|
469
|
-
# these files will not yet have been removed in the source
|
470
|
-
# directory, and thus end up in the target directory.)
|
471
|
-
handle_install
|
472
|
-
elsif @options.rpm_section == 'preun' && @options.rpm_status == '0'
|
473
|
-
# A regular uninstall
|
474
|
-
# This needs to happen *before* RPM removes the files (%preun with
|
475
|
-
# status 0), since we need to compare with what's on disk to undo
|
476
|
-
# the copy done during the RPM install via handle_install()
|
477
|
-
handle_uninstall
|
478
|
-
end
|
479
|
-
end
|
480
|
-
return 0
|
481
|
-
rescue RuntimeError => e
|
482
|
-
$stderr.puts(e)
|
483
|
-
return 1
|
484
|
-
rescue Exception => e
|
485
|
-
$stderr.puts(e)
|
486
|
-
e.backtrace.first(10).each{|l| $stderr.puts l }
|
487
|
-
return 1
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
if __FILE__ == $0
|
492
|
-
helper = SimpRpmHelper.new
|
493
|
-
exit helper.run(ARGV)
|
494
|
-
end
|
495
|
-
|