aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Nykryn <lnykryn@redhat.com>2013-09-20 13:22:32 +0200
committerLukas Nykryn <lnykryn@redhat.com>2013-09-23 15:20:04 +0200
commit53c65afa1508cfc89ff3c38909ad1a956a57c28f (patch)
tree714c53891a0f7da25f06e40cf6c91bf82241b1c1 /src
parent363999c2255fd41d1548956d9ca04c0655ffabdb (diff)
downloadinitscripts-53c65afa1508cfc89ff3c38909ad1a956a57c28f.tar
initscripts-53c65afa1508cfc89ff3c38909ad1a956a57c28f.tar.gz
initscripts-53c65afa1508cfc89ff3c38909ad1a956a57c28f.tar.bz2
initscripts-53c65afa1508cfc89ff3c38909ad1a956a57c28f.tar.xz
initscripts-53c65afa1508cfc89ff3c38909ad1a956a57c28f.zip
brandbot: tool to write branding to /etc/os-release (#1009947)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile10
-rw-r--r--src/brandbot.c36
2 files changed, 45 insertions, 1 deletions
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 <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#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;
+}