Accepting request 721223 from home:eeich

- Submitting clone-master-clean-up - a script to turn a system into a
  pristine source for system cloning (VMs, chroots etc).
  This has been SLE-only, however it is far to useful to not be in Factory.

OBS-URL: https://build.opensuse.org/request/show/721223
OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/clone-master-clean-up?expand=0&rev=1
This commit is contained in:
Anna Maresova 2019-08-06 14:23:57 +00:00 committed by Git OBS Bridge
commit 56088d92cd
12 changed files with 989 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

339
LICENSE Normal file
View File

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# clone-master-clean-up
This utility is offered on all versions of SLES4SAP 12 from SP1 and onward. The utility implements a check-list style procedure for cleaning up a system in preparation for system cloning.

9
_service Normal file
View File

@ -0,0 +1,9 @@
<services>
<service name="obs_scm" mode="disabled">
<param name="scm">git</param>
<param name="url">https://github.com/SUSE/clone-master-clean-up.git</param>
<param name="version">HEAD</param>
<param name="exclude">.git</param>
<param name="extract">*</param>
</service>
</services>

137
clone-master-clean-up.1 Normal file
View File

@ -0,0 +1,137 @@
.\"/*
.\" * All rights reserved
.\" * Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
.\" * Authors: Howard Guo <hguo@suse.com>
.\" *
.\" * This program is free software; you can redistribute it and/or
.\" * modify it under the terms of the GNU General Public License
.\" * as published by the Free Software Foundation; either version 2
.\" * of the License, or (at your option) any later version.
.\" *
.\" * This program is distributed in the hope that it will be useful,
.\" * but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" * GNU General Public License for more details.
.\" */
.\"
.TH clone-master-clean-up "1" "May 2017" "" "Clean-Up For Cloning Preparation"
.SH NAME
clone\-master\-clean\-up - Clean up a system for cloning preparation.
.SH OPTIONS
The program does not accept command line options.
.SH DESCRIPTION
Clean up a system and delete all usage history to prepare it for being cloned.
How to properly clean up a system to create a golden image is highly dependent on installed software, machine configuration, and how the image is supposed to be used.
.RS 5
1. A golden image for fast and easy way to deploy a freshly installed base operating system (a so-called plain vanilla image).
.PP
2. A golden image that is used during the life cycle management of a system or solution landscape.
.PP
.RE
Life-cycle management images normally include custom additions beyond the base operating system which are needed on all rolled-out systems. This can include additional software, e.g. for backup, hardware support, or monitoring, and system configuration, e.g. the creation of additional local users and changes to configuration files such as 'sudoers' or 'pam'.
.br
Additionally, with the use case of a life cycle management image, there will be a very intensive test cycle of newly installed software and configuration before the golden image is created and rolled out. Such testing can lead a lot of additional log files and temporary data.
.PP
This means that the parts of the operating system which need to be cleaned up are different depending on the use case and that it can be counterproductive to remove some special files or directories.
.PP
For the use case of creating an clean operating system base installation, the standard scope of 'clone-master-clean-up' is generally sufficient.
To allow customization for this use case, use the configuration file \fB/etc/sysconfig/clone-master-clean-up\fR.
.br
Here, you can configure the following behavior:
.RS 5
/etc/sudoers is restored to original, and only root is allowed to run sudo.
.RS 5
default: no
.RE
clean up user ids >= 1000
.RS 5
default: no
.RE
clean up all zypper repositories
.RS 5
default: no
.RE
remove btrfs snapshots of root filesystem
.RS 5
default: yes
.RE
(If the system is running on EC2) Allow ec2-user to run sudo password-less.
.RS 5
default: no
.RE
.RE
.PP
For the use case of a life cycle management image, it's impossible to write a standard script which will fit all requirements. To enable this use case, clone-master-clean-up allows including a drop-in file containing paths to files and directories that are deleted in addition to doing the standard clean-ups.
.PP
For more information and examples, see \fB/usr/share/clone-master-clean-up/custom_remove.template\fR. Please copy the template file \fB/usr/share/clone-master-clean-up/custom_remove.template\fR to \fB/etc/clone-master-clean-up/custom_remove\fR and un-comment the parts you need or add additional parts which will fit your needs.
.PP
If the file \fB'/etc/clone-master-clean-up/custom_remove'\fR exists, all included files and directories will be picked up line by line and additionally removed from the golden image.
.SH "CLEANED UP ITEMS"
The program asks for confirmation before proceeding with cleanup. If you proceed by typing "YES" and enter, the following locations/items will be cleaned up (or deleted):
.IP \[bu]
SUSE registration, all software repositories.
.IP \[bu]
SSH host keys, user SSH keys, user authorized keys, user shell history.
.IP \[bu]
User mails and user cron jobs.
.IP \[bu]
Temporary files under /tmp and /var/tmp.
.IP \[bu]
Log files and archived log files under /var/log.
.IP \[bu]
Auto-generated HANA firewall configuration script.
.IP \[bu]
System random seeds.
.IP \[bu]
Systemd journal.
.IP \[bu]
Domain and host names.
.IP \[bu]
/etc/hostname, /etc/hosts, /etc/resolv.conf are restored to original.
.IP \[bu]
Persistent network interfaces (auto-generated 70-persistent-net.rules).
.IP \[bu]
YaST Firstboot is enabled if there is a firstboot.xml.
.IP \[bu]
Give root user a new password, optionally.
.IP \[bu]
Zypper anonymous ID
.IP \[bu]
Clean up postfix
.IP \[bu]
Swap the uuid strings with dev strings in /etc/fstab
.IP \[bu]
Clean up network files (except interfaces using dhcp boot protocol)
.IP \[bu]
Clean up collectd
.IP \[bu]
Clean up /root
.IP \[bu]
Clean up cache, crash and coredump
.SH FILES
.PP
\fI/etc/sysconfig/clone-master-clean-up\fR
.RS 4
Defines the behavior of clone-master-clean-up.
.RE
.PP
\fI/usr/share/clone-master-clean-up/custom_remove.template\fR
.RS 4
Template for a vendor/customer-specific drop-in file. Defines additional files and directories to clean up.
.RE
.PP
\fI/etc/clone-master-clean-up/custom_remove\fR
.RS 4
\'Operation-ready\' copy of the template file. If this file exists, clone-master-clean-up will remove files and directories that are listed in it.
.RE
.SH AUTHOR
.NF
Howard Guo <hguo@suse.com>, Angela Briel <abriel@suse.com>

