You can disable the automatic update check by setting CRYFS_NO_UPDATE_CHECK=true in your environment.
This commit is contained in:
parent
9c83d3b2a4
commit
d95cc33a58
@ -3,6 +3,7 @@ Version 0.9.3 (unreleased)
|
||||
* It's easier for tools and scripts to use CryFS:
|
||||
If an environment variable CRYFS_FRONTEND=noninteractive is set, we don't ask for options (but take default values for everything that's not specified on command line).
|
||||
Furthermore, we won't ask for password confirmation when creating a file system but the password only has to be sent once to stdin.
|
||||
* You can disable the automatic update check by setting CRYFS_NO_UPDATE_CHECK=true in your environment.
|
||||
|
||||
Version 0.9.2
|
||||
---------------
|
||||
|
@ -5,6 +5,7 @@ set(SOURCES
|
||||
cli/VersionChecker.cpp
|
||||
cli/VersionCompare.cpp
|
||||
cli/CallAfterTimeout.cpp
|
||||
cli/Environment.cpp
|
||||
cli/program_options/utils.cpp
|
||||
cli/program_options/ProgramOptions.cpp
|
||||
cli/program_options/Parser.cpp
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "VersionChecker.h"
|
||||
#include "VersionCompare.h"
|
||||
#include "Environment.h"
|
||||
|
||||
//TODO Fails with gpg-homedir in filesystem: gpg --homedir gpg-homedir --gen-key
|
||||
//TODO Many functions accessing the ProgramOptions object. Factor out into class that stores it as a member.
|
||||
@ -70,15 +71,10 @@ using cpputils::dynamic_pointer_move;
|
||||
//TODO Performance difference when setting compiler parameter -maes for scrypt?
|
||||
|
||||
namespace cryfs {
|
||||
const string Cli::CRYFS_FRONTEND_KEY = "CRYFS_FRONTEND";
|
||||
const string Cli::CRYFS_FRONTEND_NONINTERACTIVE = "noninteractive";
|
||||
|
||||
Cli::Cli(RandomGenerator &keyGenerator, const SCryptSettings &scryptSettings, shared_ptr<Console> console, shared_ptr<HttpClient> httpClient):
|
||||
_keyGenerator(keyGenerator), _scryptSettings(scryptSettings), _console(console), _httpClient(httpClient), _noninteractive(false) {
|
||||
char *frontend = std::getenv(CRYFS_FRONTEND_KEY.c_str());
|
||||
if (frontend != nullptr && frontend == CRYFS_FRONTEND_NONINTERACTIVE) {
|
||||
_noninteractive = true;
|
||||
}
|
||||
_noninteractive = Environment::isNoninteractive();
|
||||
}
|
||||
|
||||
void Cli::_showVersion() {
|
||||
@ -95,6 +91,13 @@ namespace cryfs {
|
||||
#ifndef NDEBUG
|
||||
cout << "WARNING! This is a debug build. Performance might be slow." << endl;
|
||||
#endif
|
||||
if (!Environment::noUpdateCheck()) {
|
||||
_checkForUpdates();
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void Cli::_checkForUpdates() {
|
||||
VersionChecker versionChecker(_httpClient);
|
||||
optional<string> newestVersion = versionChecker.newestVersion();
|
||||
if (newestVersion == none) {
|
||||
@ -106,7 +109,6 @@ namespace cryfs {
|
||||
if (securityWarning != none) {
|
||||
cout << *securityWarning << endl;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
bool Cli::_checkPassword(const string &password) {
|
||||
|
@ -19,6 +19,7 @@ namespace cryfs {
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
private:
|
||||
void _checkForUpdates();
|
||||
void _runFilesystem(const program_options::ProgramOptions &options);
|
||||
CryConfigFile _loadOrCreateConfig(const program_options::ProgramOptions &options);
|
||||
boost::optional<CryConfigFile> _loadOrCreateConfigFile(const boost::filesystem::path &configFilePath, const boost::optional<std::string> &cipher);
|
||||
@ -40,8 +41,6 @@ namespace cryfs {
|
||||
boost::optional<cpputils::unique_ref<CallAfterTimeout>> _createIdleCallback(boost::optional<double> minutes, std::function<void()> callback);
|
||||
void _sanityCheckFilesystem(CryDevice *device);
|
||||
|
||||
static const std::string CRYFS_FRONTEND_KEY;
|
||||
static const std::string CRYFS_FRONTEND_NONINTERACTIVE;
|
||||
|
||||
cpputils::RandomGenerator &_keyGenerator;
|
||||
cpputils::SCryptSettings _scryptSettings;
|
||||
|
19
src/cryfs/cli/Environment.cpp
Normal file
19
src/cryfs/cli/Environment.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "Environment.h"
|
||||
#include <cstdlib>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace cryfs {
|
||||
const string Environment::FRONTEND_KEY = "CRYFS_FRONTEND";
|
||||
const string Environment::FRONTEND_NONINTERACTIVE = "noninteractive";
|
||||
const string Environment::NOUPDATECHECK_KEY = "CRYFS_NO_UPDATE_CHECK";
|
||||
|
||||
bool Environment::isNoninteractive() {
|
||||
char *frontend = std::getenv(FRONTEND_KEY.c_str());
|
||||
return frontend != nullptr && frontend == FRONTEND_NONINTERACTIVE;
|
||||
}
|
||||
|
||||
bool Environment::noUpdateCheck() {
|
||||
return nullptr != std::getenv(NOUPDATECHECK_KEY.c_str());
|
||||
}
|
||||
}
|
24
src/cryfs/cli/Environment.h
Normal file
24
src/cryfs/cli/Environment.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#ifndef MESSMER_CRYFS_CLI_ENVIRONMENT_H
|
||||
#define MESSMER_CRYFS_CLI_ENVIRONMENT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class Environment {
|
||||
public:
|
||||
static bool isNoninteractive();
|
||||
static bool noUpdateCheck();
|
||||
|
||||
private:
|
||||
Environment() = delete;
|
||||
|
||||
static const std::string FRONTEND_KEY;
|
||||
static const std::string FRONTEND_NONINTERACTIVE;
|
||||
static const std::string NOUPDATECHECK_KEY;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -9,6 +9,7 @@ set(SOURCES
|
||||
cli/program_options/ProgramOptionsTest.cpp
|
||||
cli/program_options/ParserTest.cpp
|
||||
cli/CliTest_ShowingHelp.cpp
|
||||
cli/EnvironmentTest.cpp
|
||||
cli/VersionCheckerTest.cpp
|
||||
cli/VersionCompareTest.cpp
|
||||
config/crypto/CryConfigEncryptorFactoryTest.cpp
|
||||
|
64
test/cryfs/cli/EnvironmentTest.cpp
Normal file
64
test/cryfs/cli/EnvironmentTest.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cryfs/cli/Environment.h>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
using namespace cryfs;
|
||||
using std::string;
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
|
||||
class EnvironmentTest : public ::testing::Test {
|
||||
public:
|
||||
// WithEnv sets an environment variable while it is in scope.
|
||||
// Once it leaves scope, the environment is reset.
|
||||
class WithEnv {
|
||||
public:
|
||||
WithEnv(const string &key, const string &value): _key(key) , _oldValue(none) {
|
||||
char *oldValue = std::getenv(key.c_str());
|
||||
if (nullptr != oldValue) {
|
||||
_oldValue = string(oldValue);
|
||||
}
|
||||
::setenv(key.c_str(), value.c_str(), 1);
|
||||
}
|
||||
~WithEnv() {
|
||||
if (none == _oldValue) {
|
||||
::unsetenv(_key.c_str());
|
||||
} else {
|
||||
::setenv(_key.c_str(), _oldValue->c_str(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
string _key;
|
||||
optional<string> _oldValue;
|
||||
};
|
||||
};
|
||||
|
||||
TEST_F(EnvironmentTest, Noninteractive_Unset) {
|
||||
EXPECT_FALSE(Environment::isNoninteractive());
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, Noninteractive_Set) {
|
||||
WithEnv env("CRYFS_FRONTEND", "noninteractive");
|
||||
EXPECT_TRUE(Environment::isNoninteractive());
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, Noninteractive_SetToOtherValue) {
|
||||
WithEnv env("CRYFS_FRONTEND", "someotherfrontend");
|
||||
EXPECT_FALSE(Environment::isNoninteractive());
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, NoUpdateCheck_Unset) {
|
||||
EXPECT_FALSE(Environment::noUpdateCheck());
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, NoUpdateCheck_Set) {
|
||||
WithEnv env("CRYFS_NO_UPDATE_CHECK", "true");
|
||||
EXPECT_TRUE(Environment::noUpdateCheck());
|
||||
}
|
||||
|
||||
TEST_F(EnvironmentTest, NoUpdateCheck_SetToOtherValue) {
|
||||
WithEnv env("CRYFS_NO_UPDATE_CHECK", "someothervalue");
|
||||
// No matter what the value is, setting the environment variable says we don't do update checks.
|
||||
EXPECT_TRUE(Environment::noUpdateCheck());
|
||||
}
|
Loading…
Reference in New Issue
Block a user