summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c8
-rw-r--r--snac.h1
-rw-r--r--utils.c24
3 files changed, 27 insertions, 6 deletions
diff --git a/data.c b/data.c
index bbd0e0c..7197320 100644
--- a/data.c
+++ b/data.c
@@ -156,6 +156,14 @@ int srv_open(const char *basedir, int auto_upgrade)
156 /* read (and drop) emojis.json, possibly creating it */ 156 /* read (and drop) emojis.json, possibly creating it */
157 xs_free(emojis()); 157 xs_free(emojis());
158 158
159 /* if style.css does not exist, create it */
160 xs *css_fn = xs_fmt("%s/style.css", srv_basedir);
161
162 if (mtime(css_fn) == 0) {
163 srv_log(xs_fmt("Writing style.css"));
164 write_default_css();
165 }
166
159 return ret; 167 return ret;
160} 168}
161 169
diff --git a/snac.h b/snac.h
index 8f02f0a..65bfb84 100644
--- a/snac.h
+++ b/snac.h
@@ -347,6 +347,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
347 char **body, int *b_size, char **ctype); 347 char **body, int *b_size, char **ctype);
348xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc); 348xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc);
349 349
350int write_default_css(void);
350int snac_init(const char *_basedir); 351int snac_init(const char *_basedir);
351int adduser(const char *uid); 352int adduser(const char *uid);
352int resetpwd(snac *snac); 353int resetpwd(snac *snac);
diff --git a/utils.c b/utils.c
index d5c2ee4..09a201b 100644
--- a/utils.c
+++ b/utils.c
@@ -107,6 +107,22 @@ static const char *greeting_html =
107 "<p>This site is powered by <abbr title=\"Social Networks Are Crap\">snac</abbr>.</p>\n" 107 "<p>This site is powered by <abbr title=\"Social Networks Are Crap\">snac</abbr>.</p>\n"
108 "</body></html>\n"; 108 "</body></html>\n";
109 109
110
111int write_default_css(void)
112{
113 FILE *f;
114
115 xs *sfn = xs_fmt("%s/style.css", srv_basedir);
116 if ((f = fopen(sfn, "w")) == NULL)
117 return 1;
118
119 fwrite(default_css, strlen(default_css), 1, f);
120 fclose(f);
121
122 return 0;
123}
124
125
110int snac_init(const char *basedir) 126int snac_init(const char *basedir)
111{ 127{
112 FILE *f; 128 FILE *f;
@@ -217,15 +233,11 @@ int snac_init(const char *basedir)
217 fwrite(gh, strlen(gh), 1, f); 233 fwrite(gh, strlen(gh), 1, f);
218 fclose(f); 234 fclose(f);
219 235
220 xs *sfn = xs_fmt("%s/style.css", srv_basedir); 236 if (write_default_css()) {
221 if ((f = fopen(sfn, "w")) == NULL) { 237 printf("ERROR: cannot create style.css\n");
222 printf("ERROR: cannot create '%s'\n", sfn);
223 return 1; 238 return 1;
224 } 239 }
225 240
226 fwrite(default_css, strlen(default_css), 1, f);
227 fclose(f);
228
229 xs *cfn = xs_fmt("%s/server.json", srv_basedir); 241 xs *cfn = xs_fmt("%s/server.json", srv_basedir);
230 if ((f = fopen(cfn, "w")) == NULL) { 242 if ((f = fopen(cfn, "w")) == NULL) {
231 printf("ERROR: cannot create '%s'\n", cfn); 243 printf("ERROR: cannot create '%s'\n", cfn);