Top Level Namespace
Instance Method Summary collapse
-
#adduser(username, args = {}) ⇒ Object
This is a driver for the pw command.
-
#install_port(port) {|commands| ... } ⇒ Object
Installs a port.
-
#put_template(tmpl, dest, b) ⇒ Object
Upload a file and copy it into a final location.
-
#update_ports ⇒ Object
Updates ports, uses portsnap update.
-
#upload_pubkey(user, keyfile) ⇒ Object
Uploads file as a public key [user] username [keyfile] keyfile to upload (.ssh/id_dsa.pub is a popular choice).
Instance Method Details
#adduser(username, args = {}) ⇒ Object
This is a driver for the pw command. pass arguments in as a hash of k-v. simple flags map to nil. will only add a user if it doesn’t exist You can pass arbitrary arguments to pw using the args hash in the form: ‘-flag’=>‘value’. See the pw man page for extensive documentation.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vlad/freebsd.rb', line 35 def adduser(username, args={}) args = { '-s' => '/usr/local/bin/bash', "-c"=>"'service user'", "-n"=>username, "-m"=>nil, '-w'=>'no'}.merge(args) slug = "if [ $(id -u sophia > /dev/null) ];then \n" slug += "pw user add " args.each do |k,v| slug << ' ' << [k,v].join(" ") end puts "running #{slug}" slug += "\nfi" sudo slug end |
#install_port(port) {|commands| ... } ⇒ Object
Installs a port. Uses the portinstall command in –batch mode. Note that if a block is passed, an array is yielded allowing the caller to manipulate the actually executed command; handy for setting make args and the like. See portinstall manpage for extensive documentation.
50 51 52 53 54 55 56 57 |
# File 'lib/vlad/freebsd.rb', line 50 def install_port(port) commands = [] commands << "portinstall --batch #{port} " yield commands if block_given? commands = commands.join(" && ") puts "Running [#{commands}]" commands.each {|x| sudo x} end |
#put_template(tmpl, dest, b) ⇒ Object
Upload a file and copy it into a final location. Uses sudo to copy after uploading. Templating is done via ERB, the user passes in the desired binding.
- tmpl
-
template file
- dest
-
destination path
- b
-
binding
65 66 67 68 69 70 71 72 |
# File 'lib/vlad/freebsd.rb', line 65 def put_template(tmpl, dest, b) tmpl = File.read(tmpl) buf = ERB.new(tmpl).result(b) put './tmpl', application do buf end sudo "cp ./tmpl #{dest}" end |
#update_ports ⇒ Object
Updates ports, uses portsnap update.
27 28 29 |
# File 'lib/vlad/freebsd.rb', line 27 def update_ports sudo "portsnap update" end |
#upload_pubkey(user, keyfile) ⇒ Object
Uploads file as a public key
- user
-
username
- keyfile
-
keyfile to upload (.ssh/id_dsa.pub is a popular choice)
20 21 22 23 24 |
# File 'lib/vlad/freebsd.rb', line 20 def upload_pubkey(user, keyfile) run sudo "mkdir -pvm 755 ~#{user}/.ssh" put_template keyfile, '~/#{user}/.ssh/authorized_keys', binding run "chown #{user}:#{user} ~#{user}/.ssh/.authorized_keys" end |