Compare commits

...

54 Commits

Author SHA1 Message Date
Vitaliy Filippov d03c4a24ce Bump version to 0.5.3 2022-11-09 12:45:14 +03:00
Vitaliy Filippov 328987ec34 Fix readme 2022-11-09 12:41:47 +03:00
Vitaliy Filippov 6645206d27 Implement Google OAuth loopback IP address flow (fixes #362 #372 #365) 2022-11-09 12:37:18 +03:00
Vitaliy Filippov 6901fbb169
Merge pull request #345 from ncaq/fix-shell-script-path
fixed: CMAKE_INSTALL_FULL_LIBDIR -> CMAKE_INSTALL_FULL_LIBEXECDIR
2021-11-29 00:13:19 +03:00
ncaq 48f5f0e52f fixed: CMAKE_INSTALL_FULL_LIBDIR -> CMAKE_INSTALL_FULL_LIBEXECDIR
Because, It must equal GRIVE_SYNC_SH_BINARY and actual grive-sync.sh path.
I patched my gentoo overlay ebuild.
[added: grive: libexec patch · ncaq/ncaq-overlay@ed3354f](ed3354fbb7)
2021-07-08 14:41:19 +09:00
Vitaliy Filippov e6fcc637f8
Merge pull request #245 from jankatins/revert_symlink_handling_in_sync
Revert "Exclude symlinks from sync"
2021-05-27 23:44:58 +03:00
Vitaliy Filippov dedb762b74
Merge pull request #246 from jankatins/add-main-systemd-unit
Add systemd unit to enable both timer and changes based syncs
2021-05-27 22:50:41 +03:00
Vitaliy Filippov d55fe7f5eb
Merge pull request #344 from agusalex/patch-1
Fix Dockerfile
2021-05-14 22:41:38 +03:00
Agustin Alexander 03a2c58403
Fix Dockerfile 2021-05-14 13:47:14 -03:00
Vitaliy Filippov b112fccd37
Merge pull request #325 from agusalex/master
Optimized (using Alpine) Docker image size (compressed) 214MB -> 62MB
2021-05-14 18:57:10 +03:00
Vitaliy Filippov cb3c586862
Merge pull request #310 from mbartlet/systemd-escape
fix systemd-escape hyphen usage
2021-05-14 18:55:21 +03:00
Vitaliy Filippov 3a28149bad
Merge pull request #340 from jankatins/update_debian_version
Update debian packaging
2021-05-14 18:48:42 +03:00
Vitaliy Filippov e36f362abb
Merge pull request #342 from 0-wiz-0/master
Fix build on NetBSD
2021-05-14 18:46:36 +03:00
Thomas Klausner 30763e2f9d Add compatibility define for off64_t.
Not all systems define off64_t.
2021-04-15 12:41:40 +02:00
Thomas Klausner 814b724cc4 Handle NetBSD like macOS for timestamp precision. 2021-04-15 12:41:10 +02:00
Jan Katins 050fcf53a0 Move helper script into libexec dir
This seems to be a proper dir for such "not-for-normal-user" things...
2021-03-30 15:19:53 +02:00
Jan Katins 9076e3aed2 Ensure that the systemd files get installed in debian
If you build in pbuilder, no systemd is installed and so the flag is set to false which means the files will not get installed. Adding the explicit flag will make sure they are included in the package.
2021-03-23 18:10:10 +01:00
Jan Katins 27ca714e56 Add .idea folder to .gitignore 2021-03-18 10:34:15 +01:00
Jan Katins e0965f7fb8 Remove the libstdc++ dependency
These are included in the right version via the suggested installation of build-essential, which which installs the right lib via dependencies: g++ -> g++-<version> ->  libstdc++-<version>

Adding it explicitly meant always adding new versions  :-(
2021-03-18 10:33:44 +01:00
Jan Katins 5510ca1b06 More consistent directory name output in logs 2021-03-15 14:24:36 +01:00
Jan Katins 4dfc9a5461 Install grive-sync.sh into the right libdir 2021-03-15 14:12:31 +01:00
Jan Katins 378df2867b Do explicit unlocks in grive-sync.sh script 2021-03-15 13:30:46 +01:00
Jan Schulz 0b53b08f57 Increment version for debian package and add some changes there
* Updated debhelper compat level to latest stable one
2021-03-15 13:11:32 +01:00
Jan Katins d7008b81c1 Remove uneeded binutils-dev depency 2021-03-15 13:11:32 +01:00
Jan Schulz 1bab757298 Add systemd unit to enable both timer and changes based syncs
Now it's enough to enable and start `grive@<folder>.service`.
2021-03-14 22:49:59 +01:00
Jan Schulz c7a949dedd Revert "Exclude symlinks from sync"
This reverts commit b47dd70f35.

This could trigger a infinite loop between the timer unit (running a sync and changing the griveignore file at the start) and the changes unit (reacting to the griveignore change and retriggering the sync).
2021-03-14 22:46:43 +01:00
Agustin Alexander a8b84930f9
Optimized image size (compressed) 214MB -> 62MB 2020-09-23 19:32:04 -03:00
crborga 97a97265fd
Support Debian 10
Added support for building on Debian 10 without installing gcc7.
2020-04-07 21:35:28 -04:00
Michael Bartlett 7b42e2da5b fix systemd-escape hyphen usage 2020-03-03 13:34:27 -07:00
Vitaliy Filippov ffb744a59b
Merge pull request #285 from brainplot/cmake-fix
Add 'project' directive to the build script
2020-02-06 01:25:03 +03:00
Vitaliy Filippov 03bbc20892
Merge pull request #300 from redmercury/master
This change fixed a BSD compile issue.
2020-02-06 01:23:43 +03:00
Vitaliy Filippov 1456e6e0ba
Merge pull request #289 from danielsouzat/master
+clean debian packaging
2020-02-06 01:19:08 +03:00
Vitaliy Filippov 2ae61ab1e6
Merge branch 'master' into master 2020-02-06 01:18:57 +03:00
Vitaliy Filippov a295641cb0
Merge pull request #259 from Tatsh/mac
macOS fixes
2020-02-06 01:16:58 +03:00
Vitaliy Filippov 2ddc0230da
Merge branch 'master' into mac 2020-02-06 01:16:46 +03:00
Vitaliy Filippov 58a689a3db
Merge pull request #295 from fbicknel/patch-1
Fix Fedora (and RHEL) suggested dependencies
2020-02-06 01:14:05 +03:00
Vitaliy Filippov af2a6de268
Merge pull request #299 from cowo78/master
Support compilation with binutils >= 2.33.1 on Debian.
2020-02-06 01:12:17 +03:00
Vitaliy Filippov fa3c39480a
Merge pull request #303 from lmmamercy/master
fix ubuntu/debian suggested dependencies
2020-02-06 01:07:59 +03:00
lmmamercy dc1946498d
fix ubuntu/debian suggested dependencies 2020-02-05 14:30:34 +00:00
Daniel Deptford 6aeec25778 Adding CMake's Backtrace package to resolve issue where the project fails to compile under BSD. 2020-01-19 20:41:02 -08:00
Giuseppe Corbelli b4d6ac055f [SymbolInfo.cc] Support compilation with binutils >= 2.33.1 on Debian.
bfd_get_section_vma macro was removed.
bfd_section_size changed signature.

See inline comment for details.
2020-01-14 11:50:20 +01:00
Vitaliy Filippov a3cce71643 Small corrections 2020-01-06 20:37:32 +03:00
Vitaliy Filippov 37df02adff
Merge pull request #297 from AmonRaNet/update-readme
Add instruction for replacing the OAuth2 client
2020-01-06 20:22:37 +03:00
AmonRaNet 94182975db Add instruction for replacing the OAuth2 client 2019-12-31 20:13:26 +01:00
Frank Bicknell de6404b246
Fix Fedora (and RHEL) suggested dependencies
We need boost-devel to compile.
2019-12-16 13:27:43 -05:00
Vitaliy Filippov bdcb76efc0
Merge pull request #294 from AmonRaNet/extend-custom-app-id-secret
Extends support application id and secret support
2019-12-15 23:58:57 +03:00
AmonRaNet 79312b9c53 Extends support application id and secret support
- persistent id's in config
- cmake supports id's during config
- priority: default(cmake), config, cli
2019-12-13 11:16:32 +01:00
daniel ad7844ba29 modified: README.md
modified:   debian/rules
2019-11-22 09:35:43 -03:00
Vitaliy Filippov 39299096cf Move to 0.5.2-dev 2019-11-13 01:06:03 +03:00
Gianluca Recchia fe17d715fc
Add 'project' directive to the build script 2019-10-30 17:37:11 +01:00
Andrew Udvare 6354689a93 libgrive: fix formatting 2019-02-09 17:06:23 -05:00
Andrew Udvare 7ef50e9523 libgrive: Fix destructors of Feed and Feed2 2019-02-09 17:01:00 -05:00
Tatsh e972a77790
Fix line 2019-02-09 10:56:23 -05:00
Andrew Udvare 8e3c3d25cb Define off64_t=off_t for macOS
Detect the systemd binary and install the systemd units conditionally.
2019-02-09 01:33:39 -05:00
25 changed files with 366 additions and 124 deletions

2
.gitignore vendored
View File

@ -23,3 +23,5 @@ debian/grive/
debian/.debhelper
obj-x86_64-linux-gnu/
.idea

View File

@ -1,15 +1,27 @@
cmake_minimum_required(VERSION 2.8)
project(grive2)
include(GNUInstallDirs)
# Grive version. remember to update it for every new release!
set( GRIVE_VERSION "0.5.1" )
set( GRIVE_VERSION "0.5.3" CACHE STRING "Grive version" )
message(WARNING "Version to build: ${GRIVE_VERSION}")
# common compile options
add_definitions( -DVERSION="${GRIVE_VERSION}" )
add_definitions( -D_FILE_OFFSET_BITS=64 -std=c++0x )
if ( APPLE )
add_definitions( -Doff64_t=off_t )
endif ( APPLE )
find_program(
HAVE_SYSTEMD systemd
PATHS /lib/systemd /usr/lib/systemd
NO_DEFAULT_PATH
)
if ( HAVE_SYSTEMD )
add_subdirectory( systemd )
endif( HAVE_SYSTEMD )
add_subdirectory( systemd )
add_subdirectory( libgrive )
add_subdirectory( grive )

View File

@ -1,32 +1,27 @@
FROM ubuntu:16.04
FROM alpine:3.7 as build
RUN apt-get update && \
apt-get install --yes --no-install-recommends g++ cmake build-essential \
libgcrypt11-dev libyajl-dev libboost-all-dev \
libcurl4-openssl-dev libexpat1-dev libcppunit-dev \
binutils-dev pkg-config zlib1g-dev && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*
RUN apk add git make cmake g++ libgcrypt-dev yajl-dev yajl \
boost-dev curl-dev expat-dev cppunit-dev binutils-dev \
pkgconfig \
&& git clone https://github.com/vitalif/grive2.git \
&& mkdir grive2/build \
&& cd grive2/build \
&& cmake .. \
&& make -j4 \
&& make install \
&& cd ../.. \
&& rm -rf grive2 \
&& mkdir /drive
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
ADD . /grive2
RUN cd /grive2 && \
mkdir build && \
cd build && \
cmake .. && \
make -j4 && \
mv /grive2/build/grive/grive /usr/local/bin/grive && \
rm -rf /grive2
FROM alpine:3.7
COPY --from=build /usr/local/bin/grive /bin/grive
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init
RUN chmod 777 /bin/dumb-init /bin/grive \
&& mkdir /data \
&& apk add yajl-dev curl-dev libgcrypt \
boost-program_options boost-regex libstdc++ boost-system boost-dev binutils-dev \
&& apk add boost-filesystem --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
VOLUME /data
WORKDIR /data
ENTRYPOINT ["dumb-init", "/usr/local/bin/grive"]
# docker build -t grive2 .
# docker run --name grive2 --rm -it -v $PWD:/data grive2:latest
ENTRYPOINT ["dumb-init", "grive"]

View File

@ -1,6 +1,6 @@
# Grive2 0.5.2-dev
# Grive2 0.5.3
13 Nov 2019, Vitaliy Filippov
09 Nov 2022, Vitaliy Filippov
http://yourcmc.ru/wiki/Grive2
@ -39,10 +39,10 @@ grive -a
A URL should be printed. Go to the link. You will need to login to your Google
account if you haven't done so. After granting the permission to Grive, the
browser will show you an authenication code. Copy-and-paste that to the
standard input of Grive.
authorization code will be forwarded to the Grive application and you will be
redirected to a localhost web page confirming the authorization.
If everything works fine, Grive will create .grive and .grive_state files in your
If everything works fine, Grive will create .grive and .grive\_state files in your
current directory. It will also start downloading files from your Google Drive to
your current directory.
@ -90,15 +90,18 @@ Prepare a Google Drive folder in your $HOME directory with `grive -a`.
```bash
# 'google-drive' is the name of your Google Drive folder in your $HOME directory
systemctl --user enable grive-timer@$(systemd-escape google-drive).timer
systemctl --user start grive-timer@$(systemd-escape google-drive).timer
systemctl --user enable grive-changes@$(systemd-escape google-drive).service
systemctl --user start grive-changes@$(systemd-escape google-drive).service
systemctl --user enable grive@$(systemd-escape google-drive).service
systemctl --user start grive@$(systemd-escape google-drive).service
```
You can enable and start these two units for multiple folders in your `$HOME`
You can enable and start this unit for multiple folders in your `$HOME`
directory if you need to sync with multiple google accounts.
You can also only enable the time based syncing or the changes based syncing
by only directly enabling and starting the corresponding unit:
`grive-changes@$(systemd-escape google-drive).service` or
`grive-timer@$(systemd-escape google-drive).timer`.
### Shared files
Files and folders which are shared with you don't automatically show up in
@ -106,6 +109,37 @@ your folder. They need to be added explicitly to your Google Drive: go to the
Google Drive website, right click on the file or folder and chose 'Add to My
Drive'.
### Different OAuth2 client to workaround over quota and google approval issues
Google recently started to restrict access for unapproved applications:
https://developers.google.com/drive/api/v3/about-auth?hl=ru
Grive2 is currently awaiting approval but it seems it will take forever.
Also even if they approve it the default Client ID supplied with grive may
exceed quota and grive will then fail to sync.
You can supply your own OAuth2 client credentials to work around these problems
by following these steps:
1. Go to https://console.developers.google.com/apis/api/drive.googleapis.com
2. Choose a project (you might need to create one first)
3. Go to https://console.developers.google.com/apis/library/drive.googleapis.com and
"Enable" the Google Drive APIs
4. Go to https://console.cloud.google.com/apis/credentials and click "Create credentials > Help me choose"
5. In the "Find out what credentials you need" dialog, choose:
- Which API are you using: "Google Drive API"
- Where will you be calling the API from: "Other UI (...CLI...)"
- What data will you be accessing: "User Data"
6. In the next steps create a client id (name doesn't matter) and
setup the consent screen (defaults are ok, no need for any URLs)
7. The needed "Client ID" and "Client Secret" are either in the shown download
or can later found by clicking on the created credential on
https://console.developers.google.com/apis/credentials/
8. When you change client ID/secret in an existing Grive folder you must first delete
the old `.grive` configuration file.
9. Call `grive -a --id <client_id> --secret <client_secret>` and follow the steps
to authenticate the OAuth2 client to allow it to access your drive folder.
## Installation
For the detailed instructions, see http://yourcmc.ru/wiki/Grive2#Installation
@ -129,13 +163,13 @@ There are also some optional dependencies:
On a Debian/Ubuntu/Linux Mint machine just run the following command to install all
these packages:
sudo apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev \
sudo apt-get install git cmake build-essential libgcrypt20-dev libyajl-dev \
libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev \
debhelper zlib1g-dev dpkg-dev pkg-config
Fedora:
sudo dnf install git cmake libgcrypt-devel gcc-c++ libstdc++ yajl-devel boost libcurl-devel expat-devel binutils zlib
sudo dnf install git cmake libgcrypt-devel gcc-c++ libstdc++ yajl-devel boost-devel libcurl-devel expat-devel binutils zlib
FreeBSD:
@ -147,7 +181,7 @@ FreeBSD:
On a Debian/Ubuntu/Linux Mint you can use `dpkg-buildpackage` utility from `dpkg-dev` package
to build grive. Just clone the repository, `cd` into it and run
dpkg-buildpackage -j4
dpkg-buildpackage -j4 --no-sign
### Manual build
@ -159,9 +193,20 @@ 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=<client_id>" "-DAPP_SECRET:STRING=<client_secret>"
make -j4
sudo make install
## Version History
### Grive2 v0.5.2-dev
### Grive2 v0.5.3
- Implement Google OAuth loopback IP redirect flow
- Various small fixes
### Grive2 v0.5.1

11
debian/changelog vendored
View File

@ -1,6 +1,15 @@
grive2 (0.5.1+git20160731) unstable; urgency=medium
grive2 (0.5.3) unstable; urgency=medium
* Implement Google OAuth loopback IP redirect flow
* Various small fixes
-- Vitaliy Filippov <vitalif@yourcmc.ru> Wed, 09 Nov 2022 12:42:28 +0300
grive2 (0.5.2+git20210315) unstable; urgency=medium
* Newer dev version
* Add systemd unit files and helper script for automatic syncs
* Add possibility to change client id and secret and save it between runs
-- Vitaliy Filippov <vitalif@yourcmc.ru> Wed, 31 Jul 2016 22:04:53 +0300

2
debian/compat vendored
View File

@ -1 +1 @@
7
11

2
debian/control vendored
View File

@ -2,7 +2,7 @@ Source: grive2
Section: net
Priority: optional
Maintainer: Vitaliy Filippov <vitalif@mail.ru>
Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-7-dev |libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, binutils-dev, libgcrypt-dev, libyajl-dev
Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, libgcrypt-dev, libyajl-dev
Standards-Version: 3.9.6
Homepage: https://yourcmc.ru/wiki/Grive2

5
debian/rules vendored
View File

@ -1,4 +1,7 @@
#!/usr/bin/make -f
override_dh_auto_configure:
dh_auto_configure -- -DHAVE_SYSTEMD=1
%:
dh $@ --buildsystem=cmake --parallel
dh $@ --buildsystem=cmake --parallel --builddirectory=build

View File

@ -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
)

View File

@ -46,8 +46,8 @@
#include <iostream>
#include <unistd.h>
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;
@ -111,8 +111,9 @@ int Main( int argc, char **argv )
( "help,h", "Produce help message" )
( "version,v", "Display Grive version" )
( "auth,a", "Request authorization token" )
( "id,i", po::value<std::string>(), "Authentication ID")
( "secret,e", po::value<std::string>(), "Authentication secret")
( "id,i", po::value<std::string>(), "Authentication ID")
( "secret,e", po::value<std::string>(), "Authentication secret")
( "print-url", "Only print url for request")
( "path,p", po::value<std::string>(), "Path to working copy root")
( "dir,s", po::value<std::string>(), "Single subdirectory to sync")
( "verbose,V", "Verbose mode. Enable more messages than normal.")
@ -174,46 +175,50 @@ 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<std::string>();
}
if( vm.count( "secret" ) )
{
secret = vm["secret"].as<std::string>();
}
if ( vm.count( "auth" ) )
{
std::string id = vm.count( "id" ) > 0
? vm["id"].as<std::string>()
: default_id ;
std::string secret = vm.count( "secret" ) > 0
? vm["secret"].as<std::string>()
: 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"
<< "Please open this URL in your browser to authenticate Grive2:\n\n"
<< token.MakeAuthURL()
<< std::endl ;
std::cout
<< "\n-----------------------\n"
<< "Please input the authentication code here: " << std::endl ;
std::string code ;
std::cin >> code ;
token.Auth( code ) ;
if ( !token.GetCode() )
{
std::cout << "Authentication failed\n";
return -1;
}
// 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 )
{
@ -224,7 +229,7 @@ int Main( int argc, char **argv )
return -1;
}
OAuth2 token( http.get(), refresh_token, id, secret ) ;
AuthAgent agent( token, http.get() ) ;
v2::Syncer2 syncer( &agent );

View File

@ -4,6 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(LibGcrypt REQUIRED)
find_package(CURL REQUIRED)
find_package(Backtrace)
find_package(Boost 1.40.0 COMPONENTS program_options filesystem unit_test_framework regex system REQUIRED)
find_package(BFD)
find_package(CppUnit)
@ -19,15 +20,15 @@ IF ( CPPUNIT_FOUND )
set( OPT_INCS ${CPPUNIT_INCLUDE_DIR} )
ENDIF ( CPPUNIT_FOUND )
# build bfd classes if libbfd is found
if ( BFD_FOUND )
set( OPT_LIBS ${DL_LIBRARY} ${BFD_LIBRARY} )
# build bfd classes if libbfd and the backtrace library is found
if ( BFD_FOUND AND Backtrace_FOUND )
set( OPT_LIBS ${DL_LIBRARY} ${BFD_LIBRARY} ${Backtrace_LIBRARY} )
file( GLOB OPT_SRC
src/bfd/*.cc
)
add_definitions( -DHAVE_BFD )
endif ( BFD_FOUND )
endif ( BFD_FOUND AND Backtrace_FOUND )
if ( IBERTY_FOUND )
set( OPT_LIBS ${OPT_LIBS} ${IBERTY_LIBRARY} )

View File

@ -30,6 +30,10 @@ Feed::Feed( const std::string &url ):
{
}
Feed::~Feed()
{
}
Feed::iterator Feed::begin() const
{
return m_entries.begin() ;

View File

@ -41,6 +41,7 @@ public :
public :
Feed( const std::string& url );
virtual bool GetNext( http::Agent *http ) = 0 ;
virtual ~Feed() = 0 ;
iterator begin() const ;
iterator end() const ;

View File

@ -49,9 +49,9 @@ SymbolInfo::SymbolInfo( )
m_impl->m_bfd = 0 ;
m_impl->m_symbols = 0 ;
m_impl->m_symbol_count = 0 ;
bfd_init( ) ;
// opening itself
bfd *b = bfd_openr( "/proc/self/exe", 0 ) ;
if ( b == NULL )
@ -60,13 +60,13 @@ SymbolInfo::SymbolInfo( )
<< bfd_errmsg( bfd_get_error() ) << std::endl ;
return ;
}
if ( bfd_check_format( b, bfd_archive ) )
{
bfd_close( b ) ;
return ;
}
char **matching ;
if ( !bfd_check_format_matches( b, bfd_object, &matching ) )
{
@ -78,7 +78,7 @@ SymbolInfo::SymbolInfo( )
std::cerr << bfd_get_filename( b ) << ": Matching formats: " ;
for ( char **p = matching ; *p != 0 ; p++ )
std::cerr << " " << *p ;
std::cerr << std::endl ;
std::free( matching ) ;
}
@ -107,7 +107,7 @@ struct SymbolInfo::BacktraceInfo
const char *m_func_name ;
unsigned int m_lineno ;
unsigned int m_is_found ;
static void Callback( bfd *abfd, asection *section, void* addr ) ;
} ;
@ -117,17 +117,24 @@ void SymbolInfo::BacktraceInfo::Callback( bfd *abfd, asection *section,
BacktraceInfo *info = (BacktraceInfo *)data ;
if ((section->flags & SEC_ALLOC) == 0)
return ;
bfd_vma vma = bfd_get_section_vma(abfd, section);
// bfd_get_section_vma works up to 7b1cfbcf1a27951fb1b3a212995075dd6fdf985b,
// removed in 7c13bc8c91abf291f0206b6608b31955c5ea70d8 (binutils 2.33.1 or so)
// so it's substituted by its implementation to avoid checking for binutils
// version (which at least on Debian SID it's not that easy because the
// version.h is not included with the official package)
bfd_vma vma = section->vma;
unsigned long address = (unsigned long)(info->m_addr);
if ( address < vma )
return;
bfd_size_type size = bfd_section_size(abfd, section);
// bfd_section_size changed between the two objects described above,
// same rationale applies
bfd_size_type size = section->size;
if ( address > (vma + size))
return ;
const SymbolInfo *pthis = info->m_pthis ;
info->m_is_found = bfd_find_nearest_line( abfd, section,
pthis->m_impl->m_symbols,
@ -149,7 +156,7 @@ void SymbolInfo::PrintTrace( void *addr, std::ostream& os, std::size_t idx )
{
this, addr, 0, 0, 0, false
} ;
Dl_info sym ;
bfd_map_over_sections( m_impl->m_bfd,
&SymbolInfo::BacktraceInfo::Callback,
@ -165,7 +172,7 @@ if ( btinfo.m_is_found )
filename.erase( pos, std::strlen( SRC_DIR ) ) ;
#endif
os << "#" << idx << " " << addr << " "
<< filename << ":" << btinfo.m_lineno
<< filename << ":" << btinfo.m_lineno
<< " "
<< (btinfo.m_func_name != 0 ? Demangle(btinfo.m_func_name) : "" )
<< std::endl ;

View File

@ -36,6 +36,10 @@ Feed2::Feed2( const std::string& url ):
{
}
Feed2::~Feed2()
{
}
bool Feed2::GetNext( http::Agent *http )
{
if ( m_next.empty() )

View File

@ -31,6 +31,7 @@ class Feed2: public Feed
{
public :
Feed2( const std::string& url ) ;
~Feed2() ;
bool GetNext( http::Agent *http ) ;
} ;

View File

@ -25,6 +25,13 @@
#include "http/Header.hh"
#include "util/log/Log.hh"
#include <netinet/in.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
// for debugging
#include <iostream>
@ -50,18 +57,29 @@ OAuth2::OAuth2(
const std::string& client_id,
const std::string& client_secret ) :
m_agent( agent ),
m_port( 0 ),
m_socket( -1 ),
m_client_id( client_id ),
m_client_secret( client_secret )
{
}
void OAuth2::Auth( const std::string& auth_code )
OAuth2::~OAuth2()
{
if ( m_socket >= 0 )
{
close( m_socket );
m_socket = -1;
}
}
bool OAuth2::Auth( const std::string& auth_code )
{
std::string post =
"code=" + auth_code +
"&client_id=" + m_client_id +
"&client_secret=" + m_client_secret +
"&redirect_uri=" + "urn:ietf:wg:oauth:2.0:oob" +
"&redirect_uri=http%3A%2F%2Flocalhost:" + std::to_string( m_port ) + "%2Fauth" +
"&grant_type=authorization_code" ;
http::ValResponse resp ;
@ -77,19 +95,120 @@ void OAuth2::Auth( const std::string& auth_code )
{
Log( "Failed to obtain auth token: HTTP %1%, body: %2%",
code, m_agent->LastError(), log::error ) ;
BOOST_THROW_EXCEPTION( AuthFailed() );
return false;
}
return true;
}
std::string OAuth2::MakeAuthURL()
{
if ( !m_port )
{
sockaddr_storage addr = { 0 };
addr.ss_family = AF_INET;
m_socket = socket( AF_INET, SOCK_STREAM, 0 );
if ( m_socket < 0 )
throw std::runtime_error( std::string("socket: ") + strerror(errno) );
if ( bind( m_socket, (sockaddr*)&addr, sizeof( addr ) ) < 0 )
{
close( m_socket );
m_socket = -1;
throw std::runtime_error( std::string("bind: ") + strerror(errno) );
}
socklen_t len = sizeof( addr );
if ( getsockname( m_socket, (sockaddr *)&addr, &len ) == -1 )
{
close( m_socket );
m_socket = -1;
throw std::runtime_error( std::string("getsockname: ") + strerror(errno) );
}
m_port = ntohs(((sockaddr_in*)&addr)->sin_port);
if ( listen( m_socket, 128 ) < 0 )
{
close( m_socket );
m_socket = -1;
m_port = 0;
throw std::runtime_error( std::string("listen: ") + strerror(errno) );
}
}
return "https://accounts.google.com/o/oauth2/auth"
"?scope=" + m_agent->Escape( "https://www.googleapis.com/auth/drive" ) +
"&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
"&redirect_uri=http%3A%2F%2Flocalhost:" + std::to_string( m_port ) + "%2Fauth" +
"&response_type=code"
"&client_id=" + m_client_id ;
}
bool OAuth2::GetCode( )
{
sockaddr_storage addr = { 0 };
int peer_fd = -1;
while ( peer_fd < 0 )
{
socklen_t peer_addr_size = sizeof( addr );
peer_fd = accept( m_socket, (sockaddr*)&addr, &peer_addr_size );
if ( peer_fd == -1 && errno != EAGAIN && errno != EINTR )
throw std::runtime_error( std::string("accept: ") + strerror(errno) );
}
fcntl( peer_fd, F_SETFL, fcntl( peer_fd, F_GETFL, 0 ) | O_NONBLOCK );
struct pollfd pfd = (struct pollfd){
.fd = peer_fd,
.events = POLLIN|POLLRDHUP,
};
char buf[4096];
std::string request;
while ( true )
{
pfd.revents = 0;
poll( &pfd, 1, -1 );
if ( pfd.revents & POLLRDHUP )
break;
int r = 1;
while ( r > 0 )
{
r = read( peer_fd, buf, sizeof( buf ) );
if ( r > 0 )
request += std::string( buf, r );
else if ( r == 0 )
break;
else if ( errno != EAGAIN && errno != EINTR )
throw std::runtime_error( std::string("read: ") + strerror(errno) );
}
if ( r == 0 || ( r < 0 && request.find( "\n" ) > 0 ) ) // GET ... HTTP/1.1\r\n
break;
}
bool ok = false;
if ( request.substr( 0, 10 ) == "GET /auth?" )
{
std::string line = request;
int p = line.find( "\n" );
if ( p > 0 )
line = line.substr( 0, p );
p = line.rfind( " " );
if ( p > 0 )
line = line.substr( 0, p );
p = line.find( "code=" );
if ( p > 0 )
line = line.substr( p+5 );
p = line.find( "&" );
if ( p > 0 )
line = line.substr( 0, p );
ok = Auth( line );
}
std::string response = ( ok
? "Authenticated successfully. Please close the page"
: "Authentication error. Please try again" );
response = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/html; charset=utf-8\r\n"
"Connection: close\r\n"
"\r\n"+
response+
"\r\n";
write( peer_fd, response.c_str(), response.size() );
close( peer_fd );
return ok;
}
void OAuth2::Refresh( )
{
std::string post =

View File

@ -41,13 +41,15 @@ public :
const std::string& refresh_code,
const std::string& client_id,
const std::string& client_secret ) ;
~OAuth2( ) ;
std::string Str() const ;
std::string MakeAuthURL() ;
void Auth( const std::string& auth_code ) ;
bool Auth( const std::string& auth_code ) ;
void Refresh( ) ;
bool GetCode( ) ;
std::string RefreshToken( ) const ;
std::string AccessToken( ) const ;
@ -59,7 +61,9 @@ private :
std::string m_access ;
std::string m_refresh ;
http::Agent* m_agent ;
int m_port ;
int m_socket ;
const std::string m_client_id ;
const std::string m_client_secret ;
} ;

View File

@ -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<std::string>() ) ) ;
if ( vm.count( "secret" ) > 0 )
m_cmd.Add( "secret", Val( vm["secret"].as<std::string>() ) ) ;
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
@ -80,7 +84,7 @@ void Config::Save( )
void Config::Set( const std::string& key, const Val& value )
{
m_file.Add( key, value ) ;
m_file.Set( key, value ) ;
}
Val Config::Get( const std::string& key ) const

View File

@ -59,7 +59,7 @@ void Stat( const std::string& filename, DateTime *t, off64_t *size, FileType *ft
if ( t )
{
#if defined __APPLE__ && defined __DARWIN_64_BIT_INO_T
#if defined __NetBSD__ || ( defined __APPLE__ && defined __DARWIN_64_BIT_INO_T )
*t = DateTime( s.st_ctimespec.tv_sec, s.st_ctimespec.tv_nsec ) ;
#else
*t = DateTime( s.st_ctim.tv_sec, s.st_ctim.tv_nsec);

View File

@ -31,6 +31,10 @@ class Path ;
enum FileType { FT_FILE = 1, FT_DIR = 2, FT_UNKNOWN = 3 } ;
#ifndef off64_t
#define off64_t off_t
#endif
namespace os
{
struct Error : virtual Exception {} ;

View File

@ -1,10 +1,11 @@
SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_PREFIX}/lib/grive/grive-sync.sh")
SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_FULL_LIBEXECDIR}/grive/grive-sync.sh")
CONFIGURE_FILE(grive-changes@.service.in grive-changes@.service @ONLY)
CONFIGURE_FILE(grive-timer@.service.in grive-timer@.service @ONLY)
install(
FILES
grive@.service
${CMAKE_BINARY_DIR}/systemd/grive-changes@.service
${CMAKE_BINARY_DIR}/systemd/grive-timer@.service
DESTINATION
@ -22,5 +23,5 @@ install(
PROGRAMS
grive-sync.sh
DESTINATION
lib/grive
)
${CMAKE_INSTALL_FULL_LIBEXECDIR}/grive
)

View File

@ -15,7 +15,7 @@ cd ~
### ARGUMENT PARSING ###
SCRIPT="${0}"
DIRECTORY=$(systemd-escape --unescape "$2")
DIRECTORY=$(systemd-escape --unescape -- "$2")
if [[ -z "$DIRECTORY" ]] || [[ ! -d "$DIRECTORY" ]] ; then
echo "Need a directory name in the current users home directory as second argument. Aborting."
@ -62,39 +62,36 @@ unlock() { _lock u; } # drop a lock
sync_directory() {
_directory="${1}"
reset_timer_and_exit() { echo "Retriggered google drive sync ('${_directory}')" && touch -m $LOCKFILE && exit; }
exlock_now || reset_timer_and_exit
if ping -c1 -W1 -q accounts.google.com >/dev/null 2>&1; then
true
# pass
else
echo "Google drive server not reachable..."
echo "Google drive server not reachable, NOT syncing..."
unlock
exit 0
fi
reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m "$LOCKFILE" && exit; }
exlock_now || reset_timer_and_exit
TIME_AT_START=0
TIME_AT_END=1
while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do
echo "Syncing "${_directory}"..."
echo "Syncing '${_directory}'..."
TIME_AT_START="$(stat -c %Y "$LOCKFILE")"
# exclude symlinks from sync
cat "${_directory}"/.griveignore 2>/dev/null | sed '/#LINKS-EDIT_BEFORE_THIS$/,$d' > /tmp/.griveignore.base
cp /tmp/.griveignore.base "${_directory}"/.griveignore
rm /tmp/.griveignore.base
echo "#LINKS-EDIT_BEFORE_THIS" >> "${_directory}"/.griveignore
( cd "${_directory}" && find . -type l | sed 's/^.\///g'; ) >> "${_directory}"/.griveignore
grive -p "${_directory}" 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$"
TIME_AT_END="$(stat -c %Y "$LOCKFILE")"
echo "Sync of "${_directory}" done."
echo "Sync of '${_directory}' done."
done
# always exit ok, so that we never go into a wrong systemd state
unlock
exit 0
}
### LISTEN TO DIRECTORY CHANGES ###
### LISTEN TO CHANGES IN DIRECTORY ###
listen_directory() {
@ -102,7 +99,7 @@ listen_directory() {
type inotifywait >/dev/null 2>&1 || { echo >&2 "I require inotifywait but it's not installed. Aborting."; exit 1; }
echo "Listening for changes in ~/"${_directory}""
echo "Listening for changes in '${_directory}'"
while true #run indefinitely
do

View File

@ -1,5 +1,5 @@
[Unit]
Description=Google drive sync
Description=Google drive sync (executed by timer unit)
After=network-online.target
[Service]

13
systemd/grive@.service Normal file
View File

@ -0,0 +1,13 @@
[Unit]
Description=Google drive sync (main)
Requires=grive-timer@%i.timer grive-changes@%i.service
# dummy service
[Service]
Type=oneshot
ExecStart=/bin/true
# This service shall be considered active after start
RemainAfterExit=yes
[Install]
WantedBy=default.target