mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
Add support for auto-detetcing OS heading for progress
This patch removes the cognitive overhead of having to manually set your OS heading, --with-heading="Foo OS vX.YY". As of this patch, Finit by default extracts PRETTY_NAME from /etc/os-release. It is now possible to also disable the heading entirely using --without-heading Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+6
-4
@@ -86,7 +86,7 @@ AC_PLUGIN([urandom], [yes], [Setup and save random seed at boot/shutdown])
|
||||
|
||||
# Check for extra arguments or packages
|
||||
AC_ARG_WITH(heading,
|
||||
AS_HELP_STRING([--with-heading=GREET], [Display GREET instead of Finit version at boot]),
|
||||
AS_HELP_STRING([--with-heading=GREET], [Heading for boot progress. Default: PRETTY_NAME from /etc/os-release, fallback to "Finit vX.YY"]),
|
||||
[heading=$withval], [heading=yes])
|
||||
|
||||
AC_ARG_WITH(config,
|
||||
@@ -170,9 +170,8 @@ AS_IF([test "x$with_sysconfig" != "xno"], [
|
||||
[System environment, default /etc/default & /etc/conf.d])])])
|
||||
|
||||
AS_IF([test "x$with_heading" != "xno"], [
|
||||
AS_IF([test "x$heading" = "xyes"], [
|
||||
heading="$PACKAGE_NAME v$PACKAGE_VERSION"])])
|
||||
AC_DEFINE_UNQUOTED(INIT_HEADING, "$heading", [Displayed by Finit at boot])
|
||||
AS_IF([test "x$heading" = "xyes"], [heading=""])
|
||||
AC_DEFINE_UNQUOTED(INIT_OSHEADING, "$heading", [Displayed by Finit at boot, defaults to /etc/os-release PRETTY_NAME])])
|
||||
|
||||
AS_IF([test "x$with_hostname" != "xno"], [
|
||||
AS_IF([test "x$hostname" = "xyes"], [
|
||||
@@ -222,6 +221,9 @@ AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
|
||||
AC_EXPAND_DIR(sample_conf, "$libdir/finit/sample.conf")
|
||||
AC_DEFINE_UNQUOTED(SAMPLE_CONF, "$sample_conf", [Finit sameple.conf for initctl create])
|
||||
|
||||
AS_IF([test "$heading" = ""], [heading="<DEFAULT>"])
|
||||
AS_IF([test "$heading" = "no"], [heading="<NONE>"])
|
||||
|
||||
# Generate all files
|
||||
AC_OUTPUT
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
|
||||
--sysconfdir=/etc --localstatedir=/var \
|
||||
--enable-dbus-plugin --enable-x11-common-plugin \
|
||||
--enable-alsa-utils-plugin --with-watchdog \
|
||||
--with-heading="Alpine Linux" --with-keventd
|
||||
--with-keventd
|
||||
|
||||
echo
|
||||
echo "*** Building ..."
|
||||
|
||||
@@ -26,8 +26,7 @@ echo
|
||||
--sysconfdir=/etc --localstatedir=/var \
|
||||
--enable-dbus-plugin --enable-x11-common-plugin \
|
||||
--enable-alsa-utils-plugin --with-keventd \
|
||||
--with-random-seed=/var/lib/urandom/random-seed \
|
||||
--with-heading="Debian GNU/Linux"
|
||||
--with-random-seed=/var/lib/urandom/random-seed
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo
|
||||
|
||||
@@ -18,7 +18,7 @@ PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
|
||||
--sysconfdir=/etc --localstatedir=/var \
|
||||
--enable-dbus-plugin --enable-x11-common-plugin \
|
||||
--enable-alsa-utils-plugin --with-watchdog \
|
||||
--with-heading="Void Linux" --with-keventd
|
||||
--with-keventd
|
||||
|
||||
echo
|
||||
echo "*** Building ..."
|
||||
|
||||
+1
-2
@@ -83,8 +83,7 @@ Then configure, build and install:
|
||||
```shell
|
||||
$ ./configure --prefix=/usr --exec-prefix= \
|
||||
--sysconfdir=/etc --localstatedir=/var \
|
||||
--with-keventd --with-watchdog \
|
||||
--with-heading="Alpine Linux" --with-hostname=alpine
|
||||
--with-keventd --with-watchdog
|
||||
$ make
|
||||
.
|
||||
.
|
||||
|
||||
+9
-1
@@ -66,6 +66,7 @@ char *network = NULL;
|
||||
char *hostname = NULL;
|
||||
char *rcsd = FINIT_RCSD;
|
||||
char *runparts = NULL;
|
||||
char *osheading = NULL;
|
||||
|
||||
uev_ctx_t *ctx = NULL; /* Main loop context */
|
||||
svc_t *wdog = NULL; /* No watchdog by default */
|
||||
@@ -90,7 +91,14 @@ static void banner(void)
|
||||
*/
|
||||
plugin_run_hooks(HOOK_BANNER);
|
||||
|
||||
print_banner(INIT_HEADING);
|
||||
#ifdef INIT_OSHEADING
|
||||
osheading = INIT_OSHEADING;
|
||||
if (osheading) {
|
||||
if (!osheading[0])
|
||||
osheading = release_heading();
|
||||
print_banner(osheading);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -115,6 +115,7 @@ extern char *sdown;
|
||||
extern char *network;
|
||||
extern char *hostname;
|
||||
extern char *runparts;
|
||||
extern char *osheading;
|
||||
extern uev_ctx_t *ctx;
|
||||
|
||||
#endif /* FINIT_H_ */
|
||||
|
||||
@@ -124,6 +124,49 @@ void show_progress(pstyle_t style)
|
||||
progress_onoff = style;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find PRETTY_NAME in /etc/os-release to use as heading at boot
|
||||
* and on runlevel changes. Fallback: "Finit vX.YY"
|
||||
*/
|
||||
char *release_heading(void)
|
||||
{
|
||||
char *name = NULL;
|
||||
char buf[256];
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen("/etc/os-release", "r");
|
||||
if (fp) {
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
char *ptr = &buf[12];
|
||||
|
||||
if (strncmp(buf, "PRETTY_NAME=", 12))
|
||||
continue;
|
||||
|
||||
if (*ptr == '"' || *ptr == '\"') {
|
||||
char *end = &ptr[strlen(ptr) - 1];
|
||||
char q = *ptr;
|
||||
|
||||
while (end > ptr && isspace(*end))
|
||||
*end-- = 0;
|
||||
|
||||
if (*end == q) {
|
||||
*end = 0;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
name = strdup(ptr);
|
||||
break;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
if (!name)
|
||||
name = strdup(PACKAGE_NAME " v" PACKAGE_VERSION);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return screen length of string, not counting escape chars, and
|
||||
* accounting for unicode characters as only one screen byte wide
|
||||
|
||||
@@ -68,6 +68,8 @@ char *strip_line (char *line);
|
||||
void enable_progress (int onoff);
|
||||
void show_progress (pstyle_t style);
|
||||
|
||||
char *release_heading (void);
|
||||
|
||||
speed_t stty_parse_speed(char *baud);
|
||||
void stty (int fd, speed_t speed);
|
||||
|
||||
|
||||
@@ -150,7 +150,10 @@ restart:
|
||||
}
|
||||
|
||||
_d("Setting new runlevel --> %d <-- previous %d", runlevel, prevlevel);
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "%s, entering runlevel %d", INIT_HEADING, runlevel);
|
||||
if (osheading)
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "%s, entering runlevel %d", osheading, runlevel);
|
||||
else
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Entering runlevel %d", runlevel);
|
||||
runlevel_set(prevlevel, runlevel);
|
||||
|
||||
/* Disable login in single-user mode as well as shutdown/reboot */
|
||||
|
||||
Reference in New Issue
Block a user