-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathksgen.rb
executable file
·53 lines (40 loc) · 1.5 KB
/
ksgen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'sinatra'
require 'cgi'
require './conf.rb'
# Ksgen - A Ruby/Sinatra program to generate Kickstart files or Arch Linux
# install scripts based on the given URL from ERB templates
# can change disk profile and cpu arch via url, others need separate profiles
set :environment, :development
set :views, [ 'snippets', 'profiles' ]
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# "find_template" method is used by Sinatra if you define it
helpers do
def find_template(views, name, engine, &block)
Array(views).each { |v| super(v, name, engine, &block) }
end
end
get '/:profile/:storage/?' do
content_type 'text/plain'
# Defaults
@arch = settings.arch
@filesystem = settings.filesystem
# parameters
@profile = params['profile']
@storage = params['storage']
# get query params from url
@query = CGI.parse(request.query_string)
# optional query parameters static? can't we make this more flexible?
@snippets = @query['snippet'] # return array, multiple snippet parameters allowed
# Use defaults if value not given - needs to be DRY'd or put into subroutine
@arch = @query['arch'][0]
@arch.nil? && @arch = settings.arch
@hostname = @query['hostname'][0]
@hostname.nil? && @hostname = settings.hostname
@filesystem = @query['filesystem'][0]
@filesystem.nil? && @filesystem = settings.filesystem
@version = @query['version'][0]
@version.nil? && @version = '0'
@location = @query['location'][0]
@location.nil? && @location = 'unspecified'
erb :"#{@profile}"
end