0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd:Ⓜ️ Move bootstrap to module.

modules/m_init_bootstrap: Trigger bootstrap via import.
This commit is contained in:
Jason Volk 2019-07-14 15:42:36 -07:00
parent 2ad1c3acb9
commit 58aad0194b
3 changed files with 107 additions and 78 deletions

View file

@ -52,7 +52,7 @@ try
std::make_unique<modules>()
}
{
if(!ircd::write_avoid)
if(!ircd::write_avoid && vm::sequence::retired != 0)
presence::set(me, "online", me_online_status_msg);
}
catch(const m::error &e)
@ -156,8 +156,26 @@ ircd::m::init::modules::init_imports()
throw;
}
if(db::sequence(*dbs::events) == 0)
if(vm::sequence::retired == 0)
{
log::notice
{
log, "This appears to be your first time running IRCd because the events "
"database is empty. I will be bootstrapping it with initial events now..."
};
const module m_init_bootstrap
{
"m_init_bootstrap"
};
const mods::import<void ()> bootstrap
{
m_init_bootstrap, "ircd::m::init::bootstrap"
};
bootstrap();
}
}
void
@ -300,82 +318,6 @@ ircd::m::module_names_optional
"media_magick",
};
void
ircd::m::init::bootstrap()
try
{
assert(dbs::events);
assert(db::sequence(*dbs::events) == 0);
log::notice
{
log, "This appears to be your first time running IRCd because the events "
"database is empty. I will be bootstrapping it with initial events now..."
};
if(me.user_id.hostname() == "localhost")
log::warning
{
"The ircd.origin is configured to localhost. This is probably not"
" what you want. To fix this now, you will have to remove the "
" database and start over."
};
if(!exists(user::users))
create(user::users, me.user_id, "internal");
if(!exists(my_room))
create(my_room, me.user_id, "internal");
if(!exists(me))
{
create(me.user_id);
me.activate();
}
if(!my_room.membership(me.user_id, "join"))
join(my_room, me.user_id);
if(!my_room.has("m.room.name", ""))
send(my_room, me.user_id, "m.room.name", "",
{
{ "name", "IRCd's Room" }
});
if(!my_room.has("m.room.topic", ""))
send(my_room, me.user_id, "m.room.topic", "",
{
{ "topic", "The daemon's den." }
});
if(!user::users.has("m.room.name", ""))
send(user::users, me.user_id, "m.room.name", "",
{
{ "name", "Users" }
});
if(!exists(user::tokens))
create(user::tokens, me.user_id);
if(!user::tokens.has("m.room.name",""))
send(user::tokens, me.user_id, "m.room.name", "",
{
{ "name", "User Tokens" }
});
log::info
{
log, "Bootstrap event generation completed nominally."
};
}
catch(const std::exception &e)
{
throw ircd::panic
{
"bootstrap error :%s", e.what()
};
}
///////////////////////////////////////////////////////////////////////////////
//
// m/self.h

View file

@ -116,6 +116,7 @@ m_room_aliases_la_SOURCES = m_room_aliases.cc
m_room_message_la_SOURCES = m_room_message.cc
m_room_power_levels_la_SOURCES = m_room_power_levels.cc
m_room_server_acl_la_SOURCES = m_room_server_acl.cc
m_init_bootstrap_la_SOURCES = m_init_bootstrap.cc
m_module_LTLIBRARIES = \
m_vm.la \
@ -147,6 +148,7 @@ m_module_LTLIBRARIES = \
m_room_message.la \
m_room_power_levels.la \
m_room_server_acl.la \
m_init_bootstrap.la \
###
###############################################################################

View file

@ -0,0 +1,85 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
ircd::mapi::header
IRCD_MODULE
{
"Matrix initial bootstrap support."
};
void
IRCD_MODULE_EXPORT
ircd::m::init::bootstrap()
try
{
assert(dbs::events);
assert(db::sequence(*dbs::events) == 0);
if(me.user_id.hostname() == "localhost")
log::warning
{
"The ircd.origin is configured to localhost. This is probably not"
" what you want. To fix this now, you will have to remove the "
" database and start over."
};
if(!exists(user::users))
create(user::users, me.user_id, "internal");
if(!exists(my_room))
create(my_room, me.user_id, "internal");
if(!exists(me))
{
create(me.user_id);
me.activate();
}
if(!my_room.membership(me.user_id, "join"))
join(my_room, me.user_id);
if(!my_room.has("m.room.name", ""))
send(my_room, me.user_id, "m.room.name", "",
{
{ "name", "IRCd's Room" }
});
if(!my_room.has("m.room.topic", ""))
send(my_room, me.user_id, "m.room.topic", "",
{
{ "topic", "The daemon's den." }
});
if(!user::users.has("m.room.name", ""))
send(user::users, me.user_id, "m.room.name", "",
{
{ "name", "Users" }
});
if(!exists(user::tokens))
create(user::tokens, me.user_id);
if(!user::tokens.has("m.room.name",""))
send(user::tokens, me.user_id, "m.room.name", "",
{
{ "name", "User Tokens" }
});
log::info
{
log, "Bootstrap event generation completed nominally."
};
}
catch(const std::exception &e)
{
throw ircd::panic
{
"bootstrap error :%s", e.what()
};
}