Fossil SCM

Add the --create option to "fossil server", which causes a new repository to be created for the server is one does not already exist. The intended use case is Docker.

drh 2015-03-18 14:17 trunk
Commit a6e2ceb4541526f29a380733df5c5908c80f529c
+1 -3
--- Dockerfile
+++ Dockerfile
@@ -20,10 +20,8 @@
2020
2121
USER fossil
2222
2323
ENV HOME /opt/fossil
2424
25
-RUN fossil new --docker -A admin /opt/fossil/repository.fossil && fossil user password -R /opt/fossil/repository.fossil admin admin && fossil cache init -R /opt/fossil/repository.fossil
26
-
2725
EXPOSE 8080
2826
29
-CMD ["/usr/bin/fossil", "server", "/opt/fossil/repository.fossil"]
27
+CMD ["/usr/bin/fossil", "server", "--create", "/opt/fossil/repository.fossil"]
3028
--- Dockerfile
+++ Dockerfile
@@ -20,10 +20,8 @@
20
21 USER fossil
22
23 ENV HOME /opt/fossil
24
25 RUN fossil new --docker -A admin /opt/fossil/repository.fossil && fossil user password -R /opt/fossil/repository.fossil admin admin && fossil cache init -R /opt/fossil/repository.fossil
26
27 EXPOSE 8080
28
29 CMD ["/usr/bin/fossil", "server", "/opt/fossil/repository.fossil"]
30
--- Dockerfile
+++ Dockerfile
@@ -20,10 +20,8 @@
20
21 USER fossil
22
23 ENV HOME /opt/fossil
24
 
 
25 EXPOSE 8080
26
27 CMD ["/usr/bin/fossil", "server", "--create", "/opt/fossil/repository.fossil"]
28
--- src/cache.c
+++ src/cache.c
@@ -226,10 +226,18 @@
226226
cache_read_done:
227227
sqlite3_exec(db, "COMMIT", 0, 0, 0);
228228
sqlite3_close(db);
229229
return rc;
230230
}
231
+
232
+/*
233
+** Create a cache database for the current repository if no such
234
+** database already exists.
235
+*/
236
+void cache_initialize(void){
237
+ sqlite3_close(cacheOpen(1));
238
+}
231239
232240
/*
233241
** COMMAND: cache*
234242
** Usage: %fossil cache SUBCOMMAND
235243
**
236244
--- src/cache.c
+++ src/cache.c
@@ -226,10 +226,18 @@
226 cache_read_done:
227 sqlite3_exec(db, "COMMIT", 0, 0, 0);
228 sqlite3_close(db);
229 return rc;
230 }
 
 
 
 
 
 
 
 
231
232 /*
233 ** COMMAND: cache*
234 ** Usage: %fossil cache SUBCOMMAND
235 **
236
--- src/cache.c
+++ src/cache.c
@@ -226,10 +226,18 @@
226 cache_read_done:
227 sqlite3_exec(db, "COMMIT", 0, 0, 0);
228 sqlite3_close(db);
229 return rc;
230 }
231
232 /*
233 ** Create a cache database for the current repository if no such
234 ** database already exists.
235 */
236 void cache_initialize(void){
237 sqlite3_close(cacheOpen(1));
238 }
239
240 /*
241 ** COMMAND: cache*
242 ** Usage: %fossil cache SUBCOMMAND
243 **
244
+1 -1
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164164
}else{
165165
db_create_repository(g.argv[3]);
166166
db_open_repository(g.argv[3]);
167167
db_begin_transaction();
168168
db_record_repository_filename(g.argv[3]);
169
- db_initial_setup(0, 0, zDefaultUser, 0);
169
+ db_initial_setup(0, 0, zDefaultUser);
170170
user_select();
171171
db_set("content-schema", CONTENT_SCHEMA, 0);
172172
db_set("aux-schema", AUX_SCHEMA_MAX, 0);
173173
db_set("rebuilt", get_version(), 0);
174174
remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
175175
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 }else{
165 db_create_repository(g.argv[3]);
166 db_open_repository(g.argv[3]);
167 db_begin_transaction();
168 db_record_repository_filename(g.argv[3]);
169 db_initial_setup(0, 0, zDefaultUser, 0);
170 user_select();
171 db_set("content-schema", CONTENT_SCHEMA, 0);
172 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
173 db_set("rebuilt", get_version(), 0);
174 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
175
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 }else{
165 db_create_repository(g.argv[3]);
166 db_open_repository(g.argv[3]);
167 db_begin_transaction();
168 db_record_repository_filename(g.argv[3]);
169 db_initial_setup(0, 0, zDefaultUser);
170 user_select();
171 db_set("content-schema", CONTENT_SCHEMA, 0);
172 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
173 db_set("rebuilt", get_version(), 0);
174 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
175
+8 -38
--- src/db.c
+++ src/db.c
@@ -1475,42 +1475,10 @@
14751475
" VALUES('reader','','kptw','Reader');"
14761476
);
14771477
}
14781478
}
14791479
1480
-/*
1481
-** This function sets the server and project codes if they do not already
1482
-** exist. Currently, it should be called only by the db_initial_setup()
1483
-** or cmd_webserver() functions, the latter being used to facilitate more
1484
-** robust integration with "canned image" environments (e.g. Docker).
1485
-*/
1486
-void db_setup_server_and_project_codes(
1487
- int optional
1488
-){
1489
- if( !optional ){
1490
- db_multi_exec(
1491
- "INSERT INTO config(name,value,mtime)"
1492
- " VALUES('server-code', lower(hex(randomblob(20))),now());"
1493
- "INSERT INTO config(name,value,mtime)"
1494
- " VALUES('project-code', lower(hex(randomblob(20))),now());"
1495
- );
1496
- }else if( db_is_writeable("repository") ){
1497
- if( db_get("server-code", 0)==0 ) {
1498
- db_multi_exec(
1499
- "INSERT INTO config(name,value,mtime)"
1500
- " VALUES('server-code', lower(hex(randomblob(20))),now());"
1501
- );
1502
- }
1503
- if( db_get("project-code", 0)==0 ) {
1504
- db_multi_exec(
1505
- "INSERT INTO config(name,value,mtime)"
1506
- " VALUES('project-code', lower(hex(randomblob(20))),now());"
1507
- );
1508
- }
1509
- }
1510
-}
1511
-
15121480
/*
15131481
** Return a pointer to a string that contains the RHS of an IN operator
15141482
** that will select CONFIG table names that are in the list of control
15151483
** settings.
15161484
*/
@@ -1548,23 +1516,25 @@
15481516
** not server and project codes are invented for this repository.
15491517
*/
15501518
void db_initial_setup(
15511519
const char *zTemplate, /* Repository from which to copy settings. */
15521520
const char *zInitialDate, /* Initial date of repository. (ex: "now") */
1553
- const char *zDefaultUser, /* Default user for the repository */
1554
- int makeServerCodes /* True to make new server & project codes */
1521
+ const char *zDefaultUser /* Default user for the repository */
15551522
){
15561523
char *zDate;
15571524
Blob hash;
15581525
Blob manifest;
15591526
15601527
db_set("content-schema", CONTENT_SCHEMA, 0);
15611528
db_set("aux-schema", AUX_SCHEMA_MAX, 0);
15621529
db_set("rebuilt", get_version(), 0);
1563
- if( makeServerCodes ){
1564
- db_setup_server_and_project_codes(0);
1565
- }
1530
+ db_multi_exec(
1531
+ "INSERT INTO config(name,value,mtime)"
1532
+ " VALUES('server-code', lower(hex(randomblob(20))),now());"
1533
+ "INSERT INTO config(name,value,mtime)"
1534
+ " VALUES('project-code', lower(hex(randomblob(20))),now());"
1535
+ );
15661536
if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
15671537
if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
15681538
if( !db_is_global("timeline-plaintext") ){
15691539
db_set_int("timeline-plaintext", 1, 0);
15701540
}
@@ -1687,11 +1657,11 @@
16871657
db_open_repository(g.argv[2]);
16881658
db_open_config(0);
16891659
if( zTemplate ) db_attach(zTemplate, "settingSrc");
16901660
db_begin_transaction();
16911661
if( zDate==0 ) zDate = "now";
1692
- db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1662
+ db_initial_setup(zTemplate, zDate, zDefaultUser);
16931663
db_end_transaction(0);
16941664
if( zTemplate ) db_detach("settingSrc");
16951665
fossil_print("project-id: %s\n", db_get("project-code", 0));
16961666
fossil_print("server-id: %s\n", db_get("server-code", 0));
16971667
zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
16981668
--- src/db.c
+++ src/db.c
@@ -1475,42 +1475,10 @@
1475 " VALUES('reader','','kptw','Reader');"
1476 );
1477 }
1478 }
1479
1480 /*
1481 ** This function sets the server and project codes if they do not already
1482 ** exist. Currently, it should be called only by the db_initial_setup()
1483 ** or cmd_webserver() functions, the latter being used to facilitate more
1484 ** robust integration with "canned image" environments (e.g. Docker).
1485 */
1486 void db_setup_server_and_project_codes(
1487 int optional
1488 ){
1489 if( !optional ){
1490 db_multi_exec(
1491 "INSERT INTO config(name,value,mtime)"
1492 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1493 "INSERT INTO config(name,value,mtime)"
1494 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1495 );
1496 }else if( db_is_writeable("repository") ){
1497 if( db_get("server-code", 0)==0 ) {
1498 db_multi_exec(
1499 "INSERT INTO config(name,value,mtime)"
1500 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1501 );
1502 }
1503 if( db_get("project-code", 0)==0 ) {
1504 db_multi_exec(
1505 "INSERT INTO config(name,value,mtime)"
1506 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1507 );
1508 }
1509 }
1510 }
1511
1512 /*
1513 ** Return a pointer to a string that contains the RHS of an IN operator
1514 ** that will select CONFIG table names that are in the list of control
1515 ** settings.
1516 */
@@ -1548,23 +1516,25 @@
1548 ** not server and project codes are invented for this repository.
1549 */
1550 void db_initial_setup(
1551 const char *zTemplate, /* Repository from which to copy settings. */
1552 const char *zInitialDate, /* Initial date of repository. (ex: "now") */
1553 const char *zDefaultUser, /* Default user for the repository */
1554 int makeServerCodes /* True to make new server & project codes */
1555 ){
1556 char *zDate;
1557 Blob hash;
1558 Blob manifest;
1559
1560 db_set("content-schema", CONTENT_SCHEMA, 0);
1561 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
1562 db_set("rebuilt", get_version(), 0);
1563 if( makeServerCodes ){
1564 db_setup_server_and_project_codes(0);
1565 }
 
 
 
1566 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1567 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1568 if( !db_is_global("timeline-plaintext") ){
1569 db_set_int("timeline-plaintext", 1, 0);
1570 }
@@ -1687,11 +1657,11 @@
1687 db_open_repository(g.argv[2]);
1688 db_open_config(0);
1689 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1690 db_begin_transaction();
1691 if( zDate==0 ) zDate = "now";
1692 db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1693 db_end_transaction(0);
1694 if( zTemplate ) db_detach("settingSrc");
1695 fossil_print("project-id: %s\n", db_get("project-code", 0));
1696 fossil_print("server-id: %s\n", db_get("server-code", 0));
1697 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1698
--- src/db.c
+++ src/db.c
@@ -1475,42 +1475,10 @@
1475 " VALUES('reader','','kptw','Reader');"
1476 );
1477 }
1478 }
1479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1480 /*
1481 ** Return a pointer to a string that contains the RHS of an IN operator
1482 ** that will select CONFIG table names that are in the list of control
1483 ** settings.
1484 */
@@ -1548,23 +1516,25 @@
1516 ** not server and project codes are invented for this repository.
1517 */
1518 void db_initial_setup(
1519 const char *zTemplate, /* Repository from which to copy settings. */
1520 const char *zInitialDate, /* Initial date of repository. (ex: "now") */
1521 const char *zDefaultUser /* Default user for the repository */
 
1522 ){
1523 char *zDate;
1524 Blob hash;
1525 Blob manifest;
1526
1527 db_set("content-schema", CONTENT_SCHEMA, 0);
1528 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
1529 db_set("rebuilt", get_version(), 0);
1530 db_multi_exec(
1531 "INSERT INTO config(name,value,mtime)"
1532 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1533 "INSERT INTO config(name,value,mtime)"
1534 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1535 );
1536 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1537 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1538 if( !db_is_global("timeline-plaintext") ){
1539 db_set_int("timeline-plaintext", 1, 0);
1540 }
@@ -1687,11 +1657,11 @@
1657 db_open_repository(g.argv[2]);
1658 db_open_config(0);
1659 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1660 db_begin_transaction();
1661 if( zDate==0 ) zDate = "now";
1662 db_initial_setup(zTemplate, zDate, zDefaultUser);
1663 db_end_transaction(0);
1664 if( zTemplate ) db_detach("settingSrc");
1665 fossil_print("project-id: %s\n", db_get("project-code", 0));
1666 fossil_print("server-id: %s\n", db_get("server-code", 0));
1667 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1668
+1 -1
--- src/import.c
+++ src/import.c
@@ -1543,11 +1543,11 @@
15431543
}
15441544
db_open_repository(g.argv[2]);
15451545
db_open_config(0);
15461546
15471547
db_begin_transaction();
1548
- if( !incrFlag ) db_initial_setup(0, 0, 0, 1);
1548
+ if( !incrFlag ) db_initial_setup(0, 0, 0);
15491549
15501550
if( svnFlag ){
15511551
db_multi_exec(
15521552
"CREATE TEMP TABLE xrevisions("
15531553
" trev INTEGER, tbranch INT, trid INT, tparent INT DEFAULT 0,"
15541554
--- src/import.c
+++ src/import.c
@@ -1543,11 +1543,11 @@
1543 }
1544 db_open_repository(g.argv[2]);
1545 db_open_config(0);
1546
1547 db_begin_transaction();
1548 if( !incrFlag ) db_initial_setup(0, 0, 0, 1);
1549
1550 if( svnFlag ){
1551 db_multi_exec(
1552 "CREATE TEMP TABLE xrevisions("
1553 " trev INTEGER, tbranch INT, trid INT, tparent INT DEFAULT 0,"
1554
--- src/import.c
+++ src/import.c
@@ -1543,11 +1543,11 @@
1543 }
1544 db_open_repository(g.argv[2]);
1545 db_open_config(0);
1546
1547 db_begin_transaction();
1548 if( !incrFlag ) db_initial_setup(0, 0, 0);
1549
1550 if( svnFlag ){
1551 db_multi_exec(
1552 "CREATE TEMP TABLE xrevisions("
1553 " trev INTEGER, tbranch INT, trid INT, tparent INT DEFAULT 0,"
1554
+32 -12
--- src/main.c
+++ src/main.c
@@ -2031,19 +2031,38 @@
20312031
** Open the repository to be served if it is known. If g.argv[arg] is
20322032
** a directory full of repositories, then set g.zRepositoryName to
20332033
** the name of that directory and the specific repository will be
20342034
** opened later by process_one_web_page() based on the content of
20352035
** the PATH_INFO variable.
2036
+**
2037
+** If the fCreate flag is set, then create the repository if it
2038
+** does not already exist.
20362039
*/
2037
-static void find_server_repository(int arg){
2040
+static void find_server_repository(int arg, int fCreate){
20382041
if( g.argc<=arg ){
20392042
db_must_be_within_tree();
2040
- }else if( file_isdir(g.argv[arg])==1 ){
2041
- g.zRepositoryName = mprintf("%s", g.argv[arg]);
2042
- file_simplify_name(g.zRepositoryName, -1, 0);
20432043
}else{
2044
- db_open_repository(g.argv[arg]);
2044
+ const char *zRepo = g.argv[arg];
2045
+ int isDir = file_isdir(zRepo);
2046
+ if( isDir==1 ){
2047
+ g.zRepositoryName = mprintf("%s", zRepo);
2048
+ file_simplify_name(g.zRepositoryName, -1, 0);
2049
+ }else{
2050
+ if( isDir==0 && fCreate ){
2051
+ db_create_repository(zRepo);
2052
+ db_open_repository(zRepo);
2053
+ db_begin_transaction();
2054
+ db_initial_setup(0,"now","admin");
2055
+ db_multi_exec("UPDATE user SET pw='admin' WHERE login='admin'");
2056
+ db_end_transaction(0);
2057
+ cache_initialize();
2058
+ g.zLogin = 0;
2059
+ g.userUid = 0;
2060
+ }else{
2061
+ db_open_repository(zRepo);
2062
+ }
2063
+ }
20452064
}
20462065
}
20472066
20482067
/*
20492068
** undocumented format:
@@ -2146,15 +2165,15 @@
21462165
g.fullHttpReply = 1;
21472166
if( g.argc>=5 ){
21482167
g.httpIn = fossil_fopen(g.argv[2], "rb");
21492168
g.httpOut = fossil_fopen(g.argv[3], "wb");
21502169
zIpAddr = g.argv[4];
2151
- find_server_repository(5);
2170
+ find_server_repository(5, 0);
21522171
}else{
21532172
g.httpIn = stdin;
21542173
g.httpOut = stdout;
2155
- find_server_repository(2);
2174
+ find_server_repository(2, 0);
21562175
}
21572176
if( zIpAddr==0 ){
21582177
zIpAddr = cgi_ssh_remote_addr(0);
21592178
if( zIpAddr && zIpAddr[0] ){
21602179
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2197,11 +2216,11 @@
21972216
Th_InitTraceLog();
21982217
login_set_capabilities("sx", 0);
21992218
g.useLocalauth = 1;
22002219
g.httpIn = stdin;
22012220
g.httpOut = stdout;
2202
- find_server_repository(2);
2221
+ find_server_repository(2, 0);
22032222
g.cgiOutput = 1;
22042223
g.fullHttpReply = 1;
22052224
zIpAddr = cgi_ssh_remote_addr(0);
22062225
if( zIpAddr && zIpAddr[0] ){
22072226
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2276,10 +2295,11 @@
22762295
** connection is from localhost. The "ui" command also enables --repolist
22772296
** by default.
22782297
**
22792298
** Options:
22802299
** --baseurl URL Use URL as the base (useful for reverse proxies)
2300
+** --create Create a new REPOSITORY if it does not already exist
22812301
** --files GLOBLIST Comma-separated list of glob patterns for static files
22822302
** --localauth enable automatic login for requests from localhost
22832303
** --localhost listen on 127.0.0.1 only (always true for "ui")
22842304
** --nojail Drop root privileges but do not enter the chroot jail
22852305
** --notfound URL Redirect
@@ -2305,10 +2325,11 @@
23052325
#endif
23062326
int allowRepoList; /* List repositories on URL "/" */
23072327
const char *zAltBase; /* Argument to the --baseurl option */
23082328
const char *zFileGlob; /* Static content must match this */
23092329
char *zIpAddr = 0; /* Bind to this IP address */
2330
+ int fCreate = 0;
23102331
23112332
#if defined(_WIN32)
23122333
const char *zStopperFile; /* Name of file used to terminate server */
23132334
zStopperFile = find_option("stopper", 0, 1);
23142335
#endif
@@ -2329,10 +2350,11 @@
23292350
Th_InitTraceLog();
23302351
zPort = find_option("port", "P", 1);
23312352
zNotFound = find_option("notfound", 0, 1);
23322353
allowRepoList = find_option("repolist",0,0)!=0;
23332354
zAltBase = find_option("baseurl", 0, 1);
2355
+ fCreate = find_option("create",0,0)!=0;
23342356
if( find_option("scgi", 0, 0)!=0 ) flags |= HTTP_SERVER_SCGI;
23352357
if( zAltBase ){
23362358
set_base_url(zAltBase);
23372359
}
23382360
if( find_option("localhost", 0, 0)!=0 ){
@@ -2347,11 +2369,11 @@
23472369
if( isUiCmd ){
23482370
flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
23492371
g.useLocalauth = 1;
23502372
allowRepoList = 1;
23512373
}
2352
- find_server_repository(2);
2374
+ find_server_repository(2, fCreate);
23532375
if( zPort ){
23542376
int i;
23552377
for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
23562378
if( i>0 ){
23572379
zIpAddr = mprintf("%.*s", i, zPort);
@@ -2387,12 +2409,10 @@
23872409
}else{
23882410
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
23892411
}
23902412
if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
23912413
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2392
- }else{
2393
- db_setup_server_and_project_codes(1);
23942414
}
23952415
db_close(1);
23962416
if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
23972417
fossil_fatal("unable to listen on TCP socket %d", iPort);
23982418
}
@@ -2401,11 +2421,11 @@
24012421
g.httpOut = stdout;
24022422
if( g.fHttpTrace || g.fSqlTrace ){
24032423
fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
24042424
}
24052425
g.cgiOutput = 1;
2406
- find_server_repository(2);
2426
+ find_server_repository(2, 0);
24072427
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
24082428
if( flags & HTTP_SERVER_SCGI ){
24092429
cgi_handle_scgi_request();
24102430
}else{
24112431
cgi_handle_http_request(0);
24122432
--- src/main.c
+++ src/main.c
@@ -2031,19 +2031,38 @@
2031 ** Open the repository to be served if it is known. If g.argv[arg] is
2032 ** a directory full of repositories, then set g.zRepositoryName to
2033 ** the name of that directory and the specific repository will be
2034 ** opened later by process_one_web_page() based on the content of
2035 ** the PATH_INFO variable.
 
 
 
2036 */
2037 static void find_server_repository(int arg){
2038 if( g.argc<=arg ){
2039 db_must_be_within_tree();
2040 }else if( file_isdir(g.argv[arg])==1 ){
2041 g.zRepositoryName = mprintf("%s", g.argv[arg]);
2042 file_simplify_name(g.zRepositoryName, -1, 0);
2043 }else{
2044 db_open_repository(g.argv[arg]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2045 }
2046 }
2047
2048 /*
2049 ** undocumented format:
@@ -2146,15 +2165,15 @@
2146 g.fullHttpReply = 1;
2147 if( g.argc>=5 ){
2148 g.httpIn = fossil_fopen(g.argv[2], "rb");
2149 g.httpOut = fossil_fopen(g.argv[3], "wb");
2150 zIpAddr = g.argv[4];
2151 find_server_repository(5);
2152 }else{
2153 g.httpIn = stdin;
2154 g.httpOut = stdout;
2155 find_server_repository(2);
2156 }
2157 if( zIpAddr==0 ){
2158 zIpAddr = cgi_ssh_remote_addr(0);
2159 if( zIpAddr && zIpAddr[0] ){
2160 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2197,11 +2216,11 @@
2197 Th_InitTraceLog();
2198 login_set_capabilities("sx", 0);
2199 g.useLocalauth = 1;
2200 g.httpIn = stdin;
2201 g.httpOut = stdout;
2202 find_server_repository(2);
2203 g.cgiOutput = 1;
2204 g.fullHttpReply = 1;
2205 zIpAddr = cgi_ssh_remote_addr(0);
2206 if( zIpAddr && zIpAddr[0] ){
2207 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2276,10 +2295,11 @@
2276 ** connection is from localhost. The "ui" command also enables --repolist
2277 ** by default.
2278 **
2279 ** Options:
2280 ** --baseurl URL Use URL as the base (useful for reverse proxies)
 
2281 ** --files GLOBLIST Comma-separated list of glob patterns for static files
2282 ** --localauth enable automatic login for requests from localhost
2283 ** --localhost listen on 127.0.0.1 only (always true for "ui")
2284 ** --nojail Drop root privileges but do not enter the chroot jail
2285 ** --notfound URL Redirect
@@ -2305,10 +2325,11 @@
2305 #endif
2306 int allowRepoList; /* List repositories on URL "/" */
2307 const char *zAltBase; /* Argument to the --baseurl option */
2308 const char *zFileGlob; /* Static content must match this */
2309 char *zIpAddr = 0; /* Bind to this IP address */
 
2310
2311 #if defined(_WIN32)
2312 const char *zStopperFile; /* Name of file used to terminate server */
2313 zStopperFile = find_option("stopper", 0, 1);
2314 #endif
@@ -2329,10 +2350,11 @@
2329 Th_InitTraceLog();
2330 zPort = find_option("port", "P", 1);
2331 zNotFound = find_option("notfound", 0, 1);
2332 allowRepoList = find_option("repolist",0,0)!=0;
2333 zAltBase = find_option("baseurl", 0, 1);
 
2334 if( find_option("scgi", 0, 0)!=0 ) flags |= HTTP_SERVER_SCGI;
2335 if( zAltBase ){
2336 set_base_url(zAltBase);
2337 }
2338 if( find_option("localhost", 0, 0)!=0 ){
@@ -2347,11 +2369,11 @@
2347 if( isUiCmd ){
2348 flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
2349 g.useLocalauth = 1;
2350 allowRepoList = 1;
2351 }
2352 find_server_repository(2);
2353 if( zPort ){
2354 int i;
2355 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2356 if( i>0 ){
2357 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2387,12 +2409,10 @@
2387 }else{
2388 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2389 }
2390 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2391 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2392 }else{
2393 db_setup_server_and_project_codes(1);
2394 }
2395 db_close(1);
2396 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2397 fossil_fatal("unable to listen on TCP socket %d", iPort);
2398 }
@@ -2401,11 +2421,11 @@
2401 g.httpOut = stdout;
2402 if( g.fHttpTrace || g.fSqlTrace ){
2403 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2404 }
2405 g.cgiOutput = 1;
2406 find_server_repository(2);
2407 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
2408 if( flags & HTTP_SERVER_SCGI ){
2409 cgi_handle_scgi_request();
2410 }else{
2411 cgi_handle_http_request(0);
2412
--- src/main.c
+++ src/main.c
@@ -2031,19 +2031,38 @@
2031 ** Open the repository to be served if it is known. If g.argv[arg] is
2032 ** a directory full of repositories, then set g.zRepositoryName to
2033 ** the name of that directory and the specific repository will be
2034 ** opened later by process_one_web_page() based on the content of
2035 ** the PATH_INFO variable.
2036 **
2037 ** If the fCreate flag is set, then create the repository if it
2038 ** does not already exist.
2039 */
2040 static void find_server_repository(int arg, int fCreate){
2041 if( g.argc<=arg ){
2042 db_must_be_within_tree();
 
 
 
2043 }else{
2044 const char *zRepo = g.argv[arg];
2045 int isDir = file_isdir(zRepo);
2046 if( isDir==1 ){
2047 g.zRepositoryName = mprintf("%s", zRepo);
2048 file_simplify_name(g.zRepositoryName, -1, 0);
2049 }else{
2050 if( isDir==0 && fCreate ){
2051 db_create_repository(zRepo);
2052 db_open_repository(zRepo);
2053 db_begin_transaction();
2054 db_initial_setup(0,"now","admin");
2055 db_multi_exec("UPDATE user SET pw='admin' WHERE login='admin'");
2056 db_end_transaction(0);
2057 cache_initialize();
2058 g.zLogin = 0;
2059 g.userUid = 0;
2060 }else{
2061 db_open_repository(zRepo);
2062 }
2063 }
2064 }
2065 }
2066
2067 /*
2068 ** undocumented format:
@@ -2146,15 +2165,15 @@
2165 g.fullHttpReply = 1;
2166 if( g.argc>=5 ){
2167 g.httpIn = fossil_fopen(g.argv[2], "rb");
2168 g.httpOut = fossil_fopen(g.argv[3], "wb");
2169 zIpAddr = g.argv[4];
2170 find_server_repository(5, 0);
2171 }else{
2172 g.httpIn = stdin;
2173 g.httpOut = stdout;
2174 find_server_repository(2, 0);
2175 }
2176 if( zIpAddr==0 ){
2177 zIpAddr = cgi_ssh_remote_addr(0);
2178 if( zIpAddr && zIpAddr[0] ){
2179 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2197,11 +2216,11 @@
2216 Th_InitTraceLog();
2217 login_set_capabilities("sx", 0);
2218 g.useLocalauth = 1;
2219 g.httpIn = stdin;
2220 g.httpOut = stdout;
2221 find_server_repository(2, 0);
2222 g.cgiOutput = 1;
2223 g.fullHttpReply = 1;
2224 zIpAddr = cgi_ssh_remote_addr(0);
2225 if( zIpAddr && zIpAddr[0] ){
2226 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2276,10 +2295,11 @@
2295 ** connection is from localhost. The "ui" command also enables --repolist
2296 ** by default.
2297 **
2298 ** Options:
2299 ** --baseurl URL Use URL as the base (useful for reverse proxies)
2300 ** --create Create a new REPOSITORY if it does not already exist
2301 ** --files GLOBLIST Comma-separated list of glob patterns for static files
2302 ** --localauth enable automatic login for requests from localhost
2303 ** --localhost listen on 127.0.0.1 only (always true for "ui")
2304 ** --nojail Drop root privileges but do not enter the chroot jail
2305 ** --notfound URL Redirect
@@ -2305,10 +2325,11 @@
2325 #endif
2326 int allowRepoList; /* List repositories on URL "/" */
2327 const char *zAltBase; /* Argument to the --baseurl option */
2328 const char *zFileGlob; /* Static content must match this */
2329 char *zIpAddr = 0; /* Bind to this IP address */
2330 int fCreate = 0;
2331
2332 #if defined(_WIN32)
2333 const char *zStopperFile; /* Name of file used to terminate server */
2334 zStopperFile = find_option("stopper", 0, 1);
2335 #endif
@@ -2329,10 +2350,11 @@
2350 Th_InitTraceLog();
2351 zPort = find_option("port", "P", 1);
2352 zNotFound = find_option("notfound", 0, 1);
2353 allowRepoList = find_option("repolist",0,0)!=0;
2354 zAltBase = find_option("baseurl", 0, 1);
2355 fCreate = find_option("create",0,0)!=0;
2356 if( find_option("scgi", 0, 0)!=0 ) flags |= HTTP_SERVER_SCGI;
2357 if( zAltBase ){
2358 set_base_url(zAltBase);
2359 }
2360 if( find_option("localhost", 0, 0)!=0 ){
@@ -2347,11 +2369,11 @@
2369 if( isUiCmd ){
2370 flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
2371 g.useLocalauth = 1;
2372 allowRepoList = 1;
2373 }
2374 find_server_repository(2, fCreate);
2375 if( zPort ){
2376 int i;
2377 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2378 if( i>0 ){
2379 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2387,12 +2409,10 @@
2409 }else{
2410 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2411 }
2412 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2413 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
 
 
2414 }
2415 db_close(1);
2416 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2417 fossil_fatal("unable to listen on TCP socket %d", iPort);
2418 }
@@ -2401,11 +2421,11 @@
2421 g.httpOut = stdout;
2422 if( g.fHttpTrace || g.fSqlTrace ){
2423 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2424 }
2425 g.cgiOutput = 1;
2426 find_server_repository(2, 0);
2427 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
2428 if( flags & HTTP_SERVER_SCGI ){
2429 cgi_handle_scgi_request();
2430 }else{
2431 cgi_handle_http_request(0);
2432
+1 -1
--- src/rebuild.c
+++ src/rebuild.c
@@ -953,11 +953,11 @@
953953
/* We should be done with options.. */
954954
verify_all_options();
955955
956956
db_open_config(0);
957957
db_begin_transaction();
958
- db_initial_setup(0, 0, 0, 1);
958
+ db_initial_setup(0, 0, 0);
959959
960960
fossil_print("Reading files from directory \"%s\"...\n", g.argv[3]);
961961
recon_read_dir(g.argv[3]);
962962
fossil_print("\nBuilding the Fossil repository...\n");
963963
964964
--- src/rebuild.c
+++ src/rebuild.c
@@ -953,11 +953,11 @@
953 /* We should be done with options.. */
954 verify_all_options();
955
956 db_open_config(0);
957 db_begin_transaction();
958 db_initial_setup(0, 0, 0, 1);
959
960 fossil_print("Reading files from directory \"%s\"...\n", g.argv[3]);
961 recon_read_dir(g.argv[3]);
962 fossil_print("\nBuilding the Fossil repository...\n");
963
964
--- src/rebuild.c
+++ src/rebuild.c
@@ -953,11 +953,11 @@
953 /* We should be done with options.. */
954 verify_all_options();
955
956 db_open_config(0);
957 db_begin_transaction();
958 db_initial_setup(0, 0, 0);
959
960 fossil_print("Reading files from directory \"%s\"...\n", g.argv[3]);
961 recon_read_dir(g.argv[3]);
962 fossil_print("\nBuilding the Fossil repository...\n");
963
964

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button