Skip to content

Commit

Permalink
update commands.json
Browse files Browse the repository at this point in the history
  • Loading branch information
jworkmanjc committed Nov 27, 2024
1 parent 5005204 commit dab1716
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Commands Gallery/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
},
Expand Down

0 comments on commit dab1716

Please sign in to comment.