forked from intel/Edge-Software-Provisioner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeusb.sh
executable file
·156 lines (140 loc) · 6.61 KB
/
makeusb.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
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
#!/bin/bash
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
set -u
if [[ $(id -u) -ne 0 ]]; then
echo -e "\e[1m\e[31;1m Please run this script as root \e[0m"
exit 1
fi
# If running from within container change to builder directory
if [ "${BUILDER_PATH:=}" != "" ]; then
cd ${BUILDER_PATH}
fi
source "scripts/textutils.sh"
source "scripts/fileutils.sh"
source "scripts/bulkfileutils.sh"
source "scripts/profileutils.sh"
source "scripts/pxemenuutils.sh"
source "scripts/templateutils.sh"
if [ -f ".env" ]; then
source ".env"
fi
printHelp() {
printMsg "\n Main ${T_BOLD}${C_BLUE}Make USB Script${T_RESET}"
printMsg " You can specify one the following options:"
printMsg " ${T_BOLD}-p${T_RESET}, --profile Build USB bootable image for the specified Profile. The image will be located in data/usr/share/nginx/html/usb/(Profile Name)/. If omitted it will build menu system to select a profile from the USB stick."
printMsg " ${T_BOLD}-b${T_RESET}, --bios Set USB bootable stick to legacy BIOS or EFI, valid options [ efi | bios ]. Defaults to efi."
printMsg " ${T_BOLD}-l${T_RESET}, --bootloader Set USB bootable stick bootloader to IPXE or SYSLINUX, valid options [ ipxe | syslinux ]. Defaults to syslinux."
printMsg " ${T_BOLD}-d${T_RESET}, --dev Path to usb devices, for example '/dev/sdc'. WARNING: this will wipe out the target device. If omitted it will provide instructions how to flash a USB device."
printMsg " ${T_BOLD}-m${T_RESET}, --skip-memory Skip system memory check."
printMsg " ${T_BOLD}-n${T_RESET}, --skip-net Skips network autodetection and verification"
printMsg " ${T_BOLD}-g${T_RESET}, --random Generate a random name for the image."
printMsg " ${T_BOLD}-h${T_RESET}, --help Show this help dialog"
printMsg ""
printMsg " Usage: $0 --profile Clear_Linux --bios efi"
printMsg ""
exit 0
}
export USB_PROFILE=""
export USB_BIOS="efi"
export USB_BOOTLOADER="syslinux"
export USB_DEV=""
export USB_RANDOM="false"
export SKIP_MEMORY="false"
export SKIP_NET="false"
export SINGLE_PROFILE=""
while (( "$#" )); do
case "$1" in
"-p" | "--profile" ) export USB_PROFILE=$2
shift 2;;
"-b" | "--bios" ) export USB_BIOS=$2
shift 2;;
"-l" | "--bootloader" ) export USB_BOOTLOADER=$2
shift 2;;
"-d" | "--dev" ) export USB_DEV=$2
shift 2;;
"-m" | "--skip-memory" ) export SKIP_MEMORY="true"
shift 1;;
"-n" | "--skip-net" ) export SKIP_NET="true"
shift 1;;
"-g" | "--random" ) export USB_RANDOM="true"
shift 1;;
"-v" | "--verbose" ) export VERBOSE="true"
shift 1;;
"-h" | "--help" ) printHelp;;
"--" ) # end argument parsing
shift
break;;
-* | --*= ) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1;;
* ) # preserve positional arguments
PARAMS="$PARAMS $1"
shift;;
esac
done
if [ -n "${USB_PROFILE}" ]; then
validateInput filename "${USB_PROFILE}" "'--profile' value is not a valid profile name: ${USB_PROFILE}"
fi
validateInput custom "${USB_BIOS}" "'--bios' value is not a valid value [bios|efi]: ${USB_BIOS}" "^(bios|efi)$"
if [ -n "${USB_DEV}" ]; then
validateInput dirname "${USB_DEV}" "'--dev' value is not a valid directory name value: ${USB_DEV}"
fi
if [[ "${SKIP_MEMORY}" == "false" ]]; then
if [ $(grep MemTotal /proc/meminfo | awk '{print $2}') -lt 3145728 ]; then
printErrMsg " There is not enough memory available for Makeusb.sh. This system needs 3G or more of RAM."
exit
fi
fi
# Copy flashusb.sh so that is available from the web
cp ./flashusb.sh data/usr/share/nginx/html/
# Incorporate proxy preferences
if [ "${HTTP_PROXY+x}" != "" ]; then
export DOCKER_BUILD_ARGS="--build-arg http_proxy='${http_proxy}' --build-arg https_proxy='${https_proxy}' --build-arg HTTP_PROXY='${HTTP_PROXY}' --build-arg HTTPS_PROXY='${HTTPS_PROXY}' --build-arg NO_PROXY='localhost,127.0.0.1'"
export DOCKER_RUN_ARGS="--env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env HTTP_PROXY=${HTTP_PROXY} --env HTTPS_PROXY=${HTTPS_PROXY} --env NO_PROXY=localhost,127.0.0.1"
export AWS_CLI_PROXY="export http_proxy='${http_proxy}'; export https_proxy='${https_proxy}'; export HTTP_PROXY='${HTTP_PROXY}'; export HTTPS_PROXY='${HTTPS_PROXY}'; export NO_PROXY='localhost,127.0.0.1';"
else
export DOCKER_BUILD_ARGS=""
export DOCKER_RUN_ARGS=""
export AWS_CLI_PROXY=""
fi
printMsg "\n-------------------------"
printMsg " ${T_BOLD}${C_BLUE}Welcome to Make USB${T_RESET}"
printMsg "-------------------------"
logMsg "Welcome to Make USB"
parseConfig
if [[ "${SKIP_NET}" == "true" ]]; then
printBanner "Skipping ${C_GREEN}Network Config Check..."
logMsg "Skipping Network Config Check..."
else
printBanner "Checking ${C_GREEN}Network Config..."
logMsg "Checking Network Config..."
fi
verifyNetworkConfig
printMsg ""
printMsg ""
# Verifiy uOS Images are built, if not run build process
if (docker images | grep uos/kernel > /dev/null 2>&1); then
logMsg "uos/kernel is in the local image database."
else
printBanner "Building ${C_GREEN}Micro OS (uOS)..."
logMsg "Building Micro OS (uOS)..."
source "scripts/buildUOS.sh"
fi
if [[ "${builder_config_disable_uos_wifi-x}" == "true" ]]; then
logMsg "Skipping building Micro OS (uOS)"
else
# Verifiy uOS Images are built, if not run build process
if (docker images | grep uos/wlan > /dev/null 2>&1); then
logMsg "uos/wlan is in the local image database."
else
printBanner "Building ${C_GREEN}Micro OS (uOS)..."
logMsg "Building Micro OS (uOS)..."
source "scripts/buildUOS.sh"
fi
fi
if [ -n "${USB_PROFILE}" ]; then
makeUsbProfile genProfileUsbBoot ${USB_PROFILE}
else
genAllProfileUsbBoot
fi