Skip to content

Instantly share code, notes, and snippets.

@ilobmirt
Last active August 9, 2021 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilobmirt/f8a0ec11da169557a761fd91dc81664e to your computer and use it in GitHub Desktop.
Save ilobmirt/f8a0ec11da169557a761fd91dc81664e to your computer and use it in GitHub Desktop.
load agps data through modem manager
#!/bin/bash
CURRENTDIR=$(pwd)
AGPS_URL='http://xtrapath1.izatcloud.net/xtra3gr.bin'
AGPS_FILENAME='xtra3gr.bin'
#Verifies if a provided local filename exists. 1=YES 0=NO
#Has one parameter: $1 = Name of the local file
file_exists(){
local DOES_EXIST=0
local FILENAME="$CURRENTDIR/$1"
[ ! -z "$1" ] && DOES_EXIST=1 || DOES_EXIST=0
if [ $DOES_EXIST -gt 0 ]; then
if [ -f "$FILENAME" ]; then
DOES_EXIST=1
else
DOES_EXIST=0
fi
fi
return $DOES_EXIST
}
#Clears old AGPS files, and downloads a fresh copy
#Has no parameters
get_agps_data(){
local IS_SUCCESS=0
echo '========================================='
echo 'Downloading AGPS DATA'
echo '========================================='
file_exists "$AGPS_FILENAME"
if [ $? -gt 0 ]; then
echo '- clearing agps file'
rm "$AGPS_FILENAME"
else
echo '- no existing agps file to clear'
fi
echo '- downloading file'
wget "$AGPS_URL"
if [ $? -eq 0 ]; then
echo '- WGET was successful'
file_exists "$AGPS_FILENAME"
if [ $? -gt 0 ]; then
echo '- got the agps file'
IS_SUCCESS=1
else
echo '- failed to get fresh copy of agps file'
fi
fi
return $IS_SUCCESS
}
#Takes the local AGPS file, and loads it into the modem
#Has one parameter: $1 = Name of the local AGPS file
set_agps_data(){
local IS_SUCCESS=0
local FILENAME="$CURRENTDIR/$1"
echo '========================================='
echo 'Uploading AGPS DATA to MODEM'
echo '========================================='
if [ ! -z "$1" ]; then
file_exists "$AGPS_FILENAME"
if [ $? -gt 0 ]; then
mmcli -G DEBUG
mmcli -m any --location-inject-assistance-data="$FILENAME"
if [ $? -eq 0 ]; then
echo '- AGPS data upload successful!'
IS_SUCCESS=1
else
echo '- AGPS data upload was a failure'
fi
else
echo '- file does not exist to upload'
fi
else
echo '- no filename given to upload'
fi
return $IS_SUCCESS
}
#The actual start of the script
get_agps_data
if [ $? -eq 0 ]; then
exit 0
fi
set_agps_data "$AGPS_FILENAME"
if [ $? -eq 0 ]; then
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment