admin: initialize directory structure and required files at launch
This commit is contained in:
parent
7da6f5cd0c
commit
af2fe21d73
2 changed files with 25 additions and 22 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
@ -33,24 +32,7 @@ func getROSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
}
|
||||
|
||||
func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
if settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
|
||||
return settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile))
|
||||
} else {
|
||||
return settings.FICSettings{
|
||||
Title: "Challenge FIC",
|
||||
Authors: "Laboratoire SRS, ÉPITA",
|
||||
Start: time.Unix(0, 0),
|
||||
End: time.Unix(0, 0),
|
||||
Generation: time.Unix(0, 0),
|
||||
FirstBlood: fic.FirstBlood,
|
||||
SubmissionCostBase: fic.SubmissionCostBase,
|
||||
AllowRegistration: false,
|
||||
DenyNameChange: false,
|
||||
EnableResolutionRoute: false,
|
||||
PartialValidation: true,
|
||||
EnableExerciceDepend: true,
|
||||
}, nil
|
||||
}
|
||||
return settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile))
|
||||
}
|
||||
|
||||
func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
|
|
|
@ -143,9 +143,6 @@ func main() {
|
|||
if settings.SettingsDir, err = filepath.Abs(settings.SettingsDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if fic.FilesDir, err = filepath.Abs(fic.FilesDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if *baseURL != "/" {
|
||||
tmp := path.Clean(*baseURL)
|
||||
baseURL = &tmp
|
||||
|
@ -154,6 +151,30 @@ func main() {
|
|||
baseURL = &tmp
|
||||
}
|
||||
|
||||
// Creating minimal directories structure
|
||||
os.MkdirAll(fic.FilesDir, 0777)
|
||||
os.MkdirAll(pki.PKIDir, 0711)
|
||||
os.MkdirAll(api.TeamsDir, 0777)
|
||||
os.MkdirAll(settings.SettingsDir, 0777)
|
||||
|
||||
// Initialize settings and load them
|
||||
if !settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
|
||||
if err := settings.SaveSettings(path.Join(settings.SettingsDir, settings.SettingsFile), settings.FICSettings{
|
||||
Title: "Challenge FIC",
|
||||
Authors: "Laboratoire SRS, ÉPITA",
|
||||
FirstBlood: fic.FirstBlood,
|
||||
SubmissionCostBase: fic.SubmissionCostBase,
|
||||
AllowRegistration: false,
|
||||
DenyNameChange: false,
|
||||
EnableResolutionRoute: false,
|
||||
PartialValidation: true,
|
||||
EnableExerciceDepend: true,
|
||||
}); err != nil {
|
||||
log.Fatal("Unable to initialize settings.json:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Database connection
|
||||
log.Println("Opening database...")
|
||||
if err := fic.DBInit(*dsn); err != nil {
|
||||
log.Fatal("Cannot open the database: ", err)
|
||||
|
|
Reference in a new issue