我一直收到文件结尾错误。我尝试手动检查代码,并尝试了多个在线 bash 检查器,有人能帮忙吗?

我一直收到文件结尾错误。我尝试手动检查代码,并尝试了多个在线 bash 检查器,有人能帮忙吗?

我编写了这个 bash 脚本来将 Web 应用程序自动部署到我的 tomcat 服务器。我一直收到意外的文件结束错误,但代码对我来说似乎没问题。我还尝试了多个在线 bash 语法检查器,它们没有发现任何问题。

我正在使用 Ubuntu 20.04 LTS Hyper-V VM

这是 bash 代码:

#!/bin/bash
CURRENT_DIRECTORY_PATH="$PWD"
PROPS_PATH=$CURRENT_DIRECTORY_PATH/iiq_auto_deployment.properties
certsIIQ_PATH=$CURRENT_DIRECTORY_PATH/certsIIQ
TOMCAT_PATH=$(grep TOMCAT_PATH "$PROPS_PATH" | cut -d= -f2)
WAR_PATH=$(grep WAR_PATH "$PROPS_PATH" | cut -d= -f2)
SERVICE_PATH=$(grep SERVICE_PATH "$PROPS_PATH" | cut -d= -f2)
BACKUP_PATH=$(grep BACKUP_PATH "$PROPS_PATH" | cut -d= -f2)
BACKUP_IIQ=$(grep BACKUP_IIQ "$PROPS_PATH" | cut -d= -f2)
BACKUP_WAR=$(grep BACKUP_WAR "$PROPS_PATH" | cut -d= -f2)
launchIIQConsole=$(grep launchIIQConsole "$PROPS_PATH" | cut -d= -f2)
date=$(date +%d-%m-%Y)
FILECMD_IMPORT=$CURRENT_DIRECTORY_PATH/import_sp_init_custom.txt
IIQPROPERTIES_FILE=/home/centos/Desktop #a enlever
# Check if the passenc file already exists
if [ ! -f "$certsIIQ_PATH/.passenc" ]
then
    # Read user's username and password
    read -r -s -p "Username: " username
    read -r -s -p "Password: " password

    # Generate private key and public key to encrypt/decrypt password
    mkdir "$certsIIQ_PATH"
    sudo openssl genrsa -out "$certsIIQ_PATH"/passwordPrivKey.pem 2048
    sudo openssl rsa -in "$certsIIQ_PATH"/passwordPrivKey.pem -text -noout
    sudo openssl rsa -in "$certsIIQ_PATH"/passwordPrivKey.pem -pubout -out "$certsIIQ_PATH"/passwordPubKey.pem
    sudo openssl rsa -in "$certsIIQ_PATH"/passwordPubKey.pem -pubin -text -noout
    sudo chmod 400 "$certsIIQ_PATH"/passwordPrivKey.pem


    # Save username and password inside a file and encrypt it
    echo "$password" > "$certsIIQ_PATH"/.pass
    echo "$username" > "$certsIIQ_PATH"/.username
    sudo chmod 400 "$certsIIQ_PATH"/.pass
    sudo openssl rsautl -encrypt -inkey "$certsIIQ_PATH"/passwordPubKey.pem -pubin -in "$certsIIQ_PATH"/.pass -out "$certsIIQ_PATH"/.passenc
    rm -f "$certsIIQ_PATH"/.pass    
fi
if [ ! -d "$BACKUP_PATH" ]
then
    mkdir "$BACKUP_PATH"
fi
if [ ! -d "$BACKUP_IIQ" ]
then
    mkdir "$BACKUP_IIQ"
fi
if [ ! -d "$BACKUP_WAR" ]
then
    mkdir "$BACKUP_WAR"
fi
if [ -d "$TOMCAT_PATH" ]
then
    if [ -f "$WAR_PATH" ]
    then
        if [ -f "$SERVICE_PATH" ]
        then
            sudo systemctl stop tomcat
            echo "Le service Apache Tomcat s'est arrete correctement."
            sleep 1.5
            echo "Sauvagarde du dossier IdentityIQ actuel..."
            sleep 1
            sudo mv "$TOMCAT_PATH"/webapps/identityiq "$BACKUP_IIQ"/identityiq.backup"$date"
            echo "Decompression du fichier WAR..."
            sleep 1.5
            sudo unzip -o "$WAR_PATH" -d "$TOMCAT_PATH"/webapps/identityiq
            echo "Decompression du fichier WAR terminee."
            sudo cp $IIQPROPERTIES_FILE/iiq.properties "$TOMCAT_PATH"/webapps/identityiq/WEB-INF/classes #a enlever
            if [ -f "$TOMCAT_PATH/webapps/identityiq/WEB-INF/lib/mssql-jdbc-10.2.1.jre17.jar" ]
            then
                sudo rm "$TOMCAT_PATH"/webapps/identityiq/WEB-INF/lib/mssql-jdbc-10.2.1.jre17.jar 
            fi
            if [ "$launchIIQConsole" == true ]
            then
                if [ ! -f "$FILECMD_IMPORT" ]
                then
                    echo "Creation du fichier temporaire..."
                    echo "import sp.init-custom.xml">"$FILECMD_IMPORT"
                fi
                username=$(cat "$certsIIQ_PATH"/.username)
                password=$(sudo openssl rsautl -decrypt -inkey"$certsIIQ_PATH"/passwordPrivKey.pem -in "$certsIIQ_PATH"/.passenc)
                sudo chmod +x "$TOMCAT_PATH"/webapps/identityiq/WEB-INF/bin/iiq
                echo "IIQ Console is launched!"
                cd "$TOMCAT_PATH"/webapps/identityiq/WEB-INF/bin/ && ./iiq console -u "$username" -p "$password" < "$FILECMD_IMPORT"
            fi
            sudo systemctl start tomcat
            echo "Le service Apache Tomcat a demarre correctement."
            sudo mv "$WAR_PATH" "$BACKUP_WAR"/identityiq.war"$date"
            if [ -f "$FILECMD_IMPORT" ] 
            then
                rm "$FILECMD_IMPORT" 
            fi
            sudo find "$BACKUP_IIQ" -mtime +1 -exec rm -rf {} \;
            sudo find "$BACKUP_WAR" -mtime +1 -exec rm -rf {} \;
            echo "Old files deleted successfully."
        else
            echo "Le fichier $SERVICE_PATH n'existe pas."
        fi
    else
        echo "Le fichier $WAR_PATH n'existe pas."
    fi
else
    echo "Le repertoire $TOMCAT_PATH n'existe pas."
fi

如果有人能帮忙我将不胜感激。谢谢!

相关内容