diff --git a/PowerShell/JumpCloud Commands Gallery/Linux Commands/Linux - Rename System HostName from JumpCloud.md b/PowerShell/JumpCloud Commands Gallery/Linux Commands/Linux - Rename System HostName from JumpCloud.md index 00a768290..3c4ab3f26 100644 --- a/PowerShell/JumpCloud Commands Gallery/Linux Commands/Linux - Rename System HostName from JumpCloud.md +++ b/PowerShell/JumpCloud Commands Gallery/Linux Commands/Linux - Rename System HostName from JumpCloud.md @@ -17,7 +17,7 @@ linux ################################################################################ # Set Read API KEY - Required to read "DisplayName" from console.jumpcloud.com -API_KEY="yourReadWriteAPIKey" +API_KEY="YourReadOnlyAPIKey" # ------- Do not modify below this line ------ diff --git a/PowerShell/JumpCloud Commands Gallery/commands.json b/PowerShell/JumpCloud Commands Gallery/commands.json index 2e9746103..4cb04db06 100644 --- a/PowerShell/JumpCloud Commands Gallery/commands.json +++ b/PowerShell/JumpCloud Commands Gallery/commands.json @@ -44,7 +44,7 @@ { "name": "Linux - Rename System HostName from JumpCloud | v2.0 JCCG", "type": "linux", - "command": "#!/bin/bash\n################################################################################\n# This script will update the system hostname to\n# match the value of this systems displayName in the JumpCloud console.\n# An API Key with read access is required to run this script.\n################################################################################\n\n# Set Read API KEY - Required to read \"DisplayName\" from console.jumpcloud.com\nAPI_KEY=\"yourReadWriteAPIKey\"\n\n# ------- Do not modify below this line ------\n\n# Exit immediately on error\nset -e\n# Functions\nfunction validateVariable() {\n var=$1\n if [[ -z \"$var\" ]]; then\n echo \"Required variable was null, exiting...\"\n exit 1\n else\n echo \"Variable is set to '$var'\"\n fi\n} >&2\n# Get System Key\nfunction getSystemKey() {\n conf=\"$(cat /opt/jc/jcagent.conf)\"\n regex='\\\"systemKey\\\":\\\"[a-zA-Z0-9]{24}\\\"'\n if [[ $conf =~ $regex ]]; then\n systemKey=\"${BASH_REMATCH[@]}\"\n fi\n # echo \"$(date \"+%Y-%m-%dT%H:%M:%S\"): systemKey = $systemKey \"\n regex='[a-zA-Z0-9]{24}'\n if [[ $systemKey =~ $regex ]]; then\n systemID=\"${BASH_REMATCH[@]}\"\n fi\n # echo \"$(date \"+%Y-%m-%dT%H:%M:%S\"): systemID = $systemID \"\n echo \"$systemID\"\n}\nsystemID=$(getSystemKey)\nsearch=$(\n curl -f -X GET https://console.jumpcloud.com/api/systems/${systemID} \\\n -H 'Accept: application/json' \\\n -H 'Content-Type: application/json' \\\n -H \"x-api-key: ${API_KEY}\"\n)\n# regex pattern to search displayNames. This pattern selects the text after \"displayName\":\" and before \",\nregex='(\"displayName\":\")([^\"]*)(\",)'\nif [[ $search =~ $regex ]]; then\n new_hostname=\"${BASH_REMATCH[2]}\"\nfi\n\nold_hostname=$( cat /etc/hostname )\nhostnamectl set-hostname $new_hostname\nsed -i -e \"s/$old_hostname/$new_hostname/g\" /etc/hosts\n\necho \"$old_hostname was renamed to $new_hostname\"\n\nexit 0", + "command": "#!/bin/bash\n################################################################################\n# This script will update the system hostname to\n# match the value of this systems displayName in the JumpCloud console.\n# An API Key with read access is required to run this script.\n################################################################################\n\n# Set Read API KEY - Required to read \"DisplayName\" from console.jumpcloud.com\nAPI_KEY=\"YourReadOnlyAPIKey\"\n\n# ------- Do not modify below this line ------\n\n# Exit immediately on error\nset -e\n# Functions\nfunction validateVariable() {\n var=$1\n if [[ -z \"$var\" ]]; then\n echo \"Required variable was null, exiting...\"\n exit 1\n else\n echo \"Variable is set to '$var'\"\n fi\n} >&2\n# Get System Key\nfunction getSystemKey() {\n conf=\"$(cat /opt/jc/jcagent.conf)\"\n regex='\\\"systemKey\\\":\\\"[a-zA-Z0-9]{24}\\\"'\n if [[ $conf =~ $regex ]]; then\n systemKey=\"${BASH_REMATCH[@]}\"\n fi\n # echo \"$(date \"+%Y-%m-%dT%H:%M:%S\"): systemKey = $systemKey \"\n regex='[a-zA-Z0-9]{24}'\n if [[ $systemKey =~ $regex ]]; then\n systemID=\"${BASH_REMATCH[@]}\"\n fi\n # echo \"$(date \"+%Y-%m-%dT%H:%M:%S\"): systemID = $systemID \"\n echo \"$systemID\"\n}\nsystemID=$(getSystemKey)\nsearch=$(\n curl -f -X GET https://console.jumpcloud.com/api/systems/${systemID} \\\n -H 'Accept: application/json' \\\n -H 'Content-Type: application/json' \\\n -H \"x-api-key: ${API_KEY}\"\n)\n# regex pattern to search displayNames. This pattern selects the text after \"displayName\":\" and before \",\nregex='(\"displayName\":\")([^\"]*)(\",)'\nif [[ $search =~ $regex ]]; then\n new_hostname=\"${BASH_REMATCH[2]}\"\nfi\n\nold_hostname=$( cat /etc/hostname )\nhostnamectl set-hostname $new_hostname\nsed -i -e \"s/$old_hostname/$new_hostname/g\" /etc/hosts\n\necho \"$old_hostname was renamed to $new_hostname\"\n\nexit 0", "link": "https://github.com/TheJumpCloud/support/blob/master/PowerShell/JumpCloud%20Commands%20Gallery/Linux%20Commands/Linux%20-%20Rename%20System%20HostName%20from%20JumpCloud.md", "description": "This script uses a read only API key to gather info about the current system. Using Regex, the code filters out the displayName of a given system and sets the system HostName to the name set in the JumpCloud console." },