Skip to content

Commit

Permalink
Use mandatory config file argument
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorthurlow committed May 14, 2018
1 parent d59c52e commit 50555e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion lib/panda_motd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion lib/panda_motd/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ scp panda-motd*.gem [email protected]:~/temp/pandamotd.gem
ssh -t [email protected] "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 '---------------------'"

0 comments on commit 50555e4

Please sign in to comment.