1package Magus::Config; 2# 3# Copyright (C) 2025 Lucas Holt 4# Copyright (c) 2007,2008 Chris Reinhardt. All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: 9# 10# 1. Redistributions of source code must retain the above copyright notice 11# this list of conditions and the following disclaimer. 12# 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 18# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 19# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28 29 30use strict; 31use warnings; 32use YAML qw(LoadFile); 33use Sys::Hostname qw(hostname); 34 35our %Config; 36 37sub import { 38 no strict 'refs'; 39 40 my $caller = caller; 41 42 *{"$caller\::Config"} = \%Config; 43} 44 45sub load_config { 46 my $file = shift; 47 48 my %filecfg = %{LoadFile($file)}; 49 50 %Config = ( 51 # defaults 52 DBHost => 'localhost', 53 DBName => 'magus', 54 DBUser => 'magus', 55 Machine => hostname(), 56 DoneWaitPeriod => 200, 57 ChrootTarBall => '/usr/magus/os.tar.xz', 58 DistfilesRoot => '/mnt/magus/distfiles', 59 PkgfilesRoot => '/mnt/magus/packages', 60 PkgExtension => 'mport', 61 MasterDataDir => 'ftp://stargazer.midnightbsd.org/pub/magus', 62 MportsSnapDir => 'runs', 63 VcsRoot => 'https://github.com/midnightbsd/', 64 SlaveSrcDir => '/usr/src', 65 SlavePidFile => '/var/run/magus.pid', 66 MemoryDiskSize => '32G', 67 MemoryDiskEnabled => 0, 68 69 # file values override defaults 70 %filecfg, 71 ); 72 73 # More defaults 74 $Config{SlaveDataDir} ||= "$Magus::Root/slave-data"; 75 $Config{SlaveMportsDir} ||= "$Config{SlaveDataDir}/mports"; 76 $Config{SlaveChrootsDir} ||= "$Config{SlaveDataDir}/chroots"; 77 $Config{LostDBWaitPeriod} ||= 120; 78} 79 80BEGIN {load_config("$Magus::Root/config.yaml")}; 81 821; 83__END__ 84 85