File: drbl-usb-netinstall

package info (click to toggle)
drbl 5.7.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,984 kB
  • sloc: sh: 43,522; perl: 8,820; xml: 867; makefile: 131
file content (235 lines) | stat: -rwxr-xr-x 8,605 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: Download the netinstall kernel & initrd and package them as a zip file for USB flash drive to boot and install GNU/Linux.
# This program only works for syslinux >= 6.0 because the EFI boot is supported from syslinux >= 6.0.

DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
[ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf
[ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions

#
supported_dists="$(LC_ALL=C set | grep -i "_netinstall_ver" | awk -F"_" '{print $1}' | sort | uniq)"
supported_dists="$(echo $supported_dists)" # To make it one line
supported_dists_with_comma="$(echo $supported_dists | sed -e "s/ /, /g")"

USAGE() {
  echo "Download GNU/Linux netinstall kernel and initrd and package them as a zip file for USB flash drive to boot and install GNU/Linux."
  echo "Usage: $0 [OPTION] [DIR]"
  echo "OPTION:"
  echo "-a, --file-name-prefix NAME    Assign the output file name as NAME.zip. $0 will auto append '.zip' in the end of filename."
  echo "-d, --dist DIST:       Create GNU/Linux DIST netinstall zip. DIST is one of these: $supported_dists_with_comma. If this option is not assigned, all the supported GNU/Linux netinstall files will be included."
  echo "-i, --assign-version-no NO  Assign the version number as NO instead of date."
  echo "-s, --syslinux-ver NO  Assign the syslinux version number to be used as NO ."
}

#############
###  MAIN ###
#############
#
# Parse command-line options
while [ $# -gt 0 ]; do
  case "$1" in
    -a|--file-name-prefix)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              target_zip_prefix="$1"
              shift
            fi
	    [ -z "$target_zip_prefix" ] && USAGE && exit 1
            ;;
    -d|--dist)
        shift; mode="install"
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
          GL_INST="$1"
          [ -z "$GL_INST" ] && USAGE && exit 1
	  shift
        fi
	;;
    -i|--assign-version-no)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              version_no="$1"
              shift
            fi
	    [ -z "$version_no" ] && USAGE && exit 1
            ;;
    -s|--syslinux-ver)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              syslinux_ver_no="$1"
              shift
            fi
	    [ -z "$syslinux_ver_no" ] && USAGE && exit 1
            ;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done
#
target_d="$1"

#
check_if_root

# if working dir is not assigned, create one
if [ -z "$target_d" ]; then
  target_d="$(mktemp -d /tmp/netinstall.XXXXXX)"
  echo "Working dir: $target_d"
fi
if [ -z "$GL_INST" ]; then
  GL_INST="all"
else
  # Check if it is in the supported distributions.
  for i in $GL_INST; do
    if [ -z "$(echo $supported_dists | grep -Ew $i)" ]; then
     echo "\"$GL_INST\" is not a supported distribution."
     echo "Supported ones are (case sensitive): $supported_dists."
     exit 1
    fi
  done
fi

[ -z "$version_no" ] && version_no="$(date +%Y%m%d)"
zip_label_tag="${version_no}"
if [ -n "$target_zip_prefix" ]; then
  output_filename="${target_zip_prefix}.zip"
else
  output_filename="linux-netinstall-${zip_label_tag}.zip"
fi
echo "The output file name is: $output_filename."

WD="$(pwd)"
mkdir -p $target_d/syslinux/ $target_d/live/ $target_d/EFI/boot/ $target_d/boot/grub
cp -af $pxelinux_bg_img $target_d/syslinux/
cp -af $pxelinux_bg_img /usr/share/grub/unicode.pf2 $target_d/boot/grub/

echo "The following action will download a lot of network install packages, including these distributions: $GL_INST. This might take a long time..."
echo 'If you want to assign the url, check "netinstall image settings" in drbl.conf.'
drbl-netinstall -w --skip-rerun-gen -i "$GL_INST" -d $target_d/live/

echo "Generating default pxelinux config $target_d/syslinux/syslinux.cfg..."
echo "Adding menus..."
cat <<-PXE_END > $target_d/syslinux/syslinux.cfg
# Created by generate-pxe-menu! Do NOT edit unless you know what you are doing! 
# Keep those comment "MENU DEFAULT" and "MENU HIDE"! Do NOT remove them.
# Note!!! If "serial" directive exists, it must be the first directive
default vesamenu.c32
timeout 70
prompt 0
noescape 1
MENU MARGIN 5
MENU BACKGROUND drblwp.png
# Set the color for unselected menu item and timout message
MENU COLOR UNSEL 7;32;41 #c0000090 #00000000
MENU COLOR TIMEOUT_MSG 7;32;41 #c0000090 #00000000
MENU COLOR TIMEOUT 7;32;41 #c0000090 #00000000
MENU COLOR HELP 7;32;41 #c0000090 #00000000

# MENU MASTER PASSWD

say **********************************************
say Welcome to DRBL.
say NCHC Free Software Labs, Taiwan.
say http://drbl.org; http://drbl.nchc.org.tw
say **********************************************

# Allow client to edit the parameters
ALLOWOPTIONS 1

# simple menu title
MENU TITLE DRBL (http://drbl.org)

PXE_END

# Creating the boot menu, 2 types: for BIOS and EFI
# 1. The boot menu for BIOS machine
# //NOTE// the / in the end of /live/ for -p option is important. Do not remove it. 
# Because we use that in syslinux.cfg like:
# kernel $boot_file_dir$kernel
# append initrd=$boot_file_dir$img $ramdisk_size_opt $extra_append
output_netinstall_boot_menu -p /live/ $target_d/live/ $target_d/syslinux/syslinux.cfg

# Turn on all menus before copying to EFI dir
perl -pi -e "s/^(#|[[:space:]])*MENU HIDE.*/  # MENU HIDE/i" $target_d/syslinux/syslinux.cfg

# 2. The boot menu for EFI machine
# Check if required files exists on this machine
# grub-efi-amd64-signed: /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed
# shim-signed: /usr/lib/shim/shimx64.efi.signed
uefi_boot_support="yes"
if [ -e /usr/lib/shim/shimx64.efi.signed ]; then
  cp -a /usr/lib/shim/shimx64.efi.signed $target_d/EFI/boot/bootx64.efi
else
  echo "File /usr/lib/shim/shimx64.efi.signed not found."
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "uEFI booting not supported!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "On Debian or Ubuntu Linux, you can install it by:"
  echo "apt-get install shim-signed"
  uefi_boot_support="no"
fi
if [ -e /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed ]; then
  cp -a /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed $target_d/EFI/boot/grubx64.efi
else
  echo "File /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed not found."
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "uEFI booting not supported!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "On Debian or Ubuntu Linux, you can install it by:"
  echo "apt-get install grub-efi-amd64-signed"
  uefi_boot_support="no"
fi
if [ ! -d "/usr/lib/grub/i386-efi" ]; then
  echo "File dir /usr/lib/grub/i386-efi not found."
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "uEFI booting for i386 not supported!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "On Debian or Ubuntu Linux, you can install it by:"
  echo "apt-get install grub-efi-ia32-bin"
fi

#
if [ "$uefi_boot_support" = "yes" ]; then
  # Create bootia32.efi. This is for i386 uEFI booting.
  mkdir -p $target_d/tmp-efi
  ocs-gen-grub2-efi-bldr $target_d/tmp-efi/
  rsync -avP $target_d/tmp-efi/bootia32.efi $target_d/EFI/boot/
  rm -rf $target_d/tmp-efi/
  echo -n "Copying /usr/lib/grub/x86_64-efi and /usr/lib/grub/i386-efi to $target_d/boot/grub/..."
  rsync -a /usr/lib/grub/x86_64-efi $target_d/boot/grub/
  rsync -a /usr/lib/grub/i386-efi $target_d/boot/grub/
  echo " done!"
  output_netinstall_boot_menu --efi -u -p /live/ $target_d/live/ $target_d/boot/grub/grub.cfg
fi

echo "Preparing syslinux.exe, syslinux, makeboot.bat and makeboot.sh... "
put_syslinux_makeboot_for_usb_flash $target_d/ "$syslinux_ver_no"

cp -af $DRBL_SCRIPT_PATH/doc/GPL $target_d/

(cd $target_d; zip -r $WD/$output_filename *)
echo "The netinstall file $output_filename was created."

echo "*******************************************************************"
if [ -n "$target_d" -a -d "$target_d" ]; then
  echo "Do you want to remove the downloaded files in dir $target_d?"
  echo -n "[y/N] "
  read rm_files
  case "$rm_files" in
     y|Y|[yY][eE][sS])
       # Some checkings to avoid to remove the /
       if [ -n "$target_d" -a -d "$target_d/syslinux/" -a -f "$target_d/COPYING" ]; then
	  rm -rf $target_d
       fi
       ;;
  esac
fi