@@ -119,20 +119,20 @@ func createEnvFile(d *MigrationData) {
119
119
// Define the path to the environment file
120
120
envFilePath := "/etc/curio.env"
121
121
122
- var layers []string
123
- var repoPath , nodeName string
122
+ var layers , additionalEnvVars , envVars []string
124
123
125
- envVars := map [string ]string {}
124
+ repoPath := "~/.curio"
125
+ nodeName := "ChangeME"
126
126
127
127
// Take user input to remaining env vars
128
128
for {
129
129
i , _ , err := (& promptui.Select {
130
130
Label : d .T ("Enter the info to configure your Curio node" ),
131
131
Items : []string {
132
- d .T ("CURIO_LAYERS: %s" , "" ),
133
- d .T ("CURIO_REPO_PATH: %s" , "~/.curio" ),
134
- d .T ("CURIO_NODE_NAME: %s" , "" ),
135
- d .T ("Add additional variables like FIL_PROOFS_PARAMETER_CACHE." ),
132
+ d .T ("CURIO_LAYERS: %s" , layers ),
133
+ d .T ("CURIO_REPO_PATH: %s" , repoPath ),
134
+ d .T ("CURIO_NODE_NAME: %s" , nodeName ),
135
+ d .T ("Add additional variables like FIL_PROOFS_PARAMETER_CACHE: %s" , envVars ),
136
136
d .T ("Continue update the env file." )},
137
137
Size : 6 ,
138
138
Templates : d .selectTemplates ,
@@ -189,7 +189,6 @@ func createEnvFile(d *MigrationData) {
189
189
d .say (plain , "Start typing your additional environment variables one variable per line. Use Ctrl+D to finish:" )
190
190
reader := bufio .NewReader (os .Stdin )
191
191
192
- var additionalEnvVars []string
193
192
for {
194
193
text , err := reader .ReadString ('\n' )
195
194
if err != nil {
@@ -205,47 +204,39 @@ func createEnvFile(d *MigrationData) {
205
204
for _ , envVar := range additionalEnvVars {
206
205
parts := strings .SplitN (envVar , "=" , 2 )
207
206
if len (parts ) == 2 {
208
- envVars [ strings .TrimSpace (parts [0 ])] = strings .TrimSpace (parts [1 ])
207
+ envVars = append ( envVars , fmt . Sprintf ( "%s=%s" , strings .TrimSpace (parts [0 ]), strings .TrimSpace (parts [1 ])) )
209
208
} else {
210
209
d .say (notice , "Skipping invalid input: %s" , envVar )
211
210
}
212
211
}
213
212
continue
214
213
case 4 :
215
214
// Define the environment variables to be added or updated
216
- defenvVars := map [ string ]string {
217
- "CURIO_LAYERS" : fmt .Sprintf ("export CURIO_LAYERS=%s" , strings .Join (layers , "," )),
218
- "CURIO_ALL_REMAINING_FIELDS_ARE_OPTIONAL" : " true" ,
219
- "CURIO_DB_HOST" : fmt .Sprintf ("export CURIO_DB_HOST=%s" , strings .Join (d .HarmonyCfg .Hosts , "," )),
220
- "CURIO_DB_PORT" : fmt .Sprintf ("export CURIO_DB_PORT =%s" , d .HarmonyCfg .Port ),
221
- "CURIO_DB_NAME" : fmt .Sprintf ("export CURIO_DB_HOST =%s" , d .HarmonyCfg .Database ),
222
- "CURIO_DB_USER" : fmt .Sprintf ("export CURIO_DB_HOST =%s" , d .HarmonyCfg .Username ),
223
- "CURIO_DB_PASSWORD" : fmt .Sprintf ("export CURIO_DB_HOST =%s" , d .HarmonyCfg .Password ),
224
- "CURIO_REPO_PATH" : repoPath ,
225
- "CURIO_NODE_NAME" : nodeName ,
226
- "FIL_PROOFS_USE_MULTICORE_SDR" : " 1" ,
215
+ defenvVars := [ ]string {
216
+ fmt .Sprintf ("CURIO_LAYERS=%s" , strings .Join (layers , "," )),
217
+ "CURIO_ALL_REMAINING_FIELDS_ARE_OPTIONAL= true" ,
218
+ fmt .Sprintf ("CURIO_DB_HOST=%s" , strings .Join (d .HarmonyCfg .Hosts , "," )),
219
+ fmt .Sprintf ("CURIO_DB_USER =%s" , d .HarmonyCfg .Username ),
220
+ fmt .Sprintf ("CURIO_DB_PASSWORD =%s" , d .HarmonyCfg .Password ),
221
+ fmt .Sprintf ("CURIO_DB_PORT =%s" , d .HarmonyCfg .Port ),
222
+ fmt .Sprintf ("CURIO_DB_NAME =%s" , d .HarmonyCfg .Database ),
223
+ fmt . Sprintf ( "CURIO_REPO_PATH=%s" , repoPath ) ,
224
+ fmt . Sprintf ( "CURIO_NODE_NAME=%s" , nodeName ) ,
225
+ "FIL_PROOFS_USE_MULTICORE_SDR= 1" ,
227
226
}
228
- for s , s2 := range defenvVars {
229
- envVars [s ] = s2
227
+ var w string
228
+ for _ , s := range defenvVars {
229
+ w += fmt .Sprintf ("%s\n " , s )
230
230
}
231
-
232
- // Open the file with truncation (this clears the file if it exists)
233
- file , err := os .OpenFile (envFilePath , os .O_WRONLY | os .O_TRUNC | os .O_CREATE , 0644 )
234
- if err != nil {
235
- d .say (notice , "Error opening or creating file %s: %s" , envFilePath , err )
236
- os .Exit (1 )
231
+ for _ , s := range envVars {
232
+ w += fmt .Sprintf ("%s\n " , s )
237
233
}
238
- defer func (file * os.File ) {
239
- _ = file .Close ()
240
- }(file )
241
234
242
235
// Write the new environment variables to the file
243
- for key , value := range envVars {
244
- line := fmt .Sprintf ("%s=%s\n " , key , value )
245
- if _ , err := file .WriteString (line ); err != nil {
246
- d .say (notice , "Error writing to file %s: %s" , envFilePath , err )
247
- os .Exit (1 )
248
- }
236
+ err = os .WriteFile (envFilePath , []byte (w ), 0644 )
237
+ if err != nil {
238
+ d .say (notice , "Error writing to file %s: %s" , envFilePath , err )
239
+ os .Exit (1 )
249
240
}
250
241
d .say (notice , "Service env file /etc/curio.env created successfully." )
251
242
return
0 commit comments