- Namespace ns = parseArgs(args);
- if (ns == null) {
- System.exit(1);
- }
-
- int res = init(ns);
- System.exit(res);
- }
-
- public static void installSecurityProviderWorkaround() {
- // Register our own security provider
- Security.insertProviderAt(new SecurityProvider(), 1);
- Security.addProvider(new BouncyCastleProvider());
- }
-
- public static int init(Namespace ns) {
- if (ns.getBoolean("dbus") || ns.getBoolean("dbus_system")) {
- return initDbusClient(ns, ns.getBoolean("dbus_system"));
- }
-
- final String username = ns.getString("username");
-
- final File dataPath;
- String config = ns.getString("config");
- if (config != null) {
- dataPath = new File(config);
- } else {
- dataPath = getDefaultDataPath();
- }
-
- final SignalServiceConfiguration serviceConfiguration = ServiceConfig.createDefaultServiceConfiguration(
- BaseConfig.USER_AGENT);
-
- if (!ServiceConfig.getCapabilities().isGv2()) {
- logger.warn("WARNING: Support for new group V2 is disabled,"
- + " because the required native library dependency is missing: libzkgroup");
- }
-
- if (username == null) {
- ProvisioningManager pm = new ProvisioningManager(dataPath, serviceConfiguration, BaseConfig.USER_AGENT);
- return handleCommands(ns, pm);
- }
-
- Manager manager;
- try {
- manager = Manager.init(username, dataPath, serviceConfiguration, BaseConfig.USER_AGENT);
- } catch (Throwable e) {
- logger.error("Error loading state file: {}", e.getMessage());
- return 2;
- }
-
- try (Manager m = manager) {
- try {
- m.checkAccountState();
- } catch (AuthorizationFailedException e) {
- if (!"register".equals(ns.getString("command"))) {
- // Register command should still be possible, if current authorization fails
- System.err.println("Authorization failed, was the number registered elsewhere?");
- return 2;
- }
- } catch (IOException e) {
- logger.error("Error while checking account: {}", e.getMessage());
- return 2;
- }