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

Dinger1986 mesh name to initial #1807

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions api/tacticalrmm/clients/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def post(self, request):
core = get_core_settings()
core.default_time_zone = request.data["timezone"]
core.save(update_fields=["default_time_zone"])
# add in mesh company name
if "mesh_company_name" in request.data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. no need to create a separate if block because we already have one to check if this is being called from initialsetup
  2. request.data["mesh_company_name"] wont' work because on the frontend you are setting the variable to companyname not mesh_company_name
  3. update_fields_list variable doesn't exist anywhere so you're trying to append to a non existing variable
  4. no call to save in your new if block so even if it was right, would not actually get saved to db

here is how we can make it work using the existing if block:

if "initialsetup" in request.data.keys():
    core = get_core_settings()
    core.default_time_zone = request.data["timezone"]
    core.mesh_company_name = request.data["companyname"]
    core.save(update_fields=["default_time_zone", "mesh_company_name"])

core.mesh_company_name = request.data["mesh_company_name"]
update_fields_list.append("mesh_company_name")

# save custom fields
if "custom_fields" in request.data.keys():
Expand Down
52 changes: 32 additions & 20 deletions api/tacticalrmm/core/agent_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ if [[ $DISPLAY ]]; then
exit 1
fi

agentSvcName='tacticalagent.service'
agentSysD="/etc/systemd/system/${agentSvcName}"

if [ -f "${agentSysD}" ]; then
CUSTOM_BIN_PATH=$(awk -F'=' '/ExecStart/ {print $2}' ${agentSysD} | awk '{print $1}' | xargs dirname)
else
CUSTOM_BIN_PATH=""
fi

DEBUG=0
INSECURE=0
NOMESH=0
UNINSTALL=0

agentDL='agentDLChange'
meshDL='meshDLChange'
Expand All @@ -35,7 +45,22 @@ siteID='siteIDChange'
agentType='agentTypeChange'
proxy=''

agentBinPath='/usr/local/bin'
while [[ "$#" -gt 0 ]]; do
case $1 in
-debug | --debug | debug) DEBUG=1 ;;
-insecure | --insecure | insecure) INSECURE=1 ;;
-nomesh | --nomesh | nomesh) NOMESH=1 ;;
-uninstall | --uninstall | uninstall) UNINSTALL=1 ;;
-binpath | --binpath) CUSTOM_BIN_PATH="$2"; shift ;;
*)
echo "ERROR: Unknown parameter: $1"
exit 1
;;
esac
shift
done

agentBinPath="${CUSTOM_BIN_PATH:-/usr/local/bin}"
binName='tacticalagent'
agentBin="${agentBinPath}/${binName}"
agentConf='/etc/tacticalagent'
Expand Down Expand Up @@ -137,28 +162,20 @@ Uninstall() {
RemoveOldAgent
}

if [ $# -ne 0 ] && [[ $1 =~ ^(uninstall|-uninstall|--uninstall)$ ]]; then
if [[ $UNINSTALL -eq 1 ]]; then
Uninstall
# Remove the current script
rm "$0"
exit 0
fi

while [[ "$#" -gt 0 ]]; do
case $1 in
-debug | --debug | debug) DEBUG=1 ;;
-insecure | --insecure | insecure) INSECURE=1 ;;
-nomesh | --nomesh | nomesh) NOMESH=1 ;;
*)
echo "ERROR: Unknown parameter: $1"
exit 1
;;
esac
shift
done

RemoveOldAgent

if [ ! -d "${agentBinPath}" ]; then
echo "Creating ${agentBinPath}"
mkdir -p ${agentBinPath}
fi

echo "Downloading tactical agent..."
wget -q -O ${agentBin} "${agentDL}"
if [ $? -ne 0 ]; then
Expand All @@ -182,11 +199,6 @@ else
MESH_NODE_ID=$(env XAUTHORITY=foo DISPLAY=bar ${agentBin} -m nixmeshnodeid)
fi

if [ ! -d "${agentBinPath}" ]; then
echo "Creating ${agentBinPath}"
mkdir -p ${agentBinPath}
fi

INSTALL_CMD="${agentBin} -m install -api ${apiURL} -client-id ${clientID} -site-id ${siteID} -agent-type ${agentType} -auth ${token}"

if [ "${MESH_NODE_ID}" != '' ]; then
Expand Down
Loading