v1.2.0 = Add check to verify/create folder

+ Added a check to verify and create the `licenses` folder if it doesn't exist -- popped up with R2021a
+ Setting file permissions
+ Updated style and other improvements
This commit is contained in:
Zack T
2021-04-19 18:03:26 -07:00
parent eb1cad30f2
commit 7ae99e32ab

View File

@@ -3,9 +3,9 @@
###################################################################################################
# Script Name: license_Matlab.sh
# By: Zack Thompson / Created: 1/10/2018
# Version: 1.1.1 / Updated: 4/2/2018 / By: ZT
# Version: 1.2.0 / Updated: 4/19/2021 / By: ZT
#
# Description: This script applies the license for Matlab applications.
# Description: This script applies the license for Matlab.
#
###################################################################################################
@@ -15,44 +15,64 @@ echo "***** License Matlab process: START *****"
# Define Variables
# Find all instances of Matlab
appPaths=$(/usr/bin/find /Applications -iname "Matlab*.app" -maxdepth 1 -type d)
app_paths=$( /usr/bin/find /Applications -iname "Matlab*.app" -maxdepth 1 -type d )
# Verify that a Matlab version was found.
if [[ -z "${appPaths}" ]]; then
if [[ -z "${app_paths}" ]]; then
echo "A version of Matlab was not found in the expected location!"
echo "***** License Matlab process: FAILED *****"
exit 1
else
# If the machine has multiple Matlab Applications, loop through them...
while IFS="\n" read -r appPath; do
while IFS=$'\n' read -r app_path; do
# Get the Matlab version
appVersion=$(/bin/cat "${appPath}/VersionInfo.xml" | /usr/bin/grep release | /usr/bin/awk -F "<(/)?release>" '{print $2}')
echo "Applying License for Version: ${appVersion}"
# shellcheck disable=SC2002
app_version=$( /bin/cat "${app_path}/VersionInfo.xml" | /usr/bin/grep release | /usr/bin/awk -F "<(/)?release>" '{print $2}' )
echo "Applying License for Version: ${app_version}"
# Build the license file location
licenseFile="${appPath}/licenses/network.lic"
license_folder="${app_path}/licenses"
license_file="${license_folder}/network.lic"
if [[ ! -d "${license_folder}" ]]; then
# shellcheck disable=SC2174
/bin/mkdir -p -m 755 "${license_folder}"
/usr/sbin/chown root:admin "${license_folder}"
fi
##################################################
# Create the license file.
echo "Creating license file..."
/bin/cat > "${licenseFile}" <<licenseContents
/bin/cat > "${license_file}" <<licenseContents
SERVER license.server.com 11000
USE_SERVER
licenseContents
if [[ -e "${licenseFile}" ]]; then
if [[ -e "${license_file}" ]]; then
# Set permissions on the file for everyone to be able to read.
echo "Applying permissions to license file..."
/bin/chmod 644 "${licenseFile}"
/bin/chmod 644 "${license_file}"
/usr/sbin/chown root:admin "${license_file}"
else
echo "ERROR: Failed to create the license file!"
echo "***** License Matlab process: FAILED *****"
exit 2
fi
done < <(echo "${appPaths}")
done < <(echo "${app_paths}")
fi
echo "Matlab has been activated!"