Skip to content

Commit

Permalink
Copy custom file to /boot when flashing
Browse files Browse the repository at this point in the history
Adds the ability to specify a custom file to be copied to the boot partition when flashing. I use this to write some configuration (docker-compose files and bash scripts) used for my custom host initialization.
  • Loading branch information
flochtililoch committed Feb 17, 2019
1 parent a1aa0ee commit 01eddea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This script can
* copy an optional cloud-init `user-data` and `meta-data` file into the boot partition of the SD image
* copy an optional `config.txt` file into the boot partition of the SD image (eg. to enable onboard WiFi)
* copy an optional `device-init.yaml` or `occidentalis.txt` file into the boot partition of the SD image (for older HypriotOS versions)
* copy an optional custom file into the boot partition of the SD image
* optional set the hostname of this SD image
* optional set the WiFi settings as well
* play a little sound after flashing
Expand Down Expand Up @@ -89,6 +90,7 @@ OPTIONS:
--force|-f Force flash without security prompt (for automation)
--userdata|-u Copy this cloud-init config file to /boot/user-data
--metadata|-m Copy this cloud-init config file to /boot/meta-data
--file|-F Copy this custom file to /boot
```

If no image is specified, the script will try to configure an existing
Expand Down
17 changes: 16 additions & 1 deletion flash
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ OPTIONS:
--force|-f Force flash without security prompt (for automation)
--userdata|-u Copy this cloud-init file to /boot/user-data
--metadata|-m Copy this cloud-init file to /boot/meta-data
--file|-F Copy this file to /boot
If no image is specified, the script will try to configure an existing
image. This is useful to try several configuration without the need to
Expand Down Expand Up @@ -79,6 +80,7 @@ do
--force) args="${args}-f ";;
--userdata) args="${args}-u ";;
--metadata) args="${args}-m ";;
--file) args="${args}-F ";;
# pass through anything else
*) [[ "${arg:0:1}" == "-" ]] || delim="\""
args="${args}${delim}${arg}${delim} ";;
Expand All @@ -87,7 +89,7 @@ done
# reset the translated args
eval set -- "$args"
# now we can process with getopt
while getopts ":h:vc:n:s:p:C:l:d:fu:m:" opt; do
while getopts ":h:vc:n:s:p:C:l:d:fu:m:F:" opt; do
case $opt in
h) usage ;;
v) version ;;
Expand All @@ -101,6 +103,7 @@ while getopts ":h:vc:n:s:p:C:l:d:fu:m:" opt; do
f) FORCE=1 ;;
u) USER_DATA=$OPTARG ;;
m) META_DATA=$OPTARG ;;
F) FILE=$OPTARG ;;
\?) usage ;;
:)
echo "option -$OPTARG requires an argument"
Expand Down Expand Up @@ -501,6 +504,13 @@ if [ -n "${META_DATA}" ]; then
fi
fi

if [ -n "${FILE}" ]; then
if [ ! -f "${FILE}" ]; then
echo "File ${FILE} not found!"
exit 10
fi
fi

if [ -n "${BOOT_CONF}" ]; then
if [ ! -f "${BOOT_CONF}" ]; then
echo "File ${BOOT_CONF} not found!"
Expand Down Expand Up @@ -661,6 +671,11 @@ mount_boot_disk "${disk}" "${boot}"
cp "${META_DATA}" "${boot}/meta-data"
fi

if [ -f "${FILE}" ]; then
echo "Copying file ${FILE} to ${boot}/ ..."
cp "${FILE}" "${boot}/"
fi


if [ -f "${boot}/device-init.yaml" ]; then
echo "Setting device-init"
Expand Down

0 comments on commit 01eddea

Please sign in to comment.