updated imei profile script that causes boot loop when used
This commit is contained in:
@@ -18,8 +18,8 @@ append_error() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Remove the entire quecmanager directory
|
# Remove the entire quecmanager directory
|
||||||
if [ -d "/etc/quecmanager" ]; then
|
if [ -d "/etc/quecmanager/apn_profile/" ]; then
|
||||||
rm -rf /etc/quecmanager
|
rm -rf /etc/quecmanager/apn_profile/
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
append_error "Failed to remove quecmanager directory"
|
append_error "Failed to remove quecmanager directory"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
echo "Content-type: application/json"
|
echo "Content-type: application/json"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
CONFIG_FILE="/etc/quecmanager/apn_config.txt"
|
CONFIG_FILE="/etc/quecmanager/apn_profile/apn_config.txt"
|
||||||
|
|
||||||
if [ ! -f "$CONFIG_FILE" ]; then
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
echo "{}"
|
echo "{}"
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ if [ -z "$iccidProfile1" ] || [ -z "$apnProfile1" ] || [ -z "$pdpType1" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d /etc/quecmanager ]; then
|
if [ ! -d /etc/quecmanager/apn_profile ]; then
|
||||||
mkdir -p /etc/quecmanager
|
mkdir -p /etc/quecmanager/apn_profile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a configuration file to store APN profiles (as plain text)
|
# Create a configuration file to store APN profiles (as plain text)
|
||||||
cat > /etc/quecmanager/apn_config.txt << EOF
|
cat > /etc/quecmanager/apn_profile/apn_config.txt << EOF
|
||||||
iccidProfile1=$iccidProfile1
|
iccidProfile1=$iccidProfile1
|
||||||
apnProfile1=$apnProfile1
|
apnProfile1=$apnProfile1
|
||||||
pdpType1=$pdpType1
|
pdpType1=$pdpType1
|
||||||
@@ -46,7 +46,7 @@ EOF
|
|||||||
|
|
||||||
# Add second profile only if ICCID is provided
|
# Add second profile only if ICCID is provided
|
||||||
if [ -n "$iccidProfile2" ]; then
|
if [ -n "$iccidProfile2" ]; then
|
||||||
cat >> /etc/quecmanager/apn_config.txt << EOF
|
cat >> /etc/quecmanager/apn_profile/apn_config.txt << EOF
|
||||||
iccidProfile2=$iccidProfile2
|
iccidProfile2=$iccidProfile2
|
||||||
apnProfile2=$apnProfile2
|
apnProfile2=$apnProfile2
|
||||||
pdpType2=$pdpType2
|
pdpType2=$pdpType2
|
||||||
@@ -54,13 +54,13 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the apnProfiles.sh script
|
# Create the apnProfiles.sh script
|
||||||
cat > /etc/quecmanager/apnProfiles.sh << 'EOF'
|
cat > /etc/quecmanager/apn_profile/apnProfiles.sh << 'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Function to read config values
|
# Function to read config values
|
||||||
get_config_value() {
|
get_config_value() {
|
||||||
local key=$1
|
local key=$1
|
||||||
grep "^${key}=" /etc/quecmanager/apn_config.txt | cut -d'=' -f2
|
grep "^${key}=" /etc/quecmanager/apn_profile/apn_config.txt | cut -d'=' -f2
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read configuration
|
# Read configuration
|
||||||
@@ -164,15 +164,15 @@ fi
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Make the script executable
|
# Make the script executable
|
||||||
chmod +x /etc/quecmanager/apnProfiles.sh
|
chmod +x /etc/quecmanager/apn_profile/apnProfiles.sh
|
||||||
|
|
||||||
# Add to rc.local if not already present
|
# Add to rc.local if not already present
|
||||||
if ! grep -q "/etc/quecmanager/apnProfiles.sh" /etc/rc.local; then
|
if ! grep -q "/etc/quecmanager/apn_profile/apnProfiles.sh" /etc/rc.local; then
|
||||||
sed -i '/^exit 0/i /etc/quecmanager/apnProfiles.sh' /etc/rc.local
|
sed -i '/^exit 0/i /etc/quecmanager/apn_profile/apnProfiles.sh' /etc/rc.local
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the script immediately
|
# Run the script immediately
|
||||||
/etc/quecmanager/apnProfiles.sh
|
/etc/quecmanager/apn_profile/apnProfiles.sh
|
||||||
|
|
||||||
# Check the result
|
# Check the result
|
||||||
if [ -f /tmp/apn_result.txt ]; then
|
if [ -f /tmp/apn_result.txt ]; then
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ append_error() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Remove the entire quecmanager directory
|
# Remove the entire quecmanager directory
|
||||||
if [ -d "/etc/quecmanager" ]; then
|
if [ -d "/etc/quecmanager/imei_profile/" ]; then
|
||||||
rm -rf /etc/quecmanager
|
rm -rf /etc/quecmanager/imei_profile/
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
append_error "Failed to remove quecmanager directory"
|
append_error "Failed to remove quecmanager directory"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Content-type: application/json"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
CONFIG_FILE="/etc/quecmanager/imei_profile/imei_config.txt"
|
||||||
|
|
||||||
|
if [ ! -f "$CONFIG_FILE" ]; then
|
||||||
|
echo "{}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read the configuration file
|
||||||
|
iccidProfile1=$(grep "^iccidProfile1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||||
|
imeiProfile1=$(grep "^imeiProfile1=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||||
|
iccidProfile2=$(grep "^iccidProfile2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||||
|
imeiProfile2=$(grep "^imeiProfile2=" "$CONFIG_FILE" | cut -d'=' -f2)
|
||||||
|
|
||||||
|
# Build the JSON response
|
||||||
|
echo "{"
|
||||||
|
|
||||||
|
# Add Profile 1 if it exists
|
||||||
|
if [ -n "$iccidProfile1" ]; then
|
||||||
|
echo " \"profile1\": {"
|
||||||
|
echo " \"iccid\": \"$iccidProfile1\","
|
||||||
|
echo " \"imei\": \"$imeiProfile1\""
|
||||||
|
echo " }"
|
||||||
|
# Add comma if Profile 2 exists
|
||||||
|
[ -n "$iccidProfile2" ] && echo " ,"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add Profile 2 if it exists
|
||||||
|
if [ -n "$iccidProfile2" ]; then
|
||||||
|
echo " \"profile2\": {"
|
||||||
|
echo " \"iccid\": \"$iccidProfile2\","
|
||||||
|
echo " \"imei\": \"$imeiProfile2\""
|
||||||
|
echo " }"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "}"
|
||||||
@@ -30,32 +30,32 @@ if [ -z "$iccidProfile1" ] || [ -z "$imeiProfile1" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check the directory if it exists, if not create it
|
# Check the directory if it exists, if not create it
|
||||||
if [ ! -d /etc/quecmanager ]; then
|
if [ ! -d /etc/quecmanager/imei_profile ]; then
|
||||||
mkdir -p /etc/quecmanager
|
mkdir -p /etc/quecmanager/imei_profile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a configuration file to store IMEI profiles
|
# Create a configuration file to store IMEI profiles
|
||||||
cat > /etc/quecmanager/imei_config.txt << EOF
|
cat >/etc/quecmanager/imei_profile/imei_config.txt <<EOF
|
||||||
iccidProfile1=$iccidProfile1
|
iccidProfile1=$iccidProfile1
|
||||||
imeiProfile1=$imeiProfile1
|
imeiProfile1=$imeiProfile1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Add second profile only if ICCID is provided
|
# Add second profile only if ICCID is provided
|
||||||
if [ -n "$iccidProfile2" ]; then
|
if [ -n "$iccidProfile2" ]; then
|
||||||
cat >> /etc/quecmanager/imei_config.txt << EOF
|
cat >>/etc/quecmanager/imei_profile/imei_config.txt <<EOF
|
||||||
iccidProfile2=$iccidProfile2
|
iccidProfile2=$iccidProfile2
|
||||||
imeiProfile2=$imeiProfile2
|
imeiProfile2=$imeiProfile2
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the imeiProfiles.sh script
|
# Create the imeiProfiles.sh script
|
||||||
cat > /etc/quecmanager/imeiProfiles.sh << 'EOF'
|
cat >/etc/quecmanager/imei_profile/imeiProfiles.sh <<'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Function to read config values
|
# Function to read config values
|
||||||
get_config_value() {
|
get_config_value() {
|
||||||
local key=$1
|
local key=$1
|
||||||
grep "^${key}=" /etc/quecmanager/imei_config.txt | cut -d'=' -f2
|
grep "^${key}=" /etc/quecmanager/imei_profile/imei_config.txt | cut -d'=' -f2
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read configuration
|
# Read configuration
|
||||||
@@ -108,6 +108,21 @@ get_current_iccid() {
|
|||||||
echo "$iccid"
|
echo "$iccid"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get current IMEI
|
||||||
|
get_current_imei() {
|
||||||
|
local input_file="/tmp/inputCGSN.txt"
|
||||||
|
local output_file="/tmp/outputCGSN.txt"
|
||||||
|
|
||||||
|
echo "AT+CGSN" > "$input_file"
|
||||||
|
atinout "$input_file" "/dev/$AT_PORT" "$output_file"
|
||||||
|
|
||||||
|
# Extract IMEI from the response, removing any whitespace or newlines
|
||||||
|
imei=$(cat "$output_file" | grep -v "AT+CGSN" | grep -v "OK" | tr -d '\r\n[:space:]')
|
||||||
|
|
||||||
|
rm -f "$input_file" "$output_file"
|
||||||
|
echo "$imei"
|
||||||
|
}
|
||||||
|
|
||||||
# Function to set IMEI
|
# Function to set IMEI
|
||||||
set_imei() {
|
set_imei() {
|
||||||
local imei="$1"
|
local imei="$1"
|
||||||
@@ -127,45 +142,63 @@ set_imei() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get current ICCID
|
# Get current ICCID and IMEI
|
||||||
current_iccid=$(get_current_iccid)
|
current_iccid=$(get_current_iccid)
|
||||||
|
current_imei=$(get_current_imei)
|
||||||
success=false
|
success=false
|
||||||
|
|
||||||
|
echo "Current ICCID: $current_iccid" >> "$DEBUG_LOG"
|
||||||
|
echo "Current IMEI: $current_imei" >> "$DEBUG_LOG"
|
||||||
|
echo "Profile 1 - ICCID: $iccidProfile1, IMEI: $imeiProfile1" >> "$DEBUG_LOG"
|
||||||
|
echo "Profile 2 - ICCID: $iccidProfile2, IMEI: $imeiProfile2" >> "$DEBUG_LOG"
|
||||||
|
|
||||||
# Check ICCID against profile 1 (required)
|
# Check ICCID against profile 1 (required)
|
||||||
if [ "$current_iccid" = "$iccidProfile1" ]; then
|
if [ "$current_iccid" = "$iccidProfile1" ]; then
|
||||||
if set_imei "$imeiProfile1"; then
|
if [ "$current_imei" != "$imeiProfile1" ]; then
|
||||||
|
echo "ICCID matches profile 1, but IMEI needs updating" >> "$DEBUG_LOG"
|
||||||
|
if set_imei "$imeiProfile1"; then
|
||||||
|
success=true
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ICCID and IMEI already match profile 1, no action needed" >> "$DEBUG_LOG"
|
||||||
success=true
|
success=true
|
||||||
fi
|
fi
|
||||||
# Check ICCID against profile 2 (optional)
|
# Check ICCID against profile 2 (optional)
|
||||||
elif [ -n "$iccidProfile2" ] && [ "$current_iccid" = "$iccidProfile2" ]; then
|
elif [ -n "$iccidProfile2" ] && [ "$current_iccid" = "$iccidProfile2" ]; then
|
||||||
if set_imei "$imeiProfile2"; then
|
if [ "$current_imei" != "$imeiProfile2" ]; then
|
||||||
|
echo "ICCID matches profile 2, but IMEI needs updating" >> "$DEBUG_LOG"
|
||||||
|
if set_imei "$imeiProfile2"; then
|
||||||
|
success=true
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ICCID and IMEI already match profile 2, no action needed" >> "$DEBUG_LOG"
|
||||||
success=true
|
success=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$success" = "true" ]; then
|
if [ "$success" = "true" ]; then
|
||||||
echo "IMEI set successfully" > /tmp/imei_result.txt
|
echo "IMEI check/update completed successfully" > /tmp/imei_result.txt
|
||||||
else
|
else
|
||||||
echo "Failed to set IMEI" > /tmp/imei_result.txt
|
echo "Failed to check/update IMEI" > /tmp/imei_result.txt
|
||||||
fi
|
fi
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Make the script executable
|
# Make the script executable
|
||||||
chmod +x /etc/quecmanager/imeiProfiles.sh
|
chmod +x /etc/quecmanager/imei_profile/imeiProfiles.sh
|
||||||
|
|
||||||
# Add to rc.local if not already present
|
# Add to rc.local if not already present
|
||||||
if ! grep -q "/etc/quecmanager/imeiProfiles.sh" /etc/rc.local; then
|
if ! grep -q "/etc/quecmanager/imei_profile/imeiProfiles.sh" /etc/rc.local; then
|
||||||
sed -i '/^exit 0/i /etc/quecmanager/imeiProfiles.sh' /etc/rc.local
|
sed -i '/^exit 0/i /etc/quecmanager/imei_profile/imeiProfiles.sh' /etc/rc.local
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the script immediately
|
# Run the script immediately
|
||||||
/etc/quecmanager/imeiProfiles.sh
|
/etc/quecmanager/imei_profile/imeiProfiles.sh
|
||||||
|
|
||||||
# Check the result
|
# Check the result
|
||||||
if [ -f /tmp/imei_result.txt ]; then
|
if [ -f /tmp/imei_result.txt ]; then
|
||||||
result=$(cat /tmp/imei_result.txt)
|
result=$(cat /tmp/imei_result.txt)
|
||||||
rm -f /tmp/imei_result.txt
|
rm -f /tmp/imei_result.txt
|
||||||
|
|
||||||
if [ "$result" = "IMEI set successfully" ]; then
|
if [ "$result" = "IMEI set successfully" ]; then
|
||||||
echo '{"status": "success", "message": "IMEI profiles saved and applied successfully"}'
|
echo '{"status": "success", "message": "IMEI profiles saved and applied successfully"}'
|
||||||
else
|
else
|
||||||
@@ -173,4 +206,4 @@ if [ -f /tmp/imei_result.txt ]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo '{"status": "error", "message": "Something went wrong while processing IMEI profiles"}'
|
echo '{"status": "error", "message": "Something went wrong while processing IMEI profiles"}'
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user