Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut 4465 update linux command text #623

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------

Expand Down
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