diff --git a/README.md b/README.md index f05e812..a5f7445 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Et voilĂ , you have a copy of notorious running,. This will build the docker image which you can then run it either on local bare-metal, or if you're interested in the Docker Cloud route (which I highly recommend) head over to their [Documentation](https://docs.docker.com/docker-cloud/getting-started/) They'll explain deployment 1 000% better than I can. ## Please note: -I have not yet included instructions for running everything on bare-metal and I'm using docker because it just works (sorry, I try to keep the buzzwordiness down [despite deploying notorious with mariadb, redis, docker, go...]), but those are soon to come. I just honestly thing the docker way is 10x (just like me, heh) easier to deploy with at this particular moment. +I have not yet included instructions for running everything on bare-metal and I'm using docker because it just works (sorry, I try to keep the buzzwordiness down [despite deploying notorious with redis, docker, go...]), but those are soon to come. I just honestly thing the docker way is 10x (just like me, heh) easier to deploy with at this particular moment. # Test it out? diff --git a/build/install_dependencies.sh b/build/install_dependencies.sh deleted file mode 100755 index 9275ad8..0000000 --- a/build/install_dependencies.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -go get github.com/spf13/viper -go get gopkg.in/redis.v3 - diff --git a/build/install_deps.sh b/build/install_deps.sh index ee40825..470c281 100755 --- a/build/install_deps.sh +++ b/build/install_deps.sh @@ -1,6 +1,6 @@ #!/bin/sh -go get github.com/NotoriousTracker/viper +go get github.com/spf13/viper go get github.com/jinzhu/gorm go get gopkg.in/redis.v3 go get github.com/go-sql-driver/mysql diff --git a/config.yaml b/config.yaml index 650a80b..ef93e22 100644 --- a/config.yaml +++ b/config.yaml @@ -1,8 +1,14 @@ MySQLHost: localhost -MySQLPort: 3306 +MySQLPort: "3306" MySQLUser: testuser MySQLPass: testuser MySQLDB: testdb RedisServer: localhost RedisPort: 6379 +# Whitelist indicates that torrent whitelisting is activated. When torrent +# whitelisting is activated, only pre-approved torrents can be served by +# Notorious Whitelist: false +# UseEnvVariables allows environmental variables to be used instead of +# expliclitly defined config variables. +UseEnvVariables: true diff --git a/config/config.go b/config/config.go index 41d9f33..ef572a4 100644 --- a/config/config.go +++ b/config/config.go @@ -7,7 +7,7 @@ import ( // ConfigStruct holds the values that our config file holds type ConfigStruct struct { MySQLHost string - MySQLPort int + MySQLPort string MySQLUser string MySQLPass string MySQLDB string @@ -15,7 +15,8 @@ type ConfigStruct struct { } // LoadConfig loads the config into the Config Struct and returns the -// ConfigStruct object +// ConfigStruct object. Will load from environmental variables (all caps) if we +// set a flag to true. func LoadConfig() ConfigStruct { viper.SetConfigName("config") viper.SetConfigType("yaml") @@ -23,28 +24,34 @@ func LoadConfig() ConfigStruct { viper.AddConfigPath("../") viper.AddConfigPath("/etc/") - err := viper.ReadInConfig() - if err != nil { - panic("Failed to open config file") - } + err := viper.ReadInConfig() + if err != nil { + panic("Failed to open config file") + } + + if viper.GetBool("UseEnvVariables") == true { + viper.AutomaticEnv() + viper.BindEnv("mysqluser") + } + if viper.Get("MySQLPass").(string) != "" { return ConfigStruct{ - viper.Get("MySQLHost").(string), - viper.Get("MySQLPort").(int), - viper.Get("MySQLUser").(string), - viper.Get("MySQLPass").(string), - viper.Get("MySQLDB").(string), - viper.Get("Whitelist").(bool), + viper.Get("mysqlhost").(string), + viper.Get("mysqlport").(string), + viper.Get("mysqluser").(string), + viper.Get("mysqlpass").(string), + viper.Get("mysqldb").(string), + viper.Get("whitelist").(bool), } } else { return ConfigStruct{ - viper.Get("MySQLHost").(string), - viper.Get("MySQLPort").(int), - viper.Get("MySQLUser").(string), + viper.Get("mysqlhost").(string), + viper.Get("mysqlport").(string), + viper.Get("mysqluser").(string), "", - viper.Get("MySQLDB").(string), - viper.GetBool("Whitelist"), + viper.Get("mysqldb").(string), + viper.Get("whitelist").(bool), } } diff --git a/database/database.go b/database/database.go index 7330f5e..0b7d8e1 100644 --- a/database/database.go +++ b/database/database.go @@ -12,7 +12,7 @@ import ( // formatConnectStrings concatenates the data from the config file into a // usable MySQL connection string. func formatConnectString(c config.ConfigStruct) string { - return fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?parseTime=true", + return fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?parseTime=true", c.MySQLUser, c.MySQLPass, c.MySQLHost,