diff --git a/CMakeLists.txt b/CMakeLists.txt index d2937a9..71dcb77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 2.8) include(GNUInstallDirs) # Grive version. remember to update it for every new release! -set( GRIVE_VERSION "0.5.2-dev" ) +set( GRIVE_VERSION "0.5.2-dev" CACHE STRING "Grive version" ) +message(WARNING "Version to build: ${GRIVE_VERSION}") # common compile options add_definitions( -DVERSION="${GRIVE_VERSION}" ) @@ -12,4 +13,3 @@ add_definitions( -D_FILE_OFFSET_BITS=64 -std=c++0x ) add_subdirectory( systemd ) add_subdirectory( libgrive ) add_subdirectory( grive ) - \ No newline at end of file diff --git a/README.md b/README.md index ff3cb4f..d9a0da2 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,14 @@ Grive uses cmake to build. Basic install sequence is make -j4 sudo make install +Alternativly you can define your own client_id and client_secret during build + + mkdir build + cd build + cmake .. "-DAPP_ID:STRING=" "-DAPP_SECRET:STRING=" + make -j4 + sudo make install + ## Version History ### Grive2 v0.5.2-dev diff --git a/grive/CMakeLists.txt b/grive/CMakeLists.txt index 0908380..ac5b781 100644 --- a/grive/CMakeLists.txt +++ b/grive/CMakeLists.txt @@ -20,6 +20,17 @@ target_link_libraries( grive_executable grive ) +set(DEFAULT_APP_ID "615557989097-i93d4d1ojpen0m0dso18ldr6orjkidgf.apps.googleusercontent.com") +set(DEFAULT_APP_SECRET "xiM8Apu_WuRRdheNelJcNtOD") +set(APP_ID ${DEFAULT_APP_ID} CACHE STRING "Application Id") +set(APP_SECRET ${DEFAULT_APP_SECRET} CACHE STRING "Application Secret") + +target_compile_definitions ( grive_executable + PRIVATE + -DAPP_ID="${APP_ID}" + -DAPP_SECRET="${APP_SECRET}" +) + set_target_properties( grive_executable PROPERTIES OUTPUT_NAME grive ) diff --git a/grive/src/main.cc b/grive/src/main.cc index 31a2b07..54d5560 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -46,8 +46,8 @@ #include #include -const std::string default_id = "615557989097-i93d4d1ojpen0m0dso18ldr6orjkidgf.apps.googleusercontent.com" ; -const std::string default_secret = "xiM8Apu_WuRRdheNelJcNtOD" ; +const std::string default_id = APP_ID ; +const std::string default_secret = APP_SECRET ; using namespace gr ; namespace po = boost::program_options; @@ -113,6 +113,7 @@ int Main( int argc, char **argv ) ( "auth,a", "Request authorization token" ) ( "id,i", po::value(), "Authentication ID") ( "secret,e", po::value(), "Authentication secret") + ( "print-url", "Only print url for request") ( "path,p", po::value(), "Path to working copy root") ( "dir,s", po::value(), "Single subdirectory to sync") ( "verbose,V", "Verbose mode. Enable more messages than normal.") @@ -174,23 +175,23 @@ int Main( int argc, char **argv ) http->SetProgressReporter( pb.get() ); } - std::string id = default_id; - std::string secret = default_secret; - - if( vm.count( "id" ) ) - { - id = vm["id"].as(); - } - - if( vm.count( "secret" ) ) - { - secret = vm["secret"].as(); - } - if ( vm.count( "auth" ) ) { + std::string id = vm.count( "id" ) > 0 + ? vm["id"].as() + : default_id ; + std::string secret = vm.count( "secret" ) > 0 + ? vm["secret"].as() + : default_secret ; + OAuth2 token( http.get(), id, secret ) ; + if ( vm.count("print-url") ) + { + std::cout << token.MakeAuthURL() << std::endl ; + return 0 ; + } + std::cout << "-----------------------\n" << "Please go to this URL and get an authentication code:\n\n" @@ -206,14 +207,20 @@ int Main( int argc, char **argv ) token.Auth( code ) ; // save to config + config.Set( "id", Val( id ) ) ; + config.Set( "secret", Val( secret ) ) ; config.Set( "refresh_token", Val( token.RefreshToken() ) ) ; config.Save() ; } std::string refresh_token ; + std::string id ; + std::string secret ; try { refresh_token = config.Get("refresh_token").Str() ; + id = config.Get("id").Str() ; + secret = config.Get("secret").Str() ; } catch ( Exception& e ) { diff --git a/libgrive/src/util/Config.cc b/libgrive/src/util/Config.cc index ba0c91e..c08972f 100644 --- a/libgrive/src/util/Config.cc +++ b/libgrive/src/util/Config.cc @@ -38,6 +38,10 @@ const std::string default_root_folder = "."; Config::Config( const po::variables_map& vm ) { + if ( vm.count( "id" ) > 0 ) + m_cmd.Add( "id", Val( vm["id"].as() ) ) ; + if ( vm.count( "secret" ) > 0 ) + m_cmd.Add( "secret", Val( vm["secret"].as() ) ) ; m_cmd.Add( "new-rev", Val(vm.count("new-rev") > 0) ) ; m_cmd.Add( "force", Val(vm.count("force") > 0 ) ) ; m_cmd.Add( "path", Val(vm.count("path") > 0