Skip to content

Conversation

ppawlowski
Copy link
Contributor

@ppawlowski ppawlowski commented Jul 6, 2025

Description

This pull request introduces a possibility to run the Device Agent Installer without the need to provide the One-Time-Code used for automatic device onboarding.
Without OTC provided:

  • a user is asked to confirm non-automatic Device Agent configuration
  • when the Device Agent configuration phase is reached, a user is asked to provide the device.yaml content or skip the configuration step
  • when the content of device.yaml is provided, simple validation is made, and the file is saved in the proper directory, installation continues
  • when configuration is skipped, the Device Agent is left unconfigured. User receives simple information of the manual steps needed to be done to complete the configuration process

Related Issue(s)

Closes #407

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production

Labels

  • Includes a DB migration? -> add the area:migration label

@ppawlowski ppawlowski requested review from Steve-Mcl and hardillb July 6, 2025 11:07
Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

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

In this current iteration, if a device.yml is found, the only option is to QUIT or DELETE and continue. I am not sure it works as Nick had expected.

Consider this set of steps:

  1. User already has a device.yml in place (or restored it from a backup, or downloaded it from the FF device setup dialog)
  2. User runs installer
  3. Installer finds device.yml
  4. The only option is to delete the file to continue.

IMO, just like if you installed Device Agent via NPM, it will simply start up and use device.yml already present.

I think the better approach is to (like NPM installation does today) is to keep existing yml (or at least offer the option to use existing yml file)


Output

One time code has not been provided. The Device Agent automatic configuration is not possible.
Do you want to continue with the installation? (y/N): y
Continuing with installation in interactive mode...
Logger initialized.
****************************************************************
*            FlowFuse Device Agent Installer                   *
*                                                              *
* This installer will set up the FlowFuse Device Agent on your *
* system and configure it to run as a system service.          *
*                                                              *
****************************************************************
Installing FlowFuse Device Agent...
The working directory c:\opt\flowfuse-device exists and contains Device Agent configuration file
Do you want to remove it and continue installation? (Y/n): n
[ERROR] Installation failed: pre-check failed: configuration file pre-check failed: the c:\opt\flowfuse-device directory has not been removed. Please remove it manually and try again

@hardillb
Copy link
Contributor

Yep I agree with Steve, if there is an existing file it should offer the choice to use it.

@ppawlowski
Copy link
Contributor Author

Added the possibility to decide what should happen if device.yml is detected.

@ppawlowski ppawlowski requested a review from Steve-Mcl July 10, 2025 21:20
@Steve-Mcl
Copy link
Contributor

Tested new "keep settings" option - this was the result:

device-agent\installer\go\out\windows>flowfuse-device-installer-windows-amd64.exe
One time code has not been provided. The Device Agent automatic configuration is not possible.
Do you want to continue with the installation? (y/N): y
Continuing with installation in interactive mode...
Logger initialized.
****************************************************************
*            FlowFuse Device Agent Installer                   *
*                                                              *
* This installer will set up the FlowFuse Device Agent on your *
* system and configure it to run as a system service.          *
*                                                              *
****************************************************************
Installing FlowFuse Device Agent...
The working directory c:\opt\flowfuse-device exists and contains Device Agent configuration file
Device Agent configuration already exists. What would you like to do?
* 1. Keep existing configuration and continue installation
  2. Remove all content and do fresh installation
  3. Cancel installation
Please select an option (1-3) [default: 1]:
Keeping existing configuration file, continuing with installation...
Checking Node.js installation...
Node.js version 20.19.1 found.
Installing FlowFuse Device Agent latest version...
FlowFuse Device Agent installed successfully!
Configuring FlowFuse Device Agent...
Device Agent is already configured, skipping configuration.
Configuring FlowFuse Device Agent to run as system service...
Installing FlowFuse Device Agent service for windows...
[ERROR] Service setup failed: failed to create service: exit status 5
 utput: E r r o r   c r e a t i n g   s e r v i c e !
 C r e a t e S e r v i c e ( ) :   T h e   s p e c i f i e d   s e r v i c e   a l r e a d y   e x i s t s .


[ERROR] Installation failed: service setup failed: failed to create service: exit status 5
 utput: E r r o r   c r e a t i n g   s e r v i c e !
 C r e a t e S e r v i c e ( ) :   T h e   s p e c i f i e d   s e r v i c e   a l r e a d y   e x i s t s .

Observations:

  1. Looks like UTF-16 text is being parsed as UTF-8/ascii (might want to look into https://pkg.go.dev/golang.org/x/text/encoding/unicode)
  2. Double output of error
  3. First line One time code has not been provided. The Device Agent automatic configuration is not possible. is a bit confusing. I'm not even certain any of it is necessary TBH. We might as well just start the output at the ********** banner text
  4. Should not output Logger initialized. (IMO)

Hard Issues:

  • If the service is already installed, this cannot continue without deleting config (i.e. to get past the service error I need to either a) run with --uninstall - this deletes config or b) run with option 2 "remove content": - again this deletes config!)

@ppawlowski
Copy link
Contributor Author

Hard Issues:

  • If the service is already installed, this cannot continue without deleting config (i.e. to get past the service error I need to either a) run with --uninstall - this deletes config or b) run with option 2 "remove content": - again this deletes config!)

