Update package names and import paths
[armadillo.git] / main.go
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010-2012, 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 "./server"
19 )
20
21 func main() {
22 // Set up the basic flags.
23 var configPath *string = flag.String("config", "~/.armadillo", "Path to the configuration file")
24 var jailRoot *string = flag.String("jail", "", "Restrict file operations to this directory root")
25 var port *int = flag.Int("port", 0, "Port to run the server on")
26 flag.Parse()
27
28 // Load the configuration file, if it is present.
29 var configuration = new(config.Configuration)
30 fmt.Printf("Reading configuration from %v\n", *configPath)
31 if len(*configPath) > 0 {
32 *configPath = strings.Replace(*configPath, "~", "$HOME", 1)
33 *configPath = os.ShellExpand(*configPath)
34 error := config.ReadFromFile(*configPath, configuration)
35 if error != nil {
36 fmt.Printf("Error while reading configuration: %v\n", error)
37 }
38 }
39
40 // Override configuration values with command line arguments.
41 if *jailRoot != "" {
42 configuration.JailRoot = *jailRoot
43 }
44 if *port != 0 {
45 configuration.Port = *port
46 }
47
48 if configuration.Port == 0 {
49 fmt.Printf("Failed to start server (invalid port)\n")
50 os.Exit(1)
51 }
52
53 // Run the server.
54 fmt.Printf("Starting Armadillo on port %d with root:\n %v\n",
55 configuration.Port, configuration.JailRoot)
56 paths.SetConfig(configuration)
57 server.RunBackEnd(configuration)
58 }