admin: localimporter can make symlink instead of copying whole files
This commit is contained in:
parent
d81f068eba
commit
8ed23ddc7a
5 changed files with 63 additions and 24 deletions
|
@ -62,15 +62,21 @@ func StripPrefix(prefix string, h http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
func main() {
|
||||
cloudDAVBase := ""
|
||||
cloudUsername := "fic"
|
||||
cloudPassword := ""
|
||||
localImporterDirectory := ""
|
||||
localImporterSymlink := false
|
||||
|
||||
// Read paremeters from environment
|
||||
if v, exists := os.LookupEnv("FICCLOUD_URL"); exists {
|
||||
sync.CloudDAVBase = v
|
||||
cloudDAVBase = v
|
||||
}
|
||||
if v, exists := os.LookupEnv("FICCLOUD_USER"); exists {
|
||||
sync.CloudUsername = v
|
||||
cloudUsername = v
|
||||
}
|
||||
if v, exists := os.LookupEnv("FICCLOUD_PASS"); exists {
|
||||
sync.CloudPassword = v
|
||||
cloudPassword = v
|
||||
}
|
||||
|
||||
// Read parameters from command line
|
||||
|
@ -82,19 +88,32 @@ func main() {
|
|||
flag.StringVar(&api.TeamsDir, "teams", "./TEAMS", "Base directory where save teams JSON files")
|
||||
flag.StringVar(&settings.SettingsDir, "settings", settings.SettingsDir, "Base directory where load and save settings")
|
||||
flag.StringVar(&fic.FilesDir, "files", fic.FilesDir, "Base directory where found challenges files, local part")
|
||||
flag.StringVar(&sync.CloudDAVBase, "clouddav", sync.CloudDAVBase,
|
||||
"Base directory where found challenges files, cloud part")
|
||||
flag.StringVar(&sync.CloudUsername, "clouduser", sync.CloudUsername, "Username used to sync")
|
||||
flag.StringVar(&sync.CloudPassword, "cloudpass", sync.CloudPassword, "Password used to sync")
|
||||
flag.StringVar(&localImporterDirectory, "localimport", localImporterDirectory,
|
||||
"Base directory where found challenges files to import, local part")
|
||||
flag.BoolVar(&localImporterSymlink, "localimportsymlink", localImporterSymlink,
|
||||
"Copy files or just create symlink?")
|
||||
flag.StringVar(&cloudDAVBase, "clouddav", cloudDAVBase,
|
||||
"Base directory where found challenges files to import, cloud part")
|
||||
flag.StringVar(&cloudUsername, "clouduser", cloudUsername, "Username used to sync")
|
||||
flag.StringVar(&cloudPassword, "cloudpass", cloudPassword, "Password used to sync")
|
||||
flag.BoolVar(&fic.OptionalDigest, "optionaldigest", fic.OptionalDigest, "Is the digest required when importing files?")
|
||||
flag.BoolVar(&fic.StrongDigest, "strongdigest", fic.StrongDigest, "Are BLAKE2b digests required instead of SHA-1 or BLAKE2b?")
|
||||
flag.BoolVar(&fic.StrongDigest, "strongdigest", fic.StrongDigest, "Are BLAKE2b digests required or is SHA-1 good enough?")
|
||||
flag.Parse()
|
||||
|
||||
log.SetPrefix("[admin] ")
|
||||
|
||||
//sync.GlobalImporter = sync.LocalImporter{"/mnt/fic/"}
|
||||
sync.GlobalImporter, _ = sync.NewCloudImporter(sync.CloudDAVBase, sync.CloudUsername, sync.CloudPassword)
|
||||
log.Println("Using", sync.GlobalImporter.Kind())
|
||||
// Instantiate importer
|
||||
if localImporterDirectory != "" && cloudDAVBase != "" {
|
||||
log.Fatal("Cannot have both --clouddav and --localimport defined.")
|
||||
return
|
||||
} else if localImporterDirectory != "" {
|
||||
sync.GlobalImporter = sync.LocalImporter{localImporterDirectory, localImporterSymlink}
|
||||
} else if cloudDAVBase != "" {
|
||||
sync.GlobalImporter, _ = sync.NewCloudImporter(cloudDAVBase, cloudUsername, cloudPassword)
|
||||
}
|
||||
if sync.GlobalImporter != nil {
|
||||
log.Println("Using", sync.GlobalImporter.Kind())
|
||||
}
|
||||
|
||||
// Sanitize options
|
||||
var err error
|
||||
|
|
Reference in a new issue