mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-28 13:46:32 +00:00
fwupdate: use double brackets
This commit is contained in:
parent
a2c0bebc03
commit
bebd4f2ac3
@ -26,7 +26,7 @@ function exit_usage() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [[ -z "$1" ]]; then
|
||||||
exit_usage
|
exit_usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ SYS_VERSION_FILE=/etc/version
|
|||||||
SYS_BOARD_FILE=/etc/board
|
SYS_BOARD_FILE=/etc/board
|
||||||
OS_CONF_FILE=/etc/init.d/os_conf
|
OS_CONF_FILE=/etc/init.d/os_conf
|
||||||
|
|
||||||
MIN_FREE_DISK=$((500 * 1024)) # 500 MB
|
MIN_FREE_DISK=500 # MB
|
||||||
VER_FILE=version
|
VER_FILE=version
|
||||||
BOOT_INFO_FILE=boot_info
|
BOOT_INFO_FILE=boot_info
|
||||||
ROOT_INFO_FILE=root_info
|
ROOT_INFO_FILE=root_info
|
||||||
@ -102,14 +102,14 @@ function show_versions() {
|
|||||||
IFS="|"
|
IFS="|"
|
||||||
varr=(${version})
|
varr=(${version})
|
||||||
IFS=${OIFS}
|
IFS=${OIFS}
|
||||||
if [ "${OS_PRERELEASES}" == "false" ] && [ "${varr[1]}" == "true" ]; then
|
if [[ "${OS_PRERELEASES}" == "false" && "${varr[1]}" == "true" ]]; then
|
||||||
continue # skip prereleases
|
continue # skip prereleases
|
||||||
fi
|
fi
|
||||||
if [ "${board}" != "${varr[2]}" ]; then
|
if [[ "${board}" != "${varr[2]}" ]]; then
|
||||||
continue # skip other boards
|
continue # skip other boards
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${show_json}" == "true" ]; then
|
if [[ "${show_json}" == "true" ]]; then
|
||||||
echo "{\"version\": \"${varr[0]}\"," \
|
echo "{\"version\": \"${varr[0]}\"," \
|
||||||
"\"url\": \"${varr[3]}\"," \
|
"\"url\": \"${varr[3]}\"," \
|
||||||
"\"board\": \"${varr[2]}\"," \
|
"\"board\": \"${varr[2]}\"," \
|
||||||
@ -135,17 +135,17 @@ function do_download() {
|
|||||||
mkdir -p ${FW_DIR}
|
mkdir -p ${FW_DIR}
|
||||||
|
|
||||||
# Look for local file first
|
# Look for local file first
|
||||||
if [ -f "$1" ]; then
|
if [[ -f "$1" ]]; then
|
||||||
version="custom"
|
version="custom"
|
||||||
FNAME=`basename $1`
|
FNAME=`basename $1`
|
||||||
FILEEXT=${FNAME##*.}
|
FILEEXT=${FNAME##*.}
|
||||||
DST_FNAME=""
|
DST_FNAME=""
|
||||||
if [ "${FILEEXT}" == "xz" ]; then
|
if [[ "${FILEEXT}" == "xz" ]]; then
|
||||||
DST_FNAME="${FW_DIR}/${FW_FILE_XZ}"
|
DST_FNAME="${FW_DIR}/${FW_FILE_XZ}"
|
||||||
elif [ "${FILEEXT}" == "gz" ]; then
|
elif [[ "${FILEEXT}" == "gz" ]]; then
|
||||||
DST_FNAME="${FW_DIR}/${FW_FILE_GZ}"
|
DST_FNAME="${FW_DIR}/${FW_FILE_GZ}"
|
||||||
fi
|
fi
|
||||||
if [ -n "${DST_FNAME}" ]; then
|
if [[ -n "${DST_FNAME}" ]]; then
|
||||||
cp -f $1 ${DST_FNAME}
|
cp -f $1 ${DST_FNAME}
|
||||||
echo ${version} > ${FW_DIR}/${VER_FILE}
|
echo ${version} > ${FW_DIR}/${VER_FILE}
|
||||||
return
|
return
|
||||||
@ -162,27 +162,27 @@ function do_download() {
|
|||||||
version="custom"
|
version="custom"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${url}" ]; then
|
if [[ -z "${url}" ]]; then
|
||||||
echo "no such version" 1>&2
|
echo "no such version" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
free_disk=$(df /data | tail -n 1 | tr -s ' ' | cut -d ' ' -f 4)
|
free_disk=$(df /data | tail -n 1 | tr -s ' ' | cut -d ' ' -f 4)
|
||||||
if [ "${free_disk}" -lt ${MIN_FREE_DISK} ]; then
|
if [[ "${free_disk}" -lt $((MIN_FREE_DISK * 1024)) ]]; then
|
||||||
echo "not enough disk space" 1>&2
|
echo "not enough disk space" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
outfile=${FW_DIR}/${FW_FILE_GZ}
|
outfile=${FW_DIR}/${FW_FILE_GZ}
|
||||||
format=$(echo ${url} | sed -rn 's/.*\.img\.([a-z]+)$/\1/ p')
|
format=$(echo ${url} | sed -rn 's/.*\.img\.([a-z]+)$/\1/ p')
|
||||||
if [ "${format}" == "xz" ]; then
|
if [[ "${format}" == "xz" ]]; then
|
||||||
outfile=${FW_DIR}/${FW_FILE_XZ}
|
outfile=${FW_DIR}/${FW_FILE_XZ}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ${version} > ${FW_DIR}/${VER_FILE}
|
echo ${version} > ${FW_DIR}/${VER_FILE}
|
||||||
|
|
||||||
curl_opts="-S -f -L"
|
curl_opts="-S -f -L"
|
||||||
if [ -n "${OS_FIRMWARE_USERNAME}" ]; then
|
if [[ -n "${OS_FIRMWARE_USERNAME}" ]]; then
|
||||||
curl_opts+=" --user ${OS_FIRMWARE_USERNAME}:${OS_FIRMWARE_PASSWORD}"
|
curl_opts+=" --user ${OS_FIRMWARE_USERNAME}:${OS_FIRMWARE_PASSWORD}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -191,14 +191,14 @@ function do_download() {
|
|||||||
echo ${pid} > ${FW_DIR}/${CURL_PID_FILE}
|
echo ${pid} > ${FW_DIR}/${CURL_PID_FILE}
|
||||||
wait ${pid}
|
wait ${pid}
|
||||||
|
|
||||||
if [ "$?" != 0 ]; then
|
if [[ "$?" != 0 ]]; then
|
||||||
cat ${FW_DIR}/${CURL_LOG_FILE}
|
cat ${FW_DIR}/${CURL_LOG_FILE}
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_status() {
|
function download_status() {
|
||||||
if [ -f ${FW_DIR}/${CURL_PID_FILE} ]; then
|
if [[ -f ${FW_DIR}/${CURL_PID_FILE} ]]; then
|
||||||
pid=$(cat ${FW_DIR}/${CURL_PID_FILE})
|
pid=$(cat ${FW_DIR}/${CURL_PID_FILE})
|
||||||
if kill -0 ${pid} &>/dev/null; then
|
if kill -0 ${pid} &>/dev/null; then
|
||||||
echo "running"
|
echo "running"
|
||||||
@ -206,7 +206,7 @@ function download_status() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ${FW_DIR}/${FW_FILE_GZ} -o -f ${FW_DIR}/${FW_FILE_XZ} ]; then
|
if [[ -f ${FW_DIR}/${FW_FILE_GZ} -o -f ${FW_DIR}/${FW_FILE_XZ} ]]; then
|
||||||
echo "done"
|
echo "done"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -255,24 +255,24 @@ function do_extract() {
|
|||||||
rm -f ${FW_DIR}/${FW_FILE_EXTR}
|
rm -f ${FW_DIR}/${FW_FILE_EXTR}
|
||||||
rm -f ${FW_DIR}/${BOOT_READY_FILE}
|
rm -f ${FW_DIR}/${BOOT_READY_FILE}
|
||||||
|
|
||||||
if ! [ -f ${FW_DIR}/${FW_FILE_GZ} -o -f ${FW_DIR}/${FW_FILE_XZ} ]; then
|
if ! [[ -f ${FW_DIR}/${FW_FILE_GZ} || -f ${FW_DIR}/${FW_FILE_XZ} ]]; then
|
||||||
echo "firmware file not downloaded" 1>&2
|
echo "firmware file not downloaded" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
format="gz"
|
format="gz"
|
||||||
if [ -f ${FW_DIR}/${FW_FILE_XZ} ]; then
|
if [[ -f ${FW_DIR}/${FW_FILE_XZ} ]]; then
|
||||||
format="xz"
|
format="xz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f ${FW_DIR}/${FW_FILE_EXTR}
|
rm -f ${FW_DIR}/${FW_FILE_EXTR}
|
||||||
rm -f ${FW_DIR}/${GUNZIP_PID_FILE} ${FW_DIR}/${XZCAT_PID_FILE}
|
rm -f ${FW_DIR}/${GUNZIP_PID_FILE} ${FW_DIR}/${XZCAT_PID_FILE}
|
||||||
|
|
||||||
if [ "${format}" == "xz" ]; then
|
if [[ "${format}" == "xz" ]]; then
|
||||||
DECOMPRESS_LOG_FILE=${FW_DIR}/${XZCAT_LOG_FILE}
|
DECOMPRESS_LOG_FILE=${FW_DIR}/${XZCAT_LOG_FILE}
|
||||||
DECOMPRESS_PID_FILE=${FW_DIR}/${XZCAT_PID_FILE}
|
DECOMPRESS_PID_FILE=${FW_DIR}/${XZCAT_PID_FILE}
|
||||||
xzcat ${FW_DIR}/${FW_FILE_XZ} > ${FW_DIR}/${FW_FILE_EXTR} 2>${FW_DIR}/${XZCAT_LOG_FILE} &
|
xzcat ${FW_DIR}/${FW_FILE_XZ} > ${FW_DIR}/${FW_FILE_EXTR} 2>${FW_DIR}/${XZCAT_LOG_FILE} &
|
||||||
elif [ "${format}" == "gz" ]; then
|
elif [[ "${format}" == "gz" ]]; then
|
||||||
DECOMPRESS_LOG_FILE=${FW_DIR}/${GUNZIP_LOG_FILE}
|
DECOMPRESS_LOG_FILE=${FW_DIR}/${GUNZIP_LOG_FILE}
|
||||||
DECOMPRESS_PID_FILE=${FW_DIR}/${GUNZIP_PID_FILE}
|
DECOMPRESS_PID_FILE=${FW_DIR}/${GUNZIP_PID_FILE}
|
||||||
gunzip -k -c ${FW_DIR}/${FW_FILE_GZ} > ${FW_DIR}/${FW_FILE_EXTR} 2>${FW_DIR}/${GUNZIP_LOG_FILE} &
|
gunzip -k -c ${FW_DIR}/${FW_FILE_GZ} > ${FW_DIR}/${FW_FILE_EXTR} 2>${FW_DIR}/${GUNZIP_LOG_FILE} &
|
||||||
@ -285,7 +285,7 @@ function do_extract() {
|
|||||||
echo ${pid} > ${DECOMPRESS_PID_FILE}
|
echo ${pid} > ${DECOMPRESS_PID_FILE}
|
||||||
wait ${pid}
|
wait ${pid}
|
||||||
|
|
||||||
if [ "$?" != 0 ]; then
|
if [[ "$?" != 0 ]]; then
|
||||||
cat ${DECOMPRESS_LOG_FILE}
|
cat ${DECOMPRESS_LOG_FILE}
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -397,14 +397,14 @@ function do_flash_boot() {
|
|||||||
# the /usr/libexec/fw-restore-boot-cfg script, if present, takes the old (backup) boot dir as argument
|
# the /usr/libexec/fw-restore-boot-cfg script, if present, takes the old (backup) boot dir as argument
|
||||||
# and should restore any /boot configuration that needs to be preserved across updates
|
# and should restore any /boot configuration that needs to be preserved across updates
|
||||||
# from the old boot dir to the current (new) /boot dir
|
# from the old boot dir to the current (new) /boot dir
|
||||||
if [ -x /usr/libexec/fw-restore-boot-cfg ]; then
|
if [[ -x /usr/libexec/fw-restore-boot-cfg ]]; then
|
||||||
/usr/libexec/fw-restore-boot-cfg ${FW_DIR}/old_boot 2>/dev/null || true
|
/usr/libexec/fw-restore-boot-cfg ${FW_DIR}/old_boot 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
touch ${FW_DIR}/${BOOT_READY_FILE}
|
touch ${FW_DIR}/${BOOT_READY_FILE}
|
||||||
}
|
}
|
||||||
|
|
||||||
function flash_boot_status() {
|
function flash_boot_status() {
|
||||||
if [ -f ${FW_DIR}/${DD_PID_FILE} ]; then
|
if [[ -f ${FW_DIR}/${DD_PID_FILE} ]]; then
|
||||||
pid=$(cat ${FW_DIR}/${DD_PID_FILE})
|
pid=$(cat ${FW_DIR}/${DD_PID_FILE})
|
||||||
if kill -0 ${pid} &>/dev/null; then
|
if kill -0 ${pid} &>/dev/null; then
|
||||||
echo "running"
|
echo "running"
|
||||||
@ -412,13 +412,13 @@ function flash_boot_status() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ${FW_DIR}/${BOOT_READY_FILE} ]; then
|
if [[ -f ${FW_DIR}/${BOOT_READY_FILE} ]]; then
|
||||||
echo "done"
|
echo "done"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function flash_cleanup() {
|
function flash_cleanup() {
|
||||||
if [ -f /sbin/reboot.bak ]; then
|
if [[ -f /sbin/reboot.bak ]]; then
|
||||||
rm -f /sbin/reboot
|
rm -f /sbin/reboot
|
||||||
mv /sbin/reboot.bak /sbin/reboot
|
mv /sbin/reboot.bak /sbin/reboot
|
||||||
fi
|
fi
|
||||||
@ -481,7 +481,7 @@ function do_flash_reboot() {
|
|||||||
# make the necessary changes to the current boot configuration so that
|
# make the necessary changes to the current boot configuration so that
|
||||||
# the firmware update initramfs will be used by the next boot
|
# the firmware update initramfs will be used by the next boot
|
||||||
mount -o remount,rw /boot
|
mount -o remount,rw /boot
|
||||||
if [ -x /usr/libexec/fw-prepare-boot ]; then
|
if [[ -x /usr/libexec/fw-prepare-boot ]]; then
|
||||||
/usr/libexec/fw-prepare-boot
|
/usr/libexec/fw-prepare-boot
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -507,28 +507,28 @@ function backup_conf() {
|
|||||||
|
|
||||||
function show_status() {
|
function show_status() {
|
||||||
status=$(flash_boot_status)
|
status=$(flash_boot_status)
|
||||||
if [ "${status}" == "running" ]; then
|
if [[ "${status}" == "running" ]]; then
|
||||||
echo "flashing boot $(new_version)"
|
echo "flashing boot $(new_version)"
|
||||||
return
|
return
|
||||||
elif [ "${status}" == "done" ]; then
|
elif [[ "${status}" == "done" ]]; then
|
||||||
echo "boot ready $(new_version)"
|
echo "boot ready $(new_version)"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
status=$(extract_status)
|
status=$(extract_status)
|
||||||
if [ "${status}" == "running" ]; then
|
if [[ "${status}" == "running" ]]; then
|
||||||
echo "extracting $(new_version)"
|
echo "extracting $(new_version)"
|
||||||
return
|
return
|
||||||
elif [ "${status}" == "done" ]; then
|
elif [[ "${status}" == "done" ]]; then
|
||||||
echo "extracted $(new_version)"
|
echo "extracted $(new_version)"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
status=$(download_status)
|
status=$(download_status)
|
||||||
if [ "${status}" == "running" ]; then
|
if [[ "${status}" == "running" ]]; then
|
||||||
echo "downloading $(new_version)"
|
echo "downloading $(new_version)"
|
||||||
return
|
return
|
||||||
elif [ -n "${status}" ]; then
|
elif [[ -n "${status}" ]]; then
|
||||||
echo "downloaded $(new_version)"
|
echo "downloaded $(new_version)"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -569,7 +569,7 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
download)
|
download)
|
||||||
if [ -z "$2" ]; then
|
if [[ -z "$2" ]]; then
|
||||||
exit_usage
|
exit_usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -596,7 +596,7 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
upgrade)
|
upgrade)
|
||||||
if [ -z "$2" ]; then
|
if [[ -z "$2" ]]; then
|
||||||
exit_usage
|
exit_usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user