ยง2024-10-03

  1. The function hook_script defined in 00_install_global_functions_variables.sh
function hook_script {
    echo "#!/bin/bash
git --git-dir=/var/opt/$1.git --work-tree=\"/opt/$1\" checkout "\$3" -f
cd \"/opt/$1\"
rm -rf package-lock.json
npm install --production --no-optional --no-package-lock --no-audit --ignore-scripts --no-shrinkwrap --progress=false
sudo $SYSTEMCTL_PATH restart $1 || echo \"Failed restarting service\"" > "/var/opt/$1.git/hooks/update"
    chmod +x "/var/opt/$1.git/hooks/update"
}

export -f hook_script
    1. Call the Function

Once the function is defined, you can call it with the required arguments. The function takes three parameters:

$1: The name of the project (this will be used to construct paths).
$2: This parameter is not used in the function but could be included for future flexibility.
$3: The branch or commit you want to check out.