From 53c65afa1508cfc89ff3c38909ad1a956a57c28f Mon Sep 17 00:00:00 2001 From: Lukas Nykryn Date: Fri, 20 Sep 2013 13:22:32 +0200 Subject: brandbot: tool to write branding to /etc/os-release (#1009947) --- src/Makefile | 10 +++++++++- src/brandbot.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/brandbot.c (limited to 'src') diff --git a/src/Makefile b/src/Makefile index dc4bf593..07d1f1f9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,9 +1,10 @@ CFLAGS+=$(RPM_OPT_FLAGS) -Wall -D_GNU_SOURCE LDFLAGS+=$(RPM_LD_FLAGS) -PROGS=usernetctl netreport usleep ipcalc \ +PROGS=usernetctl netreport usleep ipcalc brandbot \ ppp-watch consoletype genhostid rename_device PPPWATCH_OBJS=ppp-watch.o shvar.o +BRANDBOT_OBJS=brandbot.o shvar.o CONSOLE_INIT_OBJS=console_init.o shvar.o USLEEP_OBJS=usleep.o @@ -27,6 +28,7 @@ install: install -m 755 ppp-watch $(ROOT)/usr/sbin/ppp-watch install -m 755 consoletype $(ROOT)/usr/sbin/consoletype install -m 755 sushell $(ROOT)/usr/sbin/sushell + install -m 755 brandbot $(ROOT)/usr/sbin/brandbot install -m 755 rename_device $(ROOT)/usr/lib/udev/rename_device install -m 644 genhostid.1 $(ROOT)$(mandir)/man1 install -m 644 netreport.1 $(ROOT)$(mandir)/man1 @@ -48,6 +50,9 @@ usleep: $(USLEEP_OBJS) ppp-watch: $(PPPWATCH_OBJS) $(CC) $(LDFLAGS) -o $@ $(PPPWATCH_OBJS) `pkg-config glib-2.0 --libs` +brandbot: $(BRANDBOT_OBJS) + $(CC) $(LDFLAGS) -o $@ $(BRANDBOT_OBJS) `pkg-config glib-2.0 --libs` + usernetctl.o: usernetctl.c $(CC) $(CFLAGS) -fPIE -c usernetctl.c -o usernetctl.o @@ -63,6 +68,9 @@ netreport: netreport.o shvar.o: shvar.c $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c shvar.c -o shvar.o +brandbot.o: brandbot.c + $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c brandbot.c -o brandbot.o + ppp-watch.o: ppp-watch.c $(CC) $(CFLAGS) `pkg-config glib-2.0 --cflags` -c ppp-watch.c -o ppp-watch.o diff --git a/src/brandbot.c b/src/brandbot.c new file mode 100644 index 00000000..c9b21ecd --- /dev/null +++ b/src/brandbot.c @@ -0,0 +1,36 @@ + +#include +#include + +#include + +#include "shvar.h" + +char *read_name() { + gchar *name = NULL; + + g_file_get_contents("/var/lib/rhsm/branded_name", &name, NULL, NULL); + if (name) + name = g_strstrip(name); + return name; +} + +int main(int argc, char **argv) { + shvarFile *osrelease; + char *newname, *oldname; + int rc = 0; + + newname = read_name(); + if (!newname) + return 0; + osrelease = svNewFile("/etc/os-release"); + if (!osrelease) + return 0; + oldname = svGetValue(osrelease, "PRETTY_NAME"); + if (!strcmp(oldname, newname)) + return 0; + svSetValue(osrelease, "PRETTY_NAME", newname); + rc += svWriteFile(osrelease, 0644); + svCloseFile(osrelease); + return rc; +} -- cgit v1.2.1