Shell solves a competitive problem

I have the following script upgrade.sh. The front-end page is called through php, but multiple pages can be called at the same time. For example, when upgrading, the php side executes-- download, which can be canceled before download, and then install_pkg is called after download is completed. How can the package under download be stored to avoid concurrent logic?

after I call. / upgrade.sh-- download on the php side, I write the path of the downloaded pkg package (including the file name) to a fixed file, store the downloaded package in a random directory, and then php calls. / upgrade.sh-- install to install. During installation, I execute-- install to get our saved pkg path information, and then to install it.

the script needs to be called twice, separately because it supports canceling the upgrade. If it is written in a process, it is impossible to cancel the upgrade.

because php is called twice, singleton mode cannot be used. If you only need to call it once, you can call it only once at the same time through a singleton implementation. I have been tortured by this question all day and written in a mess. I hope you can give me some comments.

function main()
{
    if [ "$1" == "--download" ]; then
        download_pkg 
    elif [ "$1" == "--install" ]; then
        install_pkg      
    else
        usage
    fi
}
main $@
Jul.12,2022
Menu