104 lines
3.6 KiB
Bash
Executable File
104 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
# Check if Docker is installed
|
|
if ! command -v docker &> /dev/null; then
|
|
echo "Docker is not installed. Please refer to https://docs.docker.com/engine/install/ to install Docker Engine."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if 'switch' container exists
|
|
if docker ps -a --format '{{.Names}}' | grep -q '^switch$'; then
|
|
container_id=$(docker ps -a --format '{{.ID}}' --filter name=switch)
|
|
echo "The 'switch' container already exists. Container ID: $container_id. Installation cannot proceed."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if 'sdm' container exists
|
|
if docker ps -a --format '{{.Names}}' | grep -q '^sdm$'; then
|
|
container_id=$(docker ps -a --format '{{.ID}}' --filter name=sdm)
|
|
echo "The 'sdm' container already exists. Container ID: $container_id. Installation cannot proceed."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if jq is installed
|
|
if ! dpkg -s jq >/dev/null 2>&1; then
|
|
echo "jq package is not installed. Please install it using 'sudo apt-get install jq' and try again."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if openssl is installed
|
|
if ! dpkg -s openssl >/dev/null 2>&1; then
|
|
echo "openssl package is not installed. Please install it using 'sudo apt-get install openssl' and try again."
|
|
exit 1
|
|
fi
|
|
|
|
# Define prompt with retry function
|
|
prompt_with_retry() {
|
|
local prompt=$1
|
|
local max_attempts=$2
|
|
local input
|
|
|
|
for (( i=1; i<=$max_attempts; i++ )); do
|
|
read -p "$prompt" input
|
|
if [[ -n "$input" ]]; then
|
|
echo "$input"
|
|
return 0
|
|
else
|
|
echo "Input cannot be blank. Please try again."
|
|
fi
|
|
done
|
|
|
|
echo "Input cannot be blank. Install terminated."
|
|
exit 1
|
|
}
|
|
|
|
# Prompt user for Aliyun AccessKeyId
|
|
access_key_id=$(prompt_with_retry "Enter Aliyun AccessKeyId: " 3)
|
|
|
|
# Prompt user for Aliyun AccessKeySecret
|
|
access_key_secret=$(prompt_with_retry "Enter Aliyun AccessKeySecret: " 3)
|
|
|
|
# Prompt user for Aliyun appkey
|
|
app_key=$(prompt_with_retry "Enter Aliyun appkey: " 3)
|
|
|
|
# Update values in json files
|
|
jq --arg access_key_id "$access_key_id" '.AccessKeyId = $access_key_id' sdm/data/nls-cloud-sdm/conf/nlstoken.json > tmp.json && mv tmp.json sdm/data/nls-cloud-sdm/conf/nlstoken.json
|
|
jq --arg access_key_secret "$access_key_secret" '.AccessKeySecret = $access_key_secret' sdm/data/nls-cloud-sdm/conf/nlstoken.json > tmp.json && mv tmp.json sdm/data/nls-cloud-sdm/conf/nlstoken.json
|
|
jq --arg app_key "$app_key" '.appkey = $app_key' sdm/data/nls-cloud-sdm/conf/service-asr.json > tmp.json && mv tmp.json sdm/data/nls-cloud-sdm/conf/service-asr.json
|
|
jq --arg app_key "$app_key" '.appkey = $app_key' sdm/data/nls-cloud-sdm/conf/service-tts.json > tmp.json && mv tmp.json sdm/data/nls-cloud-sdm/conf/service-tts.json
|
|
|
|
# Generate ESL password hash
|
|
esl_password=$(openssl rand -hex 8)
|
|
|
|
# Update event_socket.conf.xml file
|
|
sed -i "s/\(<param name=\"password\" value=\"\)[^\"]*\(\"\/>\)/\1$esl_password\2/" switch/conf/autoload_configs/event_socket.conf.xml
|
|
# Update .fs_cli_conf file
|
|
sed -i "s/\(password => \)[^\"]*/\1$esl_password/" switch/.fs_cli_conf
|
|
|
|
# Generate default SIP password hash
|
|
default_password=$(openssl rand -hex 8)
|
|
|
|
# Update vars.xml file
|
|
sed -i "s/\(<X-PRE-PROCESS cmd=\"set\" data=\"default_password=\)[^\"]*\(\"\/>\)/\1$default_password\2/" switch/conf/vars.xml
|
|
|
|
# Extract sounds package
|
|
echo "Extracting sounds package..."
|
|
cd switch/sounds/
|
|
if [[ -f sounds.tar.bz2 ]]; then
|
|
tar -xvjf sounds.tar.bz2
|
|
echo "Sounds package extracted."
|
|
else
|
|
echo "Sounds package not found."
|
|
cd ../..
|
|
exit 1
|
|
fi
|
|
cd ../..
|
|
|
|
# Run docker compose
|
|
docker compose up -d
|
|
|
|
echo "ESL Password: $esl_password"
|
|
echo "Default SIP Password: $default_password"
|
|
echo "Install complete." |