File: bootcd-check.lib

package info (click to toggle)
bootcd 6.9.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 520 kB
  • sloc: sh: 1,940; makefile: 49
file content (374 lines) | stat: -rwxr-xr-x 11,513 bytes parent folder | download | duplicates (2)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# vim: set filetype=sh :
#        file: /usr/share/bootcd/bootcd-check.lib
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2001-2020)
#     license: GNU General Public License, version 3
# description: bootcd-check.lib - functions needed by bootcd scripts

warn_user()
{
  local answer
  if ! [ "$yes" ] && [ "$CLEAN_VAR" = "yes" ]; then
    answer="$(ia_ask "/var/cache/apt will be cleaned (apt-get clean) !" "" "" \
      "Ok to continue? (y/n) " "^(y|n)$")"
    if ! [ "$answer" = "y" ]; then
      exit 1
    fi
  fi
}

check_config()
{
  local CONFVARS PROBLEM i n r
  CONFVARS=""

  PROBLEM="The image destination $VAR/cdimage.iso exists.
Delete $VAR/cdimage.iso and try again!"
  if [ -e $VAR/cdimage.iso ] ; then
    err "$PROBLEM"
  fi

  SRCDISK="$(realpath $SRCDISK)"
  [ $? -ne 0 ] && err "Wrong Definition of SRCDISK: See $ia_logfile"
  SRCDI="$SRCDISK"; [ "$SRCDI" = "/" ] && SRCDI=""
  CONFVARS="$CONFVARS SRCDI"

  dbg "check_config  in: NOT_TO_CD(eval)=<$NOT_TO_CD>"
  eval "set -- $NOT_TO_CD"
  n="$#"
  for i in "$@"; do
    r="$(realpath -s "$i")"
    [ $? -eq 0 ] && set -- "$@" "$r" ||
      warn "Wrong Definition of NOT_TO_CD path=<$i> See $ia_logfile"
  done
  shift "$n"
  NOT_TO_CD="$(ia_set2var "$@")"
  dbg "check_config out: NOT_TO_CD(eval)=<$NOT_TO_CD>"

  eval "set -- $KERNEL"
  [ $# -eq 1 ] || err "Wrong Definition of KERNEL ($# KERNELs instead of 1 KERNEL)"
  KERNEL="$(realpath "$1")"
  [ $? -eq 0 ] || err "Wrong Definition of KERNEL=<$KERNEL> not found"

  KCONF=$(echo $KERNEL | sed "s/vmlinu./config/")
  [ "$KCONF" = "$KERNEL" -o ! -f "$KCONF" ] && KCONF=""

  REL_KERNEL=$(echo "$KERNEL" | sed "s|^$SRCDI||")
  CONFVARS="$CONFVARS REL_KERNEL"

  if [ "$INITRD" != "" ]; then
    eval "set -- $INITRD"
    [ $# -eq 1 ] || err "Wrong Definition of INITRD(eval)=<$INITRD> ($# INITRDs instead of 1 INITRD)"
    INITRD=$(realpath "$1")
    if [ $? -ne 0 ]; then
      warn "INITRD=<$1> not found, INITRD will be set to \"\""
      INITRD=""
    fi
  fi

  REL_INITRD=$(echo "$INITRD" | sed "s|^$SRCDI||")
  CONFVARS="$CONFVARS REL_INITRD"

  [ "$DISPLAY" ] && [ ! -f $DISPLAY ] && warn "DISPLAY ($DISPLAY) not found."

  if [ "$BOOTCDMODPROBE" != "standard" -a "$BOOTCDMODPROBE" != "bootcd" -a "$BOOTCDMODPROBE" != "auto" ]
  then
    warn 'BOOTCDMODPROBE is not defined as "standard", "bootcd" or "auto".' \
         'It will be treated as "auto".'
    BOOTCDMODPROBE="auto"
  fi

  if [ "$BOOTCDMODPROBE" = "auto" ]; then
    if [ -f /sbin/discover -o -f /bin/discover -o -f /usr/bin/discover ]; then
      BOOTCDMODPROBE="bootcd"
    else
      BOOTCDMODPROBE="standard"
    fi
  elif [ "$BOOTCDMODPROBE" = "bootcd" ]; then
    if [ ! -f /sbin/discover -a ! -f /bin/discover -a ! -f /usr/bin/discover ]; then
      warn "BOOTCDMODPROBE=bootcd is defined, but discover is not installed."
    fi
  fi

  CDDEV1=$(echo $CDDEV | gawk '{print $1}')
  CDDEVR=$(echo $CDDEV | gawk '{$1=""; print}')
  CONFVARS="$CONFVARS CDDEV1 CDDEVR"

  if [ "$DO_CHECK" != "no" -a "$DO_CHECK" != "yes" ]; then
    DO_CHECK=yes
    warn 'DO_CHECK is not defined as "yes" or "no".' \
         'It will be treated as "yes".'
  fi

  [ "$DO_CHECK" = "yes" ] &&
    info "--- Checking for possible Problems ---"

  if [ "$TYP" != "CD" -a "$TYP" != "DVD" ]; then
    err "TYP must be defined as \"CD\" or \"DVD\" (not \"$TYP\")."
  fi

  CONFVARS="$CONFVARS CHANGES"

  VERSION="$(dpkg-query -W -f='${Version}\n' bootcd)"
  CONFVARS="$CONFVARS VERSION"

  log "--- CONFVARS checked by check_config ---"
  for i in $CONFVARS; do
    eval "echo $i \$$i"
  done | sort | log
}

get_sizes()
{
  [ "$DO_CHECK" = "no" ] && return
  S_NOT_TO_CD=0
  [ "$NOT_TO_CD" ] && S_NOT_TO_CD=$(eval "du_dir $NOT_TO_CD \"$ia_logfile\" \"$SRCDI/tmp\"")
  dbglog "S_NOT_TO_CD=<$S_NOT_TO_CD>"

  S_CD_ALL=$(eval "du_dir $SRCDISK $NOT_TO_CD \"$ia_logfile\" \"$SRCDI/tmp\"")
  dbglog "S_CD_ALL=<$S_CD_ALL>"

  S_NEED_CD=$(expr $S_CD_ALL - $S_NOT_TO_CD)
  S_VAR=$(df_file $VAR)
  dbglog "S_VAR=<$S_VAR>"

  S_NEED_COMPRESS=$(expr $S_NEED_CD \* 2)
  dbglog "S_NEED_COMPRESS=<$S_NEED_COMPRESS>"

  if [ "$TYP" = "DVD" ]; then
    S_CD="4700000"
  else
    S_CD=$(expr 1024 \* 650)
  fi
  dbglog "S_CD=<$S_CD>"
}

check_file_rc()
{

  PROBLEM="You have installed the debian package file-rc on the system you want to
copy on cd. The file-rc package provides an alternative mechanism to boot the
system, to shut it down and to change runlevels. The /etc/rc?.d/* links
will be converted into one single configuration file /etc/runlevel.conf...

Therefore scripts in /etc/rcS.d added by bootcdwrite are not executed during
booting from CD.

To slolve the problem, please deinstall file-rc on the system you want to
copy on cd."
  [ "$(dpkg-query -W -f='${db:Status-Status}' file-rc 2>/dev/null)" = "installed" ] && warn "$PROBLEM" || :
}

check_compress()
{
  PROBLEM="
to create a compressed filesystem we need the command mkzftree.
this command is included in the debian package mkisofs since
Version 4:2.0-2 or in package genisoimage."
  if [ ! -f /usr/bin/mkzftree ]; then
    warn "command mkzftree not found.$PROBLEM"
  fi


  PROBLEM="
To enable compression there must be much space (S_VAR)
available in $VAR to hold extra space for compression.
We need double as much space (S_NEED_COMPRESS) as will be copied to CD.
but the space available is not enough"
  if [ "$DO_CHECK" = "yes" ]; then
    if [ "$S_VAR" = "" ]; then
      warn "Couldn't guess size of \"$VAR\" with df so assume enought space is available! (Press \"i\")"
    elif [ $S_NEED_COMPRESS -gt $S_VAR ]; then
      warn "S_NEED_COMPRESS > S_VAR ($S_NEED_COMPRESS > $S_VAR) $PROBLEM"
    fi
  fi

  PROBLEM="
To enable compression some options have to be compiled in the
kernel. Only with the necessary options the kernel is able to boot from the
compressed CD/DVD."
  if [ "$KCONF" ]; then
    for i in \
      "CONFIG_ZISOFS=$([ "$INITRD" ] && echo "[my]" || echo y)" \
      "CONFIG_ZISOFS_FS=$([ "$INITRD" ] && echo "[my]" || echo y)"
    do
      # Only if Option is available (with or without #) do anything
      grep -q "$i" $KCONF
      if [ $? = 0 ]; then
        # Now that we know the Option is available, check if configured
        grep -q "^$i" $KCONF
        if [ $? != 0 ]; then
          warn "$i seems not to be configured in $KERNEL$PROBLEM"
        fi
      fi
    done
  fi
}

check_cdfiles()
{
  [ "$DO_CHECK" = "no" ] && return

  PROBLEM="
This file or directory will be created in the next step by bootcdwrite.
Please remove the actual file. You are probably trying to use bootcdwrite
on a system created with bootcd2disk."
  for i in cdboot.img cdboot.catalog \
    usr/bin/bootcdflopcp usr/bin/bootcdflopcp \
    rr_moved ram1.cpio.gz ram2.cpio.gz isolinux
  do
    [ -e $SRCDI/$i ] && warn "found $SRCDI/$i$PROBLEM"
  done
  :
}

# check_kernel - Try to make some kernel checks
check_kernel()
{
  [ "$DO_CHECK" = "no" ] && return

  PROBLEM="
If you install a kernel from a .deb package the kernel will be named
/boot/vmlinuz<version> and there will be a kernel config file named
/boot/config<version>. Bootcdwrite could not find the config file and
therefore no further kernel checks could be done. This is not critical
but you could build your kernel with make-kpkg to solve the problem.
Please read the FAQ to check if you have build erverything necessary in
your kernel."

  if [ ! "$KCONF" ]; then
    warn "Could not calculate Kernelconfig to make further checks.$PROBLEM"
    return
  fi

  PROBLEM="
To run bootcd some features have to be compiled in the kernel.
Please read the FAQ and check if all necessary features are enabled."
  for i in \
    "^\(CONFIG_AUFS_FS\|CONFIG_OVERLAY_FS\)=[my]" \
    "^CONFIG_BLK_DEV_RAM=[my]" \
    "^CONFIG_BLK_DEV_LOOP=[my]" \
    "^CONFIG_TMPFS=[my]"
  do
    grep -q "$i" $KCONF
    [ $? != 0 ] && warn "$i seems not to be configured in $KERNEL$PROBLEM"
  done

  if [ "$BOOTFLOPPY" = "yes" ]; then
    PROBLEM="
You have configured BOOTFLOPPY=yes.
To boot from floppy with syslinux you need some additional features
compiled in the kernel. Please read the FAQ and check if all necessary
features are enabled."

    for i in \
      "^CONFIG_FAT_FS=y" \
      "^CONFIG_MSDOS_FS=y" \
      "^CONFIG_VFAT_FS=y"
    do
      grep -q "$i" $KCONF
      [ $? != 0 ] && warn "$i seems not to be configured in $KERNEL$PROBLEM"
    done
  fi

#  PROBLEM="
#The KERNEL has to be in SRCDISK subdir. Please edit bootcdwrite.conf."
#  [ "$(echo "$KERNEL" | grep "^$SRCDI/")" ] ||
#    warn "$KERNEL is not in $SRCDI/ subdir.$PROBLEM"
#
#  A=$(chnglist -no_mnt -rel "$SRCDISK" "$KERNEL")
#  B="$SRCDI/vmlinuz"
#  PROBLEM="
#There should be a symbolic link
#$B -> /$A.
#Bootcd2disk can later use this link to automatically install
#the kernel to the new disk. Please create the link with
#\"ln -sf /$A $B\"."
#  [ "$(/bin/ls -l $B 2>&1 | grep -e "-> /\?$A$")" ] || warn "$PROBLEM"

  if [ "$INITRD" = "" ]; then
    PROBLEM="
To run bootcd (without INITRD) some features have to be compiled in the
kernel. Please read the FAQ and check if all necessary features are enabled."
    for i in \
      "^CONFIG_ISO9660_FS=y" \
      "\(^CONFIG_EXT2_FS=y\)\|\(CONFIG_EXT4_USE_FOR_EXT23\?=y\)" \
      "^CONFIG_BLK_DEV_LOOP=[my]"
    do
      grep -q "$i" $KCONF
      [ $? != 0 ] && warn "$i seems not to be configured in $KERNEL$PROBLEM"
    done
  else
    PROBLEM="
You have configured INITRD=\"$INITRD\".
The kernel has to be configured for this to work."

    for i in \
      "^CONFIG_ISO9660_FS=[my]" \
      "\(^CONFIG_EXT2_FS=[my]\)\|\(CONFIG_EXT4_USE_FOR_EXT23\?=y\)" \
      "^CONFIG_BLK_DEV_INITRD=y"
    do
      grep -q "$i" $KCONF
      [ $? != 0 ] && warn "$i seems not to be configured in $KERNEL$PROBLEM"
    done
  fi

  return 0
}

check_sizes()
{
  [ "$DO_CHECK" = "no" ] && return

  info "--- Sizes in KByte (du -klsc ) ---"

  info "NOT_TO_CD =  . . . . . . . . . . . . . . . . . . . . . . . . . . . $S_NOT_TO_CD"
  info "CD_ALL (SRCDISK v NOT_TO_CD) = . . . . . . . . . . . . . . . . . . $S_CD_ALL"
  info "Needed = CD_ALL - NOT_TO_CD  . . . . . . . . . . . . . . . . . . . $S_NEED_CD"

  if [ "$TYP" = "DVD" ]; then
    info "DVD+ (4.7 billion bytes) = . . . . . . . . . . . . . . . . . . . . $S_CD"
  else
    info "CD (650 MB) =  . . . . . . . . . . . . . . . . . . . . . . . . . . $S_CD"
  fi

  S_CD=$(expr $S_CD \* 2)
  info "because of compression perhaps double size = . . . . . . . . . . . $S_CD"

  PROBLEM="SRCDISK does not fit on $TYP (Needed > $TYP)"
  if [ "$TYP" = "CD" ]; then
    PROBLEM="$PROBLEM
You can specify TYP=DVD instead of TYP=CD in bootcdwrite.conf."
  fi
  PROBLEM="$PROBLEM
You can exclude files/dirs in NOT_TO_CD in bootcdwrite.conf.
You can try to ignore this problem, if you only want an iso image."

  if [ $S_NEED_CD -gt $S_CD ]; then
    warn "$PROBLEM"
  else
    info "OK - SRCDISK does fit on $TYP (Needed <= $TYP)"
  fi

  info "VAR =  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . $S_VAR"
  if [ "$S_VAR" = "" ]; then
    warn "Could not guess the size of \"$VAR\" with df so assume enought space is available!"
  elif [ $S_NEED_CD -gt $S_VAR ]; then
    warn "Not enough space in $VAR (Needed > VAR)"
  else
    info "OK - enough space in $VAR (Needed <= VAR)"
  fi
}

check_locatedb()
{
  LOCATEDB=""
  for i in $SRCDISK/var/cache/locate/locatedb \
           $SRCDISK/var/lib/locate/locatedb \
	   $SRCDISK/var/lib/locate/slocatedb
  do
    if [ -f $i ]; then
      LOCATEDB="$i"
      break
    fi
  done
}