File Annotation
Not logged in
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** Copyright (c) 2007 D. Richard Hipp
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This program is free software; you can redistribute it and/or
dbda8d6ce9 2007-07-21       drh: ** modify it under the terms of the GNU General Public
dbda8d6ce9 2007-07-21       drh: ** License version 2 as published by the Free Software Foundation.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This program is distributed in the hope that it will be useful,
dbda8d6ce9 2007-07-21       drh: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
dbda8d6ce9 2007-07-21       drh: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dbda8d6ce9 2007-07-21       drh: ** General Public License for more details.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** You should have received a copy of the GNU General Public
dbda8d6ce9 2007-07-21       drh: ** License along with this library; if not, write to the
dbda8d6ce9 2007-07-21       drh: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
dbda8d6ce9 2007-07-21       drh: ** Boston, MA  02111-1307, USA.
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** Author contact information:
dbda8d6ce9 2007-07-21       drh: **   drh@hwaci.com
dbda8d6ce9 2007-07-21       drh: **   http://www.hwaci.com/drh/
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: *******************************************************************************
dbda8d6ce9 2007-07-21       drh: **
dbda8d6ce9 2007-07-21       drh: ** This file contains code used to clone a repository
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: #include "config.h"
dbda8d6ce9 2007-07-21       drh: #include "clone.h"
dbda8d6ce9 2007-07-21       drh: #include <assert.h>
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: 
dbda8d6ce9 2007-07-21       drh: /*
dbda8d6ce9 2007-07-21       drh: ** COMMAND: clone
dbda8d6ce9 2007-07-21       drh: **
c9fdb846fb 2007-08-18       drh: ** Usage: %fossil clone URL FILENAME
dbda8d6ce9 2007-07-21       drh: **
c9fdb846fb 2007-08-18       drh: ** Make a clone of a repository specified by URL in the local
c9fdb846fb 2007-08-18       drh: ** file named FILENAME.
dbda8d6ce9 2007-07-21       drh: */
dbda8d6ce9 2007-07-21       drh: void clone_cmd(void){
0c6ea0d93f 2008-11-20       drh:   char *zPassword;
f652599003 2008-05-06       drh:   url_proxy_options();
dbda8d6ce9 2007-07-21       drh:   if( g.argc!=4 ){
dbda8d6ce9 2007-07-21       drh:     usage("FILE-OR-URL NEW-REPOSITORY");
dbda8d6ce9 2007-07-21       drh:   }
00ac7945a9 2009-08-13       drh:   db_open_config(0);
dbda8d6ce9 2007-07-21       drh:   if( file_size(g.argv[3])>0 ){
dbda8d6ce9 2007-07-21       drh:     fossil_panic("file already exists: %s", g.argv[3]);
dbda8d6ce9 2007-07-21       drh:   }
dbda8d6ce9 2007-07-21       drh:   url_parse(g.argv[2]);
13b7ac16e4 2007-08-09       drh:   if( g.urlIsFile ){
9236f0c086 2008-10-05       drh:     file_copy(g.urlName, g.argv[3]);
9236f0c086 2008-10-05       drh:     db_close();
9236f0c086 2008-10-05       drh:     db_open_repository(g.argv[3]);
2bd0690fe8 2008-10-17       drh:     db_record_repository_filename(g.argv[3]);
9236f0c086 2008-10-05       drh:     db_multi_exec(
9236f0c086 2008-10-05       drh:       "REPLACE INTO config(name,value)"
9236f0c086 2008-10-05       drh:       " VALUES('server-code', lower(hex(randomblob(20))));"
945ecd1a8b 2009-04-11       drh:       "REPLACE INTO config(name,value)"
47d8fc4944 2009-08-01       drh:       " VALUES('last-sync-url', '%q');",
47d8fc4944 2009-08-01       drh:       g.urlCanonical
47d8fc4944 2009-08-01       drh:     );
02a584f7f5 2009-08-26       drh:     db_multi_exec(
02a584f7f5 2009-08-26       drh:        "DELETE FROM blob WHERE rid IN private;"
02a584f7f5 2009-08-26       drh:        "DELETE FROM delta wHERE rid IN private;"
02a584f7f5 2009-08-26       drh:        "DELETE FROM private;"
dbda8d6ce9 2007-07-21       drh:     );
02a584f7f5 2009-08-26       drh:     shun_artifacts();
0c6ea0d93f 2008-11-20       drh:     g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
0c6ea0d93f 2008-11-20       drh:     if( g.zLogin==0 ){
0c6ea0d93f 2008-11-20       drh:       db_create_default_users(1);
dbda8d6ce9 2007-07-21       drh:     }
9236f0c086 2008-10-05       drh:     printf("Repository cloned into %s\n", g.argv[3]);
dbda8d6ce9 2007-07-21       drh:   }else{
9236f0c086 2008-10-05       drh:     db_create_repository(g.argv[3]);
9236f0c086 2008-10-05       drh:     db_open_repository(g.argv[3]);
9236f0c086 2008-10-05       drh:     db_begin_transaction();
2bd0690fe8 2008-10-17       drh:     db_record_repository_filename(g.argv[3]);
9236f0c086 2008-10-05       drh:     db_initial_setup(0, 0);
9236f0c086 2008-10-05       drh:     user_select();
9236f0c086 2008-10-05       drh:     db_set("content-schema", CONTENT_SCHEMA, 0);
9236f0c086 2008-10-05       drh:     db_set("aux-schema", AUX_SCHEMA, 0);
9236f0c086 2008-10-05       drh:     db_set("last-sync-url", g.argv[2], 0);
9236f0c086 2008-10-05       drh:     db_multi_exec(
9236f0c086 2008-10-05       drh:       "REPLACE INTO config(name,value)"
9236f0c086 2008-10-05       drh:       " VALUES('server-code', lower(hex(randomblob(20))));"
9236f0c086 2008-10-05       drh:     );
676fdd088a 2008-05-01       drh:     url_enable_proxy(0);
243e02bfbd 2008-05-18       drh:     g.xlinkClusterOnly = 1;
6b0b57a924 2008-10-25       drh:     client_sync(0,0,1,CONFIGSET_ALL,0);
243e02bfbd 2008-05-18       drh:     g.xlinkClusterOnly = 0;
9236f0c086 2008-10-05       drh:     verify_cancel();
9236f0c086 2008-10-05       drh:     db_end_transaction(0);
9236f0c086 2008-10-05       drh:     db_close();
9236f0c086 2008-10-05       drh:     db_open_repository(g.argv[3]);
dbda8d6ce9 2007-07-21       drh:   }
243e02bfbd 2008-05-18       drh:   db_begin_transaction();
243e02bfbd 2008-05-18       drh:   printf("Rebuilding repository meta-data...\n");
243e02bfbd 2008-05-18       drh:   rebuild_db(0, 1);
0c6ea0d93f 2008-11-20       drh:   printf("project-id: %s\n", db_get("project-code", 0));
0c6ea0d93f 2008-11-20       drh:   printf("server-id:  %s\n", db_get("server-code", 0));
0c6ea0d93f 2008-11-20       drh:   zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
0c6ea0d93f 2008-11-20       drh:   printf("admin-user: %s (password is \"%s\")\n", g.zLogin, zPassword);
097479f99a 2007-09-26       drh:   db_end_transaction(0);
dbda8d6ce9 2007-07-21       drh: }