Fixed.

  1. Looks like UTF-16 text is being parsed as UTF-8/ascii (might want to look into https://pkg.go.dev/golang.org/x/text/encoding/unicode)

Addressed in a separate issue.

  1. Double output of error
  2. Should not output Logger initialized. (IMO)

Fixed.

  1. First line One time code has not been provided. The Device Agent automatic configuration is not possible. is a bit confusing. I'm not even certain any of it is necessary TBH. We might as well just start the output at the ********** banner text

Why did it confuse you? I wanted a user to be 100% sure what would happen and to give them a chance to cancel the installation process.

@joepavitt
Copy link
Contributor

@ppawlowski can you drop a status update on here please, 25 days and no updates.

@ppawlowski
Copy link
Contributor Author

@Steve-Mcl can I ask for feedback on my last comment, please?

@Steve-Mcl
Copy link
Contributor

5. First line One time code has not been provided. The Device Agent automatic configuration is not possible. is a bit confusing. I'm not even certain any of it is necessary TBH. We might as well just start the output at the ********** banner text

Why did it confuse you? I wanted a user to be 100% sure what would happen and to give them a chance to cancel the installation process.

I can't remember. Lets forget that for now.

@Steve-Mcl
Copy link
Contributor

Latest testing.

Run latest installer without entering a OTC (skip entering device.yml)

This was successful and outputs instructions at the end.

One time code has not been provided. The Device Agent automatic configuration is not possible.
Do you want to continue with the installation? (y/N): y
Continuing with installation in interactive mode...
****************************************************************
*            FlowFuse Device Agent Installer                   *
*                                                              *
* This installer will set up the FlowFuse Device Agent on your *
* system and configure it to run as a system service.          *
*                                                              *
****************************************************************
Installing FlowFuse Device Agent...
Checking Node.js installation...
Installing Node.js 20.19.1...
Installing FlowFuse Device Agent latest version...
FlowFuse Device Agent installed successfully!
Configuring FlowFuse Device Agent...
No OTC (One-Time Code) provided. Automatic configuration is not possible.
You can either:
  1. Install the device agent only (you'll need to configure it manually later)
  2. Provide a device configuration file now
Do you want to provide a device agent configuration now? (Y/n): n
Configuration completed successfully!
Configuring FlowFuse Device Agent to run as system service...
Installing FlowFuse Device Agent service for windows...

FlowFuse Device Agent installation completed successfully!
The Device Agent has been installed but it is not configured.
To complete the setup:
 1. Create a device.yml configuration file in c:\opt\flowfuse-device directory
 2. Start the Device Agent service
For information on how to manage the FlowFuse Device Agent,
  please refer to the documentation at https://github.com/FlowFuse/device-agent/blob/main/installer/README.md

My only suggestion would be we provide a batch/shell script that fires up the graphical setup (node/flowforge-device-agent --ui --ui-user admin --ui-pass admin --ui-port 3000 --ui-host 127.0.0.1) so that it can be configured from the built in web-ui - but this can abe considered at a later time


Run latest installer without entering a OTC (entering device.yml when prompted)

A second run (without removing the prev existing installation) failed at the service check.
In simple terms, the installer should not quit/exit because it found the existing service. Instead, it should either rebuild the service or just start what it finds.

One time code has not been provided. The Device Agent automatic configuration is not possible.
Do you want to continue with the installation? (y/N): y
Continuing with installation in interactive mode...
****************************************************************
*            FlowFuse Device Agent Installer                   *
*                                                              *
* This installer will set up the FlowFuse Device Agent on your *
* system and configure it to run as a system service.          *
*                                                              *
****************************************************************
Installing FlowFuse Device Agent...
Checking Node.js installation...
Node.js version 20.19.1 found.
Installing FlowFuse Device Agent latest version...
FlowFuse Device Agent installed successfully!
Configuring FlowFuse Device Agent...
No OTC (One-Time Code) provided. Automatic configuration is not possible.
You can either:
  1. Install the device agent only (you'll need to configure it manually later)
  2. Provide a device configuration file now
Do you want to provide a device agent configuration now? (Y/n):
Please paste your device configuration below.
The configuration should be in YAML format with all required fields.
Enter an empty line when done:
deviceId: 7rg9ApE14a
token: ffd_Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
credentialSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
forgeURL: http://192.168.xx.xx:3000
brokerURL: ws://172.xx.xx.183:8083
brokerUsername: device:d0bg4xgpR5:7rg9ApE14a
brokerPassword: ffbd_7k_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Device configuration saved successfully to: c:\opt\flowfuse-device\device.yml
Configuration completed successfully!
Configuring FlowFuse Device Agent to run as system service...
Installing FlowFuse Device Agent service for windows...
[ERROR] Service setup failed: failed to create service: exit status 5
Output: Error creating service!
CreateService(): The specified service already exists.

@ppawlowski
Copy link
Contributor Author

A second run (without removing the prev existing installation) failed at the service check.

@Steve-Mcl Fixed, please re-review.

@Steve-Mcl
Copy link
Contributor

A second run (without removing the prev existing installation) failed at the service check.

@Steve-Mcl Fixed, please re-review.

Yup, that'll do it 👍
I want to pull and test a few more scenarios (like the presence of a device.yml) and see if there are any scenarios where there is undesirable behaviour (like deletion of a perfectly good device.yml) or misleading text before I approve.

Please note: I am currently only checking against windows (would love to see some tests and trials by linux/mac users here in case I miss something)

@ppawlowski
Copy link
Contributor Author

I want to pull and test a few more scenarios.

Could you share those testing scenarios afterwards? I will create a list of them for future use.

Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

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

Windows all good

@joepavitt joepavitt moved this from In Progress to Review in 🛠 Development Aug 28, 2025
@joepavitt joepavitt merged commit ec2391f into main Aug 28, 2025
7 checks passed
@joepavitt joepavitt deleted the feat-dai-no-otc-install branch August 28, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review

Development

Successfully merging this pull request may close these issues.

Installer: Support install without OTC

4 participants