-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdistro2iso
More file actions
executable file
·177 lines (148 loc) · 4.59 KB
/
distro2iso
File metadata and controls
executable file
·177 lines (148 loc) · 4.59 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# /home/tcamuso/bin/distro2iso
#
cmdline=/home/tcamuso/bin/distro2iso
usagestr=$(
cat <<EOF
$(basename $0) distro-dir iso-dir optional-tag
distro-dir : Directory containing the distro tree
iso-dir : Directory that will contain the resulting iso image
optional-tag : Tag to be added to the end of the output filename
Example: $(basename $0) /work/distro-tree /work/iso "foo-test"
Creates a DVD iso image from a RHEL DVD tree. The idea is to use an
existing RHEL released DVD or DVD iso image to create your own custom DVD
iso having different kernel, initrd, drivers or user space applications.
Mount the existing RHEL DVD and copy its contents to a directory where you
can add and delete files in the DVD tree.
This script will use the information in the .treeinfo file at the top of
the DVD tree and a timestamp formatted as YYYYMMDD-hhmm to create a file
name for the new DVD iso image.
\0
EOF
)
usage() {
echo -e "$usagestr"
exit
}
[[ ("$1" == "-h") || ($1 == "--help") ]] && usage
[ $# -ge 2 ] || usage
info () {
[[ "$1" ]] && echo -e "$1"
echo -n "Press any key to continue..."
read -n1
}
#####################
# Error enumerations
#####################
declare notreeinfo=1
declare nodiscinfo=2
errexit() {
local error=$1
local usrstr="$2"
local errstr=""
case $error in
notreeinfo ) errstr=$(printf "%s: has no .treeinfo file." "$usrstr")
;;
nodiscinfo ) errstr=$(printf "%s: has no .discinfo file." "$usrstr")
;;
* ) errstr="Unkown error! Exiting ..."
error=255
;;
esac
printf "\n%s\n" $errstr
exit $error
}
# parse_config()
# $1 - path to config file
# $2 - section name, delimiteed by '[' and ']'
# $3 - parameter name
# $4 - will contain the return value of parameter in section
#
# returns 0 if [section] and name are found, else returns nonzero.
#
parse_config() {
local configfile=$1
local section=$2
local name=$3
local value=$4
local line=0
local text=""
echo "configfile: $configfile"
echo "section: $section"
echo "name: $name"
[[ ${section:0:1} == "[" ]] || section="[$section]"
echo "post processed section: $section"
line=$(grep -F -m1 -n $section $configfile | cut -d':' -f1)
echo "line: $line"
text=$(awk "/$name/ && NR > $line { print; exit }" $configfile)
text=$(echo $text | cut -d'=' -f2-)
text=$(echo $text)
eval $value=$text
}
declare disdir="$1" # directory containing the distro file tree
declare isodir="$2" # directory to receive the iso file
declare userstr="$3"
#declare volid="$3" # Volume ID
#declare volhdr="$4" # Volume Header String
#declare outfile=$5 # the filemane of the resulting iso file
declare tstamp=$(date +"%Y%m%d-%H%M")
declare origdir=$PWD # Save Present Working Directory
declare discinfo="" # first line of the .dicinfo file
declare xmlfile=""
declare treeinfo="" # .treeinfo file in top directory of DVD
[[ ${isodir:(-1)} == '/' ]] || isodir=$isodir"/"
[[ $(which anaconda) ]] || yum install -y anaconda anaconda-core
[[ $(which createrepo) ]] || yum install -y createrepo
cd "$disdir"
[[ -f ".treeinfo" ]] || errexit $notreeinfo "$disdir"
[[ -f ".discinfo" ]] || errexit $nodiscinfo "$disdir"
discinfo=$(head -1 .discinfo)
# Create Volume-ID, Volume Header String, and DVD iso filename
# from the .treeinfo file as follows.
#
# Volume_ID: [product].short-[product].version-[tree].variants-[tree].arch
# Volume_Hdr_Str: $Volume_ID-$tstamp-$userstr"
# DVD_ISO_file: $Volume_Hdr_Str-DVD.iso
#
declare namestr
declare verstrd
declare varstr
declare archstr
parse_config .treeinfo release short namestr
parse_config .treeinfo release version verstr
parse_config .treeinfo tree variant varstr
parse_config .treeinfo tree arch archstr
declare Volume_ID=$namestr-$verstr-$varstr-$archstr
declare Volume_Hdr=$Volume_ID-$tstamp
[[ "$userstr" ]] && Volume_Hdr=$Volume_Hdr-"$userstr"
declare DVD_iso=$Volume_Hdr-"DVD.iso"
echo -e \
"\nCreating DVD iso image:\n" \
" Volume ID : $Volume_ID\n" \
" Volume Header : $Volume_Hdr\n" \
" DVD iso file : $isodir$DVD_iso\n"
echo -n "Press ctrl-C to exit, any other key to continue."
read -n1
cd repodata
xmlfile=$(ls *comps*.xml)
cutxmlfile=$(echo $xmlfile | cut -d'-' -f2-)
# info "xmlfile: $xmlfile\ncut xmlfile: $cutxmlfile"
mv -f $xmlfile $cutxmlfile
cd "$disdir"
# info "$(ls repodata)"
createrepo -u "media://$discinfo#1" -g repodata/$cutxmlfile ./
# info "$(ls -1 repodata/*comp*.xml)"
cd "$origdir"
mkisofs -r -R -J -T -v \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-V "$Volume_ID" \
-A "$Volume_Hdr" \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-x "lost+found" \
-o "$isodir""$DVD_iso" \
"$disdir"
implantisomd5 "$isodir""$DVD_iso"