Added new build options for the build.sh script
This commit is contained in:
parent
d4a8b428f9
commit
4305c12651
87
build.sh
87
build.sh
|
@ -1,5 +1,9 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
##---------------------------
|
||||||
|
## Functions
|
||||||
|
##---------------------------
|
||||||
|
|
||||||
run_sub_stage()
|
run_sub_stage()
|
||||||
{
|
{
|
||||||
log "Begin ${SUB_STAGE_DIR}"
|
log "Begin ${SUB_STAGE_DIR}"
|
||||||
|
@ -142,36 +146,93 @@ run_stage(){
|
||||||
log "End ${STAGE_DIR}"
|
log "End ${STAGE_DIR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##---------------------------
|
||||||
|
## Start Build
|
||||||
|
##---------------------------
|
||||||
|
|
||||||
# Require Root to run
|
# Require Root to run
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "Please run as root" 1>&2
|
echo "Please run as root" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle input options
|
||||||
|
for i in "$@"
|
||||||
|
do
|
||||||
|
case $i in
|
||||||
|
|
||||||
|
--imagename=*)
|
||||||
|
IMG_NAME="${i#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
# Username to use in rootfs
|
||||||
|
--username=*)
|
||||||
|
USER_NAME="${i#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
# Hostname to use in rootfs
|
||||||
|
--password=*)
|
||||||
|
PASS_WORD="${i#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
# Hostname to use in rootfs
|
||||||
|
--hostname=*)
|
||||||
|
HOST_NAME="${i#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
# unknown option
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${IMG_NAME}" ];
|
||||||
|
then
|
||||||
|
echo "No image name specified, defaulting to \"raspbian\""
|
||||||
|
IMG_NAME="raspbian"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$USER_NAME" ]
|
||||||
|
then
|
||||||
|
echo "No username specified, defaulting to \"pi\""
|
||||||
|
USER_NAME="pi"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$PASS_WORD" ]
|
||||||
|
then
|
||||||
|
echo "No username specified, defaulting to \"raspberry\""
|
||||||
|
PASS_WORD="raspberry"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$HOST_NAME" ]
|
||||||
|
then
|
||||||
|
echo "No hostname specified, defaulting to \"raspberrypi\""
|
||||||
|
HOST_NAME="raspberrypi"
|
||||||
|
fi
|
||||||
|
|
||||||
# Source a config file if it exists
|
# Source a config file if it exists
|
||||||
if [ -f config ]; then
|
if [ -f config ]; then
|
||||||
source config
|
source config
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set image name
|
# Set and export other env variables
|
||||||
#TODO: Add way to set this, plus defaults. Defaulting to raspbian for now
|
export USER_NAME
|
||||||
IMG_NAME="raspbian"
|
export HOST_NAME
|
||||||
|
export PASS_WORD
|
||||||
if [ -z "${IMG_NAME}" ]; then
|
export IMG_NAME
|
||||||
echo "IMG_NAME not set" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set other env variables
|
|
||||||
export IMG_DATE=${IMG_DATE:-"$(date -u +%Y-%m-%d)"}
|
|
||||||
|
|
||||||
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
export SCRIPT_DIR="${BASE_DIR}/scripts"
|
export SCRIPT_DIR="${BASE_DIR}/scripts"
|
||||||
export WORK_DIR="${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"
|
export WORK_DIR="${BASE_DIR}/work/${IMG_NAME}"
|
||||||
export LOG_FILE="${WORK_DIR}/build.log"
|
export LOG_FILE="${WORK_DIR}/build.log"
|
||||||
|
|
||||||
export CLEAN
|
export CLEAN
|
||||||
export IMG_NAME
|
|
||||||
export APT_PROXY
|
export APT_PROXY
|
||||||
|
|
||||||
export STAGE
|
export STAGE
|
||||||
|
|
Loading…
Reference in New Issue
Block a user