diff --git a/src/Hydra/lib/Hydra/Helper/Nix.pm b/src/Hydra/lib/Hydra/Helper/Nix.pm index 3b928803..a6dcaa65 100644 --- a/src/Hydra/lib/Hydra/Helper/Nix.pm +++ b/src/Hydra/lib/Hydra/Helper/Nix.pm @@ -15,7 +15,7 @@ sub isValidPath { sub getHydraPath { - my $dir = $ENV{HYDRA_DATA}; + my $dir = $ENV{"HYDRA_DATA"}; die "The HYDRA_DATA environment variable is not set!\n" unless defined $dir; die "The HYDRA_DATA directory does not exist!\n" unless -d $dir; return $dir; diff --git a/src/Hydra/script/hydra_init.pl b/src/Hydra/script/hydra_init.pl new file mode 100755 index 00000000..0676b8b0 --- /dev/null +++ b/src/Hydra/script/hydra_init.pl @@ -0,0 +1,15 @@ +#!/var/run/current-system/sw/bin/perl -w + +use strict; +use Hydra::Helper::Nix; + +my $hydraHome = $ENV{"HYDRA_HOME"}; +die "The HYDRA_HOME environment variable is not set!\n" unless defined $hydraHome; + +my $hydraData = $ENV{"HYDRA_DATA"}; +mkdir $hydraData unless -d $hydraData; + +my $dbPath = getHydraPath . "/hydra.sqlite"; + +system("sqlite3 $dbPath < $hydraHome/sql/hydra.sql") == 0 + or warn "Cannot initialise database in $dbPath"; diff --git a/src/hydra.sql b/src/Hydra/sql/hydra.sql similarity index 99% rename from src/hydra.sql rename to src/Hydra/sql/hydra.sql index 31962321..94e23a24 100644 --- a/src/hydra.sql +++ b/src/Hydra/sql/hydra.sql @@ -155,7 +155,7 @@ create table Projects ( name text primary key not null, -- project id, lowercase (e.g. "patchelf") displayName text not null, -- display name (e.g. "PatchELF") description text, - enabled integer not null default 1 + enabled integer not null default 1, owner text not null, foreign key (owner) references Users(userName) -- ignored by sqlite );