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
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
if [[ -z "$1" ]]; then
|
||||
exit_usage
|
||||
fi
|
||||
|
||||
@ -40,7 +40,7 @@ SYS_VERSION_FILE=/etc/version
|
||||
SYS_BOARD_FILE=/etc/board
|
||||
OS_CONF_FILE=/etc/init.d/os_conf
|
||||
|
||||
MIN_FREE_DISK=$((500 * 1024)) # 500 MB
|
||||
MIN_FREE_DISK=500 # MB
|
||||
VER_FILE=version
|
||||
BOOT_INFO_FILE=boot_info
|
||||
ROOT_INFO_FILE=root_info
|
||||
@ -102,14 +102,14 @@ function show_versions() {
|
||||
IFS="|"
|
||||
varr=(${version})
|
||||
IFS=${OIFS}
|
||||
if [ "${OS_PRERELEASES}" == "false" ] && [ "${varr[1]}" == "true" ]; then
|
||||
if [[ "${OS_PRERELEASES}" == "false" && "${varr[1]}" == "true" ]]; then
|
||||
continue # skip prereleases
|
||||
fi
|
||||
if [ "${board}" != "${varr[2]}" ]; then
|
||||
if [[ "${board}" != "${varr[2]}" ]]; then
|
||||
continue # skip other boards
|
||||
fi
|
||||
|
||||
if [ "${show_json}" == "true" ]; then
|
||||
if [[ "${show_json}" == "true" ]]; then
|
||||
echo "{\"version\": \"${varr[0]}\"," \
|
||||
"\"url\": \"${varr[3]}\"," \
|
||||
"\"board\": \"${varr[2]}\"," \
|
||||
@ -135,17 +135,17 @@ function do_download() {
|
||||
mkdir -p ${FW_DIR}
|
||||
|
||||
# Look for local file first
|
||||
if [ -f "$1" ]; then
|
||||
if [[ -f "$1" ]]; then
|
||||
version="custom"
|
||||
FNAME=`basename $1`
|
||||
FILEEXT=${FNAME##*.}
|
||||
DST_FNAME=""
|
||||
if [ "${FILEEXT}" == "xz" ]; then
|
||||
if [[ "${FILEEXT}" == "xz" ]]; then
|
||||
DST_FNAME="${FW_DIR}/${FW_FILE_XZ}"
|
||||
elif [ "${FILEEXT}" == "gz" ]; then
|
||||
elif [[ "${FILEEXT}" == "gz" ]]; then
|
||||
DST_FNAME="${FW_DIR}/${FW_FILE_GZ}"
|
||||
fi
|
||||
if [ -n "${DST_FNAME}" ]; then
|
||||
if [[ -n "${DST_FNAME}" ]]; then
|
||||
cp -f $1 ${DST_FNAME}
|
||||
echo ${version} > ${FW_DIR}/${VER_FILE}
|
||||
return
|
||||
@ -162,27 +162,27 @@ function do_download() {
|
||||
version="custom"
|
||||
fi
|
||||
|
||||
if [ -z "${url}" ]; then
|
||||
if [[ -z "${url}" ]]; then
|
||||
echo "no such version" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
outfile=${FW_DIR}/${FW_FILE_GZ}
|
||||
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}
|
||||
fi
|
||||
|
||||
echo ${version} > ${FW_DIR}/${VER_FILE}
|
||||
|
||||
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}"
|
||||
fi
|
||||
|
||||
@ -191,14 +191,14 @@ function do_download() {
|
||||
echo ${pid} > ${FW_DIR}/${CURL_PID_FILE}
|
||||
wait ${pid}
|
||||
|
||||
if [ "$?" != 0 ]; then
|
||||
if [[ "$?" != 0 ]]; then
|
||||
cat ${FW_DIR}/${CURL_LOG_FILE}
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
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})
|
||||
if kill -0 ${pid} &>/dev/null; then
|
||||
echo "running"
|
||||
@ -206,7 +206,7 @@ function download_status() {
|
||||
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"
|
||||
fi
|
||||
}
|
||||
@ -255,24 +255,24 @@ function do_extract() {
|
||||
rm -f ${FW_DIR}/${FW_FILE_EXTR}
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
format="gz"
|
||||
if [ -f ${FW_DIR}/${FW_FILE_XZ} ]; then
|
||||
if [[ -f ${FW_DIR}/${FW_FILE_XZ} ]]; then
|
||||
format="xz"
|
||||
fi
|
||||
|
||||
rm -f ${FW_DIR}/${FW_FILE_EXTR}
|
||||
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_PID_FILE=${FW_DIR}/${XZCAT_PID_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_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} &
|
||||
@ -285,7 +285,7 @@ function do_extract() {
|
||||
echo ${pid} > ${DECOMPRESS_PID_FILE}
|
||||
wait ${pid}
|
||||
|
||||
if [ "$?" != 0 ]; then
|
||||
if [[ "$?" != 0 ]]; then
|
||||
cat ${DECOMPRESS_LOG_FILE}
|
||||
exit 1
|
||||
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
|
||||
# and should restore any /boot configuration that needs to be preserved across updates
|
||||
# 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
|
||||
fi
|
||||
touch ${FW_DIR}/${BOOT_READY_FILE}
|
||||
}
|
||||
|
||||
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})
|
||||
if kill -0 ${pid} &>/dev/null; then
|
||||
echo "running"
|
||||
@ -412,13 +412,13 @@ function flash_boot_status() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f ${FW_DIR}/${BOOT_READY_FILE} ]; then
|
||||
if [[ -f ${FW_DIR}/${BOOT_READY_FILE} ]]; then
|
||||
echo "done"
|
||||
fi
|
||||
}
|
||||
|
||||
function flash_cleanup() {
|
||||
if [ -f /sbin/reboot.bak ]; then
|
||||
if [[ -f /sbin/reboot.bak ]]; then
|
||||
rm -f /sbin/reboot
|
||||
mv /sbin/reboot.bak /sbin/reboot
|
||||
fi
|
||||
@ -481,7 +481,7 @@ function do_flash_reboot() {
|
||||
# make the necessary changes to the current boot configuration so that
|
||||
# the firmware update initramfs will be used by the next 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
|
||||
fi
|
||||
|
||||
@ -507,28 +507,28 @@ function backup_conf() {
|
||||
|
||||
function show_status() {
|
||||
status=$(flash_boot_status)
|
||||
if [ "${status}" == "running" ]; then
|
||||
if [[ "${status}" == "running" ]]; then
|
||||
echo "flashing boot $(new_version)"
|
||||
return
|
||||
elif [ "${status}" == "done" ]; then
|
||||
elif [[ "${status}" == "done" ]]; then
|
||||
echo "boot ready $(new_version)"
|
||||
return
|
||||
fi
|
||||
|
||||
status=$(extract_status)
|
||||
if [ "${status}" == "running" ]; then
|
||||
if [[ "${status}" == "running" ]]; then
|
||||
echo "extracting $(new_version)"
|
||||
return
|
||||
elif [ "${status}" == "done" ]; then
|
||||
elif [[ "${status}" == "done" ]]; then
|
||||
echo "extracted $(new_version)"
|
||||
return
|
||||
fi
|
||||
|
||||
status=$(download_status)
|
||||
if [ "${status}" == "running" ]; then
|
||||
if [[ "${status}" == "running" ]]; then
|
||||
echo "downloading $(new_version)"
|
||||
return
|
||||
elif [ -n "${status}" ]; then
|
||||
elif [[ -n "${status}" ]]; then
|
||||
echo "downloaded $(new_version)"
|
||||
return
|
||||
fi
|
||||
@ -569,7 +569,7 @@ case "$1" in
|
||||
;;
|
||||
|
||||
download)
|
||||
if [ -z "$2" ]; then
|
||||
if [[ -z "$2" ]]; then
|
||||
exit_usage
|
||||
fi
|
||||
|
||||
@ -596,7 +596,7 @@ case "$1" in
|
||||
;;
|
||||
|
||||
upgrade)
|
||||
if [ -z "$2" ]; then
|
||||
if [[ -z "$2" ]]; then
|
||||
exit_usage
|
||||
fi
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user