-
-
Save FiXato/1563430 to your computer and use it in GitHub Desktop.
Anope <= 1.8.x Deploy Script Cross-Section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
# | |
# A simple script that parses the Anope IRC Services services.conf for zbot and mysql variables. | |
# By: | |
# - Unknown_Entity aka o_o | |
# - Filip H.F. "FiXato" Slagter | |
# | |
# Now also compatible with 1.8.5 which seems to run on one of the archaic servers >< | |
require 'yaml' | |
SERVICES_CONFIG_PATH = File.expand_path(File.join('~', 'anope','data','services.conf')) | |
USE_SAMPLE_CONFIG = true | |
if USE_SAMPLE_CONFIG | |
services_conf =<<-EOS | |
MysqlHost "localhost" | |
MysqlUser "username" | |
MysqlPass "password" | |
MysqlName "dbname" | |
MysqlSock "/var/lib/mysql/mysql.sock" | |
MysqlPort "3306" | |
#MysqlSecure "md5" | |
#MysqlRetries 10 | |
#MysqlRetryGap 1 | |
#UseRDB | |
#zbotsqldb "nomatchdb" | |
#zbotsqluser "nomatchuser" | |
#zbotsqlpass "nomatchpass" | |
zbotsqldb "database" | |
zbotsqluser "user" | |
zbotsqlpass "password" | |
zbotsqlhost "localhost" | |
zbotsqlport 3306 | |
zbotsqlsock "/var/lib/mysql/mysql.sock" #"/var/run/mysqld/mysqld.sock" | |
zbotUseChanPrivmsg 1 | |
#zbotUseNickPrivmsg 1 | |
zbotFPChannelTime "1" | |
zbotFPUserTime "1" | |
ZbotUseFlatDB 0 | |
EOS | |
services_conf.gsub!(/^ {4}/, '') #remove the added heredoc indentation | |
else | |
services_conf = File.read(SERVICES_CONFIG_PATH) | |
end | |
settings = {} | |
grouped_settings = {} | |
services_conf.scan(/^((Mysql|zbot)(\S+))\s("([^"]+)"|(\d+))(.*)$/i) do |match| | |
key = match[0] | |
section = match[1].downcase | |
raw_value = match[3] | |
unquoted_value = match[4] || match[5] #Pick either the quoted value or the unquoted integer value. | |
comment = match[6] | |
value = {:raw_key => key, :raw_value => raw_value, :unquoted => unquoted_value, :comment => comment} | |
settings[key.downcase] = value | |
grouped_settings[section] ||= {} # Make sure the hash for this section already exists | |
grouped_settings[section][key.downcase] = value | |
end | |
puts "Settings: ", settings.to_yaml | |
puts '-'*80,'' | |
puts "Grouped Settings: ", grouped_settings.to_yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby anope_services_conf_parser.rb | |
Settings: | |
--- | |
mysqlhost: | |
:raw_key: MysqlHost | |
:raw_value: ! '"localhost"' | |
:unquoted: localhost | |
:comment: '' | |
mysqluser: | |
:raw_key: MysqlUser | |
:raw_value: ! '"username"' | |
:unquoted: username | |
:comment: '' | |
mysqlpass: | |
:raw_key: MysqlPass | |
:raw_value: ! '"password"' | |
:unquoted: password | |
:comment: '' | |
mysqlname: | |
:raw_key: MysqlName | |
:raw_value: ! '"dbname"' | |
:unquoted: dbname | |
:comment: '' | |
mysqlsock: | |
:raw_key: MysqlSock | |
:raw_value: ! '"/var/lib/mysql/mysql.sock"' | |
:unquoted: /var/lib/mysql/mysql.sock | |
:comment: '' | |
mysqlport: | |
:raw_key: MysqlPort | |
:raw_value: ! '"3306"' | |
:unquoted: '3306' | |
:comment: '' | |
zbotsqldb: | |
:raw_key: zbotsqldb | |
:raw_value: ! '"database"' | |
:unquoted: database | |
:comment: '' | |
zbotsqluser: | |
:raw_key: zbotsqluser | |
:raw_value: ! '"user"' | |
:unquoted: user | |
:comment: '' | |
zbotsqlpass: | |
:raw_key: zbotsqlpass | |
:raw_value: ! '"password"' | |
:unquoted: password | |
:comment: '' | |
zbotsqlhost: | |
:raw_key: zbotsqlhost | |
:raw_value: ! '"localhost"' | |
:unquoted: localhost | |
:comment: '' | |
zbotsqlport: | |
:raw_key: zbotsqlport | |
:raw_value: '3306' | |
:unquoted: '3306' | |
:comment: '' | |
zbotsqlsock: | |
:raw_key: zbotsqlsock | |
:raw_value: ! '"/var/lib/mysql/mysql.sock"' | |
:unquoted: /var/lib/mysql/mysql.sock | |
:comment: ! ' #"/var/run/mysqld/mysqld.sock"' | |
zbotusechanprivmsg: | |
:raw_key: zbotUseChanPrivmsg | |
:raw_value: '1' | |
:unquoted: '1' | |
:comment: '' | |
zbotfpchanneltime: | |
:raw_key: zbotFPChannelTime | |
:raw_value: ! '"1"' | |
:unquoted: '1' | |
:comment: '' | |
zbotfpusertime: | |
:raw_key: zbotFPUserTime | |
:raw_value: ! '"1"' | |
:unquoted: '1' | |
:comment: '' | |
zbotuseflatdb: | |
:raw_key: ZbotUseFlatDB | |
:raw_value: '0' | |
:unquoted: '0' | |
:comment: '' | |
-------------------------------------------------------------------------------- | |
Grouped Settings: | |
--- | |
mysql: | |
mysqlhost: | |
:raw_key: MysqlHost | |
:raw_value: ! '"localhost"' | |
:unquoted: localhost | |
:comment: '' | |
mysqluser: | |
:raw_key: MysqlUser | |
:raw_value: ! '"username"' | |
:unquoted: username | |
:comment: '' | |
mysqlpass: | |
:raw_key: MysqlPass | |
:raw_value: ! '"password"' | |
:unquoted: password | |
:comment: '' | |
mysqlname: | |
:raw_key: MysqlName | |
:raw_value: ! '"dbname"' | |
:unquoted: dbname | |
:comment: '' | |
mysqlsock: | |
:raw_key: MysqlSock | |
:raw_value: ! '"/var/lib/mysql/mysql.sock"' | |
:unquoted: /var/lib/mysql/mysql.sock | |
:comment: '' | |
mysqlport: | |
:raw_key: MysqlPort | |
:raw_value: ! '"3306"' | |
:unquoted: '3306' | |
:comment: '' | |
zbot: | |
zbotsqldb: | |
:raw_key: zbotsqldb | |
:raw_value: ! '"database"' | |
:unquoted: database | |
:comment: '' | |
zbotsqluser: | |
:raw_key: zbotsqluser | |
:raw_value: ! '"user"' | |
:unquoted: user | |
:comment: '' | |
zbotsqlpass: | |
:raw_key: zbotsqlpass | |
:raw_value: ! '"password"' | |
:unquoted: password | |
:comment: '' | |
zbotsqlhost: | |
:raw_key: zbotsqlhost | |
:raw_value: ! '"localhost"' | |
:unquoted: localhost | |
:comment: '' | |
zbotsqlport: | |
:raw_key: zbotsqlport | |
:raw_value: '3306' | |
:unquoted: '3306' | |
:comment: '' | |
zbotsqlsock: | |
:raw_key: zbotsqlsock | |
:raw_value: ! '"/var/lib/mysql/mysql.sock"' | |
:unquoted: /var/lib/mysql/mysql.sock | |
:comment: ! ' #"/var/run/mysqld/mysqld.sock"' | |
zbotusechanprivmsg: | |
:raw_key: zbotUseChanPrivmsg | |
:raw_value: '1' | |
:unquoted: '1' | |
:comment: '' | |
zbotfpchanneltime: | |
:raw_key: zbotFPChannelTime | |
:raw_value: ! '"1"' | |
:unquoted: '1' | |
:comment: '' | |
zbotfpusertime: | |
:raw_key: zbotFPUserTime | |
:raw_value: ! '"1"' | |
:unquoted: '1' | |
:comment: '' | |
zbotuseflatdb: | |
:raw_key: ZbotUseFlatDB | |
:raw_value: '0' | |
:unquoted: '0' | |
:comment: '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment