文件
android_device_xiaomi_sm845…/qcril_database/generate_db.sh
Arian 3becfcd8cf sm8450-common: Import qcril_database and generate the db at build time
Imported from diting V816.0.7.0.ULFMIXM

Change-Id: I7798bd3c33d3b6f801e8f48a06fe994947715db9
2024-10-06 12:46:15 +02:00

50 行
1.0 KiB
Bash
可执行文件

#!/bin/bash
#
# Copyright (C) 2024 The LineageOS Project
#
# SPDX-License-Identifier: Apache-2.0
#
set -e
if [[ $# -le 2 ]]; then
echo "syntax: generate_db.sh sqlite3 target_db sql_file0 sql_file1..."
exit 1
fi
SQLITE=$1
if [[ ! -x "$SQLITE" ]]; then
echo "sqlite binary not found or not executable: $SQLITE"
exit 1
fi
TARGET_DB=$2
shift 2
# Split the config sql and ecc sql files
for file in "$@"; do
if [[ $file == *_config.sql ]]; then
CONFIG_SQL_FILES+=("$file")
else
ECC_SQL_FILES+=("$file")
fi
done
# Sort the files
IFS=$'\n' CONFIG_SQL_FILES=($(sort -V <<< "${CONFIG_SQL_FILES[*]}"))
IFS=$'\n' ECC_SQL_FILES=($(sort -V <<< "${ECC_SQL_FILES[*]}"))
unset IFS
# Config migrations should be applied after ecc migrations
ORDERED_MIGRATIONS=("${ECC_SQL_FILES[@]}" "${CONFIG_SQL_FILES[@]}")
rm -f "$TARGET_DB"
{
echo "BEGIN TRANSACTION;"
for file in "${ORDERED_MIGRATIONS[@]}"; do
cat "$file"
done
echo "COMMIT TRANSACTION;"
} | $SQLITE "$TARGET_DB"