1111
1212namespace rpi_imager {
1313
14+ constexpr auto PI_CONNECT_CONFIG_PATH = " .config/com.raspberrypi.connect" ;
15+ constexpr auto PI_CONNECT_DEPLOY_KEY_FILENAME = " deploy.key" ;
16+
1417QString CustomisationGenerator::shellQuote (const QString& value) {
1518 QString t = value;
1619 t.replace (" '" , " '\" '\" '" );
@@ -177,16 +180,18 @@ QByteArray CustomisationGenerator::generateSystemdScript(const QVariantMap& s, c
177180 const bool piConnectEnabled = s.value (" piConnectEnabled" ).toBool ();
178181 QString piConnectTokenTrimmed = piConnectToken.trimmed ();
179182 if (piConnectEnabled && !piConnectTokenTrimmed.isEmpty ()) {
180- // Determine home directory for the effective user
183+ const QString configDir = QStringLiteral (" $TARGET_HOME/" ) + PI_CONNECT_CONFIG_PATH;
184+ const QString deployKeyPath = configDir + QStringLiteral (" /" ) + PI_CONNECT_DEPLOY_KEY_FILENAME;
185+
181186 line (QStringLiteral (" TARGET_USER=\" " ) + effectiveUser + QStringLiteral (" \" " ), script);
182187 line (QStringLiteral (" TARGET_HOME=$(getent passwd \" $TARGET_USER\" | cut -d: -f6)" ), script);
183188 line (QStringLiteral (" if [ -z \" $TARGET_HOME\" ] || [ ! -d \" $TARGET_HOME\" ]; then TARGET_HOME=\" /home/" ) + effectiveUser + QStringLiteral (" \" ; fi" ), script);
184- line (QStringLiteral (" install -o \" $TARGET_USER\" -m 700 -d \" $TARGET_HOME/com.raspberrypi.connect \" " ), script);
185- line (QStringLiteral (" cat > \" $TARGET_HOME/com.raspberrypi.connect/deploy.key \" <<'EOF'" ), script);
189+ line (QStringLiteral (" install -o \" $TARGET_USER\" -m 700 -d \" " ) + configDir + QStringLiteral ( " \" " ), script);
190+ line (QStringLiteral (" cat > \" " ) + deployKeyPath + QStringLiteral ( " \" <<'EOF'" ), script);
186191 line (piConnectTokenTrimmed, script);
187192 line (QStringLiteral (" EOF" ), script);
188- line (QStringLiteral (" chown \" $TARGET_USER:$TARGET_USER\" \" $TARGET_HOME/com.raspberrypi.connect/deploy.key \" " ), script);
189- line (QStringLiteral (" chmod 600 \" $TARGET_HOME/com.raspberrypi.connect/deploy.key \" " ), script);
193+ line (QStringLiteral (" chown \" $TARGET_USER:$TARGET_USER\" \" " ) + deployKeyPath + QStringLiteral ( " \" " ), script);
194+ line (QStringLiteral (" chmod 600 \" " ) + deployKeyPath + QStringLiteral ( " \" " ), script);
190195
191196 // Enable systemd user service rpi-connect-signin.service for the target user
192197 line (QStringLiteral (" install -o \" $TARGET_USER\" -m 700 -d \" $TARGET_HOME/.config/systemd/user/default.target.wants\" " ), script);
@@ -381,7 +386,8 @@ QByteArray CustomisationGenerator::generateCloudInitUserData(const QVariantMap&
381386 if (piConnectEnabled && !cleanToken.isEmpty ()) {
382387 // Use the same effective user decision as above
383388 const QString effectiveUser = userName.isEmpty () && sshEnabled ? currentUser : (userName.isEmpty () ? QStringLiteral (" pi" ) : userName);
384- const QString targetPath = QStringLiteral (" /home/" ) + effectiveUser + QStringLiteral (" /com.raspberrypi.connect/auth.key" );
389+ const QString configDir = QStringLiteral (" /home/" ) + effectiveUser + QStringLiteral (" /" ) + PI_CONNECT_CONFIG_PATH;
390+ const QString targetPath = configDir + QStringLiteral (" /" ) + PI_CONNECT_DEPLOY_KEY_FILENAME;
385391 push (QStringLiteral (" write_files:" ), cloud);
386392 push (QStringLiteral (" - path: " ) + targetPath, cloud);
387393 push (QStringLiteral (" permissions: '0600'" ), cloud);
@@ -392,7 +398,7 @@ QByteArray CustomisationGenerator::generateCloudInitUserData(const QVariantMap&
392398 // Ensure directory exists with correct owner
393399 push (QString (), cloud);
394400 push (QStringLiteral (" runcmd:" ), cloud);
395- push (QStringLiteral (" - [ sh, -c, \" install -o " ) + effectiveUser + QStringLiteral (" -m 700 -d /home/ " ) + effectiveUser + QStringLiteral (" /com.raspberrypi.connect \" ]" ), cloud);
401+ push (QStringLiteral (" - [ sh, -c, \" install -o " ) + effectiveUser + QStringLiteral (" -m 700 -d " ) + configDir + QStringLiteral (" \" ]" ), cloud);
396402 } else if (needsRuncmd) {
397403 // Start runcmd section if not already started
398404 push (QStringLiteral (" runcmd:" ), cloud);
0 commit comments