View File

@ -0,0 +1,67 @@
-------------------------------------------------------------------
Fri Aug 2 13:08:25 UTC 2019 - Egbert Eich <eich@suse.com>
- Add _service file to fetch package form git.
Add workaround for service osc_scm: avoid script to have the
same name repository.
-------------------------------------------------------------------
Thu Aug 1 12:27:05 CET 2019 - eich@suse.com
- Wicked stores a number of files containing unique IDs and DHCP data
in /var/lib/wicked/*. These files need to be removed for cloning:
if machines with identical settings exist in the same network
multiple times, IP addresses may change with each renewal
(bsc#1139667)
-------------------------------------------------------------------
Wed Jan 30 17:17:05 UTC 2019 - dakechi@suse.com
- Moved the configuration files out of the /var directory
* Needed for compliance with transactional updates (bsc#1092378)
-------------------------------------------------------------------
Thu Feb 1 01:35:34 CET 2018 - ro@suse.de
- Prepare for new fillup location
-------------------------------------------------------------------
Thu Jul 6 13:33:05 UTC 2017 - abriel@suse.com
- The following changes are made to accomplish FATE#322066
* Fix typos and improve man page
-------------------------------------------------------------------
Mon May 15 12:40:20 UTC 2017 - abriel@suse.com
- The following changes are made to accomplish FATE#322066
* remove some more files and directories (see man page for detailes)
* add clone-master-clean-up.sysconfig, to give the user the possibillity for minimal intervention
* add custom_remove.template to allow partner or customer specific removals
-------------------------------------------------------------------
Fri Jan 15 12:41:37 UTC 2016 - hguo@suse.com
- The following issues are addressed:
* After wiping swap, the swap gets a new UUID, causing slow boot.
* 70-persistent-net.rules is not removed.
Along with several coding style and indentation fixes.
(bsc#961906)
-------------------------------------------------------------------
Thu Dec 10 15:12:07 UTC 2015 - varkoly@suse.com
- according to comment from Berthold Gunreben in comment #18 in
- FATE#318965 Allow Clone-Master creation, the random-seed files
- need to be deleted, too
-------------------------------------------------------------------
Fri Oct 23 09:05:07 UTC 2015 - hguo@suse.com
- Add clean up item: auto-generated HANA firewall script.
-------------------------------------------------------------------
Mon Sep 14 12:35:46 UTC 2015 - hguo@suse.com
- Initial version, initial release.

View File

@ -0,0 +1,6 @@
name: clone-master-clean-up
scmdir: clone-master-clean-up_service
version: HEAD
mtime: 1565013193
commit: b13528949272fd7cecd04bd07f9e39f9e13363f9

221
clone-master-clean-up.sh Normal file
View File

@ -0,0 +1,221 @@
#!/bin/bash
# The script cleans up a system for cloning preparation.
# Author: Howard Guo <hguo@suse.com>
set -e
# bsc#1092378
DROP_IN_FILE=/etc/clone-master-clean-up/custom_remove
SYSCONF_FILE=/etc/sysconfig/clone-master-clean-up
err_exit() {
echo "Sorry! An error occured on line $1, the clean up routine did not complete successfully."
exit 1
}
trap 'err_exit $LINENO' ERR
[ "$UID" != "0" ] && echo 'Please run this program as root user.' && exit 1
echo 'The script will delete all SSH keys, log data, and more. Type YES and enter to proceed.'
read answer
[ "$answer" != "YES" ] && exit 1
# source config file
if [ -r "$SYSCONF_FILE" ]; then
. "$SYSCONF_FILE"
else
echo 'Failed to read /etc/sysconfig/clone-master-clean-up'
exit 1
fi
echo 'Wiping active swap devices/files (this may take a while)'
while read swap_name discard; do
uuid=$(env $(blkid -o export "$swap_name") printenv UUID)
echo "Turning off swap device/file $swap_name (UUID $uuid)"
swapoff "$swap_name"
echo "Zero-overwriting $swap_name..."
shred -n1 --random-source=/dev/zero "$swap_name"
mkswap "$swap_name" -U "$uuid"
done < <(tail -n+2 /proc/swaps)
echo 'Removing system registration information and zypper repositories'
> /etc/SUSEConnect
find /etc/zypp \( -iname 'suse*' -o -iname 'scc*' \) -delete
echo "Removing zypper anonymous ID"
rm -rf /var/lib/zypp/AnonymousUniqueId
echo 'Removing SSH host keys, user SSH keys, authorized keys, and shell history'
rm -rf /etc/ssh/ssh_host*key* /root/.ssh/* /home/*/.ssh/* /home/*/.*_history &> /dev/null
echo 'Removing all mails and cron-jobs'
rm -rf /var/spool/mail/*
rm -rf /var/spool/cron/{lastrun,tabs}/*
echo "Clean up postfix"
rm -rf /var/spool/postfix/{active,corrupt,deferred,hold,maildrop,saved,bounce,defer,flush,incoming,trace}/*
echo 'Removing all temporary files'
rm -rf /tmp/* /tmp/.* /var/tmp/* /var/tmp/.* &> /dev/null || true
echo 'Clearing log files and removing log archives'
find /var/log -type f -exec truncate -s 0 {} \;
find /var/log \( -iname '*.old' -o -iname '*.xz' -o -iname '*.gz' \) -delete
echo 'Clearing HANA firewall script'
rm -rf /etc/hana-firewall.d/generated_hana_firewall_script
echo 'Removing random seeds'
for seed in /var/lib/systemd/random-seed /var/lib/misc/random-seed; do
[ -f "$seed" ] && rm -f "$seed"
done
echo 'Clearing systemd journal'
pushd /etc/systemd
cp journald.conf journald.conf.bak
echo -e '\nSystemMaxUse=1K' >> journald.conf
systemctl restart systemd-journald
mv journald.conf.bak journald.conf
popd
echo 'Clearing systemd machine ID file'
truncate -s 0 /etc/machine-id
echo 'Removing domain name and set host name from DHCP in network config'
sed -i 's/^NETCONFIG_DNS_STATIC_SEARCHLIST=.*$/NETCONFIG_DNS_STATIC_SEARCHLIST=""/g' /etc/sysconfig/network/config
sed -i 's/^DHCLIENT_SET_HOSTNAME=.*$/DHCLIENT_SET_HOSTNAME="yes"/g' /etc/sysconfig/network/dhcp
echo 'Removing persistent network interfaces'
netudev=/etc/udev/rules.d/70-persistent-net.rules
if [ -f "$netudev" ]; then
if grep -i 'automatically generated' "$netudev" &> /dev/null; then
rm "$netudev"
fi
fi
echo 'Restoring initial system-wide network config'
truncate -s 0 /etc/{hostname,hosts,resolv.conf}
cat << EOF > /etc/hosts
127.0.0.1 localhost
::1 localhost ipv6-localhost ipv6-loopback
fe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
EOF
echo 'Enabling YaST Firstboot if necessary'
[ -e /etc/YaST2/firstboot.xml ] && touch /var/lib/YaST2/reconfig_system
if [ "$CMCU_RSNAP" = "yes" ]; then
if [ -d /.snapshots ]; then
echo "Remove all btrfs snapshots from /.snapshot"
for s in `snapper list | awk '/pre/||/post/{print $3}'`; do
snapper delete $s
done
fi
fi
if [ "$CMCU_ZYPP_REPOS" = "yes" ]; then
echo "Clean up all zypper repositories"
rm -rf /etc/zypp/repos.d/*
fi
if [ "$CMCU_SUDOERS" = "yes" ]; then
echo 'Restoring initial sudoers settings'
cat << EOF > /etc/sudoers
Defaults always_set_home
Defaults env_reset
Defaults env_keep = "LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS XDG_SESSION_COOKIE"
Defaults secure_path="/usr/sbin:/usr/bin:/sbin:/bin"
Defaults !insults
Defaults targetpw
ALL ALL=(ALL) ALL
root ALL=(ALL) ALL
EOF
fi
echo 'Would you like to give root user a new password? Type YES to set a new password, otherwise simply press Enter.'
read answer
[ "$answer" == "YES" ] && passwd root
if [ "$CMCU_EC2" = "yes" ]; then
if curl --connect-timeout 3 '169.254.169.254/latest' &> /dev/null; then
echo 'EC2 specific: allowing ec2-user to run sudo'
echo 'ec2-user ALL=(ALL) ALL' >> /etc/sudoers
echo 'Note to EC2 user:'
echo 'This instance will no longer be accessible after a reboot due to removal of all authorized SSH keys.'
echo "New SSH key will be installed automatically if you create a new instance from this instance's image."
fi
fi
if [ "$CMCU_USERIDS" = "yes" ]; then
echo "clean up user ids >= 1000"
for i in `awk -F ":" '$3 >= 1000 && $1 !~ /nobody/ {print $1}' /etc/passwd`; do
userdel -r $i
done
fi
echo "swap the uuid strings with dev strings in /etc/fstab"
> /tmp/fstab.tmp
while read disk remain; do
case "$disk" in
UUID=*)
uuid=${disk#UUID=}
new_disk=`/usr/sbin/blkid -U $uuid`
;;
LABEL=*)
label=${disk#LABEL=}
new_disk=`/usr/sbin/blkid -L $label`
;;
*)
new_disk="$disk"
;;
esac
echo "$new_disk $remain" >> /tmp/fstab.tmp
done < /etc/fstab
if [ -s /tmp/fstab.tmp ]; then
cp /tmp/fstab.tmp /etc/fstab
fi
rm -rf /tmp/fstab.tmp
echo "Clean up network files (except interfaces using dhcp boot protocol)"
# additional files like bondig interfaces or vlans can be found in
# /var/adm/clone-master-clean-up/custom_remove.template
for intf in `ls -1 /etc/sysconfig/network/ifcfg-eth*`; do
bprot=`grep "^BOOTPROTO=" $intf | sed "s/^BOOTPROTO=//"`
if ! [[ "$bprot" =~ dhcp ]]; then
rm -rf $intf
fi
done
if [ -d /var/lib/wicked ]; then
echo "Clean up persistent network data"
rm -rf /var/lib/wicked/*
fi
echo "Clean up collectd"
rm -rf /var/lib/collectd/WebYaST/*
echo "Clean up /root"
rm -rf /root/.viminfo /root/.bash_history /root/.Xauthority /root/.ICEauthority /root/.xsession-errors* /root/.dbus/session-bus/* /root/.config/* /root/.cache/*
echo "Clean up cache, crash and coredump"
rm -rf /var/cache/*/* /var/crash/* /var/lib/systemd/coredump/*
# checking for 'drop-in' file
if [ -r "$DROP_IN_FILE" ]; then
echo "Remove files and directories found in the drop-in file '$DROP_IN_FILE'"
while read line; do
[[ "$line" =~ ^# ]] && continue
if [ -f "$line" ]; then
rm "$line"
elif [ -d "$line" ]; then
rm -rf "$line"
else
echo "Error: '$line' has wrong format. At the moment only files or directories are supported."
fi
done < $DROP_IN_FILE
fi
echo 'Finished. The system is now sparkling clean. Feel free to shut it down and image it.'

View File

@ -0,0 +1,72 @@
#
# spec file for package clone-master-clean-up
#
# Copyright (c) 2017 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: clone-master-clean-up
Version: 1.4
Release: 0
License: GPL-2.0+
Summary: Clean up a system for cloning preparation
Url: https://www.suse.com
Group: System/Management
Source0: clone-master-clean-up.sh
Source1: clone-master-clean-up.1
Source2: sysconfig.clone-master-clean-up
Source3: custom_remove.template
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Requires: systemd sed curl coreutils
Requires(post): %fillup_prereq
BuildArch: noarch
%if ! %{defined _fillupdir}
%define _fillupdir /var/adm/fillup-templates
%endif
%description
Clean up a system for cloning preparation by cleaning up usage history and log files, etc.
%prep
%build
%install
mkdir -p %{buildroot}%{_sbindir}
install -m700 %{S:0} %{buildroot}/%{_sbindir}/clone-master-clean-up
# manpage
mkdir -p %{buildroot}%{_mandir}/man1
install -m644 %{S:1} %{buildroot}/%{_mandir}/man1/clone-master-clean-up.1
# sysconfig file
mkdir -p %{buildroot}%{_fillupdir}
install -m644 %{S:2} %{buildroot}/%{_fillupdir}/sysconfig.clone-master-clean-up
# template
mkdir -p %{buildroot}/%{_datadir}/%{name}/
install -m644 %{S:3} %{buildroot}/%{_datadir}/%{name}/custom_remove.template
# custom_remove file location
mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/
%post
%fillup_only -n clone-master-clean-up
%files
%defattr(-,root,root)
%{_sbindir}/*
%{_mandir}/man1/*
%config %{_fillupdir}/*
%dir %{_datadir}/%{name}
%dir %{_sysconfdir}/%{name}
%config %{_datadir}/%{name}/custom_remove.template
%ghost %config %{_sysconfdir}/%{name}/custom_remove

74
custom_remove.template Normal file
View File

@ -0,0 +1,74 @@
# It is a difference, if the master system is a plain vanilla installation or
# if additional software is installed, configured and heavily tested and should
# be rolled out later in the whole system landscape.
# So the parts, which need to be cleaned up, are different depending on these
# use cases.
# See some examples for additional needed clean ups below.
#
# Please copy the template file '/var/adm/clone-master-clean-up/custom_remove.template'
# to '/var/adm/clone-master-clean-up/custom_remove' and un-comment the parts
# you need or add additional parts, which will fit your needs.
# Please be careful, the template file will be changed during future package
# updates. So do NOT change the content. It will get lost. Always make changes
# to a copy of the file.
#
# Be in mind:
# At the moment only the removal of files or directories are supported.
# Removing special parts from file content or other special scripting is NOT
# supported
#
# Examples:
#
# If you install a special system management software (like Fujitsus ServerView,
# HPs Insight Management Agents or IMBs Director Agent), you need to clean up
# some log, configuration or database files.
# In most cases these files reside in:
# /etc/<mgmtSW>
# /opt/<Vendor>/<mgmtSW>
# /var/log/<Vendor>
#
# e.g. remove old ServerView Agent Database and other related data
# /etc/srvmagt/{VersionView.sav,VersionView.act,CommonConfig.ccs}
# /etc/srvmagt/VME/var/db/*
# /opt/fujitsu/ServerViewSuite/RAIDManager/bin/*\.xml
# /var/log/srvmagt/log\.
#
#
# Another use case may be the integration of a backup solution into the image
# In this case some files depending to this solution need to be cleaned up.
#
#
# Hardware dependend scenarios
#
# Lika a vendor specific management software for special hardware.
# e.g. OneCommand management software for Avago/Emulex controller hardware.
# Depending on the used version of the software the pathnames may change
# /var/opt/<vendor>/<mgmtSW>/logs/*
# or
# /usr/sbin/<mgmtSW>/*log
#
# e.g
# /usr/sbin/ocmanager/*log
# /var/opt/emulex/ocmanager/logs/*
# /var/opt/emulex/ocmanager/Dump
# /usr/sbin/hbanyware/*log
# /usr/sbin/hbanyware/Dump
# if working with saved adapter parameters
# check /usr/sbin/ocmanager/RMRepository for superfluous entries
#
# or the tools for megaRaid (MegaCli).
# /opt/MegaRAID/MegaCli/*log
#
#
# If the used HBA model has changed, check /etc/hba.conf for superfluous entries.
#
#
# Clean up additional network config files
# e.g. bonding interfaces or vlan interfaces
# /etc/sysconfig/network/ifcfg-{bond,vlan}*
# /etc/sysconfig/network/routes
#
# Room for improvement
#
#

View File

@ -0,0 +1,37 @@
# config file for clone-master-clean-up to allow minimal user intervention
#
#
## Path:
## Type: yesno
## Default: "no"
#
# clean up user ids >= 1000
CMCU_USERIDS="no"
## Path:
## Type: yesno
## Default: "no"
#
# clean up /etc/sudoers
CMCU_SUDOERS="no"
## Path:
## Type: yesno
## Default: "no"
#
# clean up zypper repositories
CMCU_ZYPP_REPOS="no"
## Path:
## Type: yesno
## Default: "yes"
#
# remove btrfs snapshots of root filesystem
CMCU_RSNAP="yes"
## Path:
## Type: yesno
## Default: "no"
#
# allow ec2-user to run sudo
CMCU_EC2="no"