-
Notifications
You must be signed in to change notification settings - Fork 8
/
clone_release_delete.sh
executable file
·114 lines (103 loc) · 4.41 KB
/
clone_release_delete.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
#
# Licensed under the GNU General Public License Version 3
#
# 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 3 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.
#
# Copyright (c) 2012 Red Hat, Inc
#
# Author : Steven Hardy <[email protected]>
#
#
# DELETE clone release channels and associated kickstarts/activationkeys/config-channels
# This can be used to clean up unused or unwanted clone-releases
#
# Source some common function definitions
. common_functions.sh
if [ $# -lt 1 ]
then
echo "usage : $0 <existing ${RELNAME} clone base channel, e.g ${RELNAME}_5_1.0_rhel-x86_64-server-5>"
exit 1
fi
# First we sanity check the CLI args to ensure they look reasonable
# If check_channel_arg returns, the channel label passed is OK
check_channel_arg $1 "delete"
SRC_CHAN=$1
# Prompt the user for confirmation before proceeding
echo
echo "******************************************************************************"
echo "WARNING : You are about to DELETE clone release ${SRC_CHAN}. "
echo "This will delete the base channel, all child channels, "
echo "along with ALL related kickstart profile, config channel and activation key content."
echo
echo "*** If unsure, DO NOT proceed, this cannot be undone!!! ***"
echo "******************************************************************************"
echo
echo "Type YES to continue"
read response
#echo "got response $response"
if [ "Z${response}" = "ZYES" ]
then
echo "User confirmed, continuing"
else
echo "Operation cancelled by user action"
exit 1
fi
# Delete the kickstart profile(s) matching the release prefix
echo_debug "Looking for kickstarts with the prefix ${KSPREFIX}"
for k in $(spacecmd -- kickstart_list 2>/dev/null | grep ${KSPREFIX})
do
echo_debug "Found kickstart $k, deleting"
echo_debug "spacecmd -y -- kickstart_delete $k 2>/dev/null"
spacecmd -y -- kickstart_delete $k 2>/dev/null
done
# Delete the activation keys matching the expected prefix
echo_debug "Looking for activation keys with the prefix ${AKPREFIX}"
for k in $(spacecmd -- activationkey_list 2>/dev/null | grep ${AKPREFIX})
do
echo_debug "Found activation key $k, deleting"
echo "spacecmd -y -- activationkey_delete $k 2>/dev/null"
spacecmd -y -- activationkey_delete $k 2>/dev/null
done
# Dump the config channels matching the expected prefix
echo_debug "Looking for config channels with the prefix ${CCPREFIX}"
for c in $( spacecmd -- configchannel_list 2>/dev/null | grep ${CCPREFIX})
do
echo_debug "Found config-channel $c, deleting"
echo_debug "spacecmd -y -- configchannel_delete $c 2>/dev/null"
spacecmd -y -- configchannel_delete $c 2>/dev/null
done
# Now the child-channlels
for c in $(spacecmd -- softwarechannel_listchildchannels 2>/dev/null | grep "^${CHANNEL_PREFIX}")
do
echo_debug "Found child-channel $c, deleting"
echo_debug "spacecmd -y -- softwarechannel_delete $c 2>/dev/null"
spacecmd -y -- softwarechannel_delete $c 2>/dev/null
done
# the kickstart-distributions
for k in $(spacecmd -- distribution_list 2>/dev/null | grep "^${CHANNEL_PREFIX}")
do
echo_debug "Found kickstart-distribution $k, deleting"
echo_debug "spacecmd -y -- distribution_delete $k 2>/dev/null"
spacecmd -y -- distribution_delete $k 2>/dev/null
done
# Finally The base-channel (this must be done after the distributions)
echo_debug "Deleting base-channel ${SRC_CHAN}"
echo_debug "spacecmd -y -- softwarechannel_delete ${SRC_CHAN} 2>/dev/null"
spacecmd -y -- softwarechannel_delete ${SRC_CHAN} 2>/dev/null
# If there an export release exists, delete this aswell
echo_debug "Deleting the export release if the directory exists"
echo_debug "test -d /var/satellite/exports/clone_release_exports/${SRC_CHAN} && rm -rf /var/satellite/exports/clone_release_exports/${SRC_CHAN}"
test -d /var/satellite/exports/clone_release_exports/${SRC_CHAN} && rm -rf /var/satellite/exports/clone_release_exports/${SRC_CHAN}