Move files around to organize along packages
[armadillo.git] / main.go
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
4 //
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
8 //
9
10 package main
11
12 import (
13 "flag"
14 "fmt"
15 "os"
16 "strings"
17 "./config"
18 "./paths"
19 "./server"
20 )
21
22 func main() {
23 // Set up the basic flags.
24 var configPath *string = flag.String("config", "~/.armadillo", "Path to the configuration file")
25 var jailRoot *string = flag.String("jail", "", "Restrict file operations to this directory root")
26 var port *int = flag.Int("port", 0, "Port to run the server on")
27 flag.Parse()
28
29 // Load the configuration file, if it is present.
30 var configuration = new(config.Configuration)
31 fmt.Printf("Reading configuration from %v\n", *configPath)
32 if len(*configPath) > 0 {
33 *configPath = strings.Replace(*configPath, "~", "$HOME", 1)
34 *configPath = os.ShellExpand(*configPath)
35 error := config.ReadFromFile(*configPath, configuration)
36 if error != nil {
37 fmt.Printf("Error while reading configuration: %v\n", error)
38 }
39 }
40
41 // Override configuration values with command line arguments.
42 if *jailRoot != "" {
43 configuration.JailRoot = *jailRoot
44 }
45 if *port != 0 {
46 configuration.Port = *port
47 }
48
49 if configuration.Port == 0 {
50 fmt.Printf("Failed to start server (invalid port)\n")
51 os.Exit(1)
52 }
53
54 // Run the server.
55 fmt.Printf("Starting Armadillo on port %d with root:\n %v\n",
56 configuration.Port, configuration.JailRoot)
57 paths.SetConfig(configuration)
58 server.RunBackEnd(configuration)
59 }