diff --git a/README.md b/README.md index fdc8206..b91e11f 100644 --- a/README.md +++ b/README.md @@ -26,17 +26,22 @@ To install the latest 'stable' release of `panda-motd`: gem install panda-motd ~~~ -At this point, you can run `sudo panda-motd` from anywhere (running with `sudo` is important), which will generate a configuration file located at `~/.config/panda-motd.yaml`. This file contains a description of each component of the MOTD and how to enable/disable/configure each one. Components are printed in your MOTD in the same order that they are defined in this configuration file. +At this point, you can run `panda-motd ~/.config/panda-motd.yaml` (without `sudo`) from anywhere, which will generate a configuration file located at `~/.config/panda-motd.yaml`. This file contains a description of each component of the MOTD and how to enable/disable/configure each one. Components are printed in your MOTD in the same order that they are defined in this configuration file. Actually getting the output of the gem to become your MOTD is going to depend on your Linux distribution. Currently, it is only tested and working on **Ubuntu 16.04 LTS**: * Go to the `/etc/update-motd.d` folder and inspect its contents. The MOTD is formed by running each of these scripts in numerical order (really alphabetically, but the convention is to start each script with two numbers), as root. The factory MOTD is generated using these scripts. * If you desire to completely replace all of these scripts with `panda-motd`, it would be wise to make a copy of the `update-motd.d` folder, and then remove all of the factory scripts. -* Create a new file in `update-motd.d` and call it `00-pandamotd`, (or really, whatever you want). Remember, the numbers at the beginning of the filename are what determine the order of execution if you have any other scripts in the folder. In this file, use a text editor to write the contents as follows: +* Create a new file in `update-motd.d` and call it `00-pandamotd`, (or really, whatever you want). Remember, the numbers at the beginning of the filename are what determine the order of execution if you have any other scripts in the folder. In this file, use a text editor to write the contents as follows, **substituting `YOUR_USERNAME` with your username**: ~~~bash #!/bin/sh -panda-motd +echo "" > /var/log/panda-motd.error.log +panda-motd /home/YOUR_USERNAME/.config/panda-motd.yaml 2> /var/log/panda-motd.error.log +if [ -s "/var/log/panda-motd.error.log" ] +then + echo "panda-motd had errors. Check '/var/log/panda-motd.error.log'." +fi ~~~ * Make the new file you created executable, by doing: @@ -45,7 +50,7 @@ panda-motd sudo chmod +x /etc/update-motd.d/00-pandamotd ~~~ -* Finally, run `sudo update-motd`. This will rebuild your MOTD, and will display the MOTD exactly as it will be when you log in. Log in and out to test the MOTD. +* You should now be able to log in to the machine over SSH and see the generated MOTD. If there are any errors, you will be notified. **Note:** Instructions for other distributions will become available over time. If you are successful in modifying your MOTD on a distribution which has no instructions yet, please open an issue so we can get the process documented. I will likely be starting a Wiki section for this purpose. diff --git a/lib/panda_motd.rb b/lib/panda_motd.rb index 4d187fe..b2d317a 100644 --- a/lib/panda_motd.rb +++ b/lib/panda_motd.rb @@ -3,6 +3,10 @@ class PandaMOTD def self.new_motd - return MOTD.new + if ARGV[0].nil? + puts 'You must provide a config file path as an argument to panda-motd.' + else + return MOTD.new(ARGV[0]) + end end end diff --git a/lib/panda_motd/config.rb b/lib/panda_motd/config.rb index 3d571f4..fe83fae 100644 --- a/lib/panda_motd/config.rb +++ b/lib/panda_motd/config.rb @@ -4,7 +4,10 @@ class Config def initialize(file_path = nil) @file_path = file_path.nil? ? File.join(Dir.home, '.config', 'panda-motd.yaml') : file_path - create_config(@file_path) unless File.exist?(@file_path) + unless File.exist?(@file_path) + create_config(@file_path) + puts "panda-motd created a default config file at: #{@file_path}" + end load_config(@file_path) end diff --git a/test.sh b/test.sh index ea08db0..db0c896 100755 --- a/test.sh +++ b/test.sh @@ -6,4 +6,6 @@ scp panda-motd*.gem taylor@taylorjthurlow.com:~/temp/pandamotd.gem ssh -t taylor@taylorjthurlow.com "cd ~/temp && \ sudo gem uninstall -x panda-motd && \ sudo gem install ./*.gem && \ - sudo panda-motd" + echo '---------------------' && \ + sudo panda-motd /home/taylor/.config/panda-motd.yaml && \ + echo '---------------------'"