public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 16/16] Add beginnings of a command line installation tool
Date: Fri,  8 Mar 2024 18:34:35 +0000	[thread overview]
Message-ID: <20240308183440.4263-17-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk>

At the moment, all this can do is retrieve setup.ini from a selected
mirror and parse it.
---
 Makefile.am    |  22 +++++-
 cli/cyclops.cc | 186 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 cli/cyclops.cc

diff --git a/Makefile.am b/Makefile.am
index 6ae5dd6..5813e1a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,7 +35,10 @@ AM_CPPFLAGS = -D__USE_MINGW_ANSI_STDIO=1 -D_FILE_OFFSET_BITS=64 -DLZMA_API_STATI
 inilex_CXXFLAGS:=-Wno-sign-compare
 iniparse_CXXFLAGS:=-Wno-free-nonheap-object
 
-noinst_PROGRAMS = @SETUP@$(EXEEXT) inilint
+noinst_PROGRAMS = \
+	@SETUP@$(EXEEXT) \
+	inilint \
+	cyclops
 
 noinst_LTLIBRARIES = \
 	libsetupcore.la
@@ -214,6 +217,23 @@ IOSTREAM_PROVIDERS = \
 	io_stream_file.cc \
 	io_stream_file.h
 
+cyclops_SOURCES = \
+	$(IOSTREAM_PROVIDERS) \
+	cli/CliParseFeedback.cc \
+	cli/CliGetNetAuth.cc \
+	cli/CliGetUrlFeedback.cc \
+	cli/CliHashCheckFeedback.cc \
+	cli/CliFeedback.h \
+	cli/cyclops.cc \
+	res.rc
+
+cyclops_LDADD = \
+	libsetupcore.la \
+	libgetopt++/libgetopt++.la \
+	$(WININET)
+
+cyclops_LDFLAGS = -mconsole -Wc,-static -static-libtool-libs
+
 @SETUP@_LDADD = \
 	libsetupcore.la \
 	libgetopt++/libgetopt++.la \
diff --git a/cli/cyclops.cc b/cli/cyclops.cc
new file mode 100644
index 0000000..549b65a
--- /dev/null
+++ b/cli/cyclops.cc
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2020 Jon Turney
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+/*
+ * The one-eyed hippo sees all!
+ */
+
+#include "CliGetNetAuth.h"
+#include "CliFeedback.h"
+#include "ini.h"
+#include "LogFile.h"
+#include "resource.h"
+#include "setup_version.h"
+#include "state.h"
+
+#include "ConnectionSetting.h"
+#include "KeysSetting.h"
+#include "SiteSetting.h"
+#include "UserSettings.h"
+#include "netio.h"
+
+#include "getopt++/GetOption.h"
+#include "getopt++/BoolOption.h"
+
+BoolOption UnsupportedOption (false, '\0', "allow-unsupported-windows", IDS_HELPTEXT_ALLOW_UNSUPPORTED_WINDOWS);
+static BoolOption HelpOption (false, 'h', "help", IDS_HELPTEXT_HELP);
+
+static void
+main_cli ()
+{
+  // installation RootDir is already established by read_mounts()
+  ConnectionSetting ConnectionSettings;
+  ExtraKeysSetting ExtraKeys;
+  SiteSetting ChosenSites;
+
+  // check windows version and abort if too low unless UnsupportedOption
+
+  // announce myself
+  std::cout << "cyclops " << setup_version << std::endl;
+
+  // mode of operation
+  // XXX: probably only support download and install mode
+  source = IDC_SOURCE_NETINST;
+
+  // XXX: local package cache dir (from options or setup.rc)
+  // (fetched setp.ini is stored here)
+  char cwd[MAX_PATH];
+  GetCurrentDirectory (MAX_PATH, cwd);
+  local_dir = std::string (cwd);
+
+  // proxy
+
+  // interactive network auth getter
+  NetIO::auth_getter = new CliGetNetAuth();
+
+  // mirror site
+
+  // fetch and parse ini file(s)
+  CliFeedback feedback;
+  bool succeeded = do_ini_thread(feedback);
+  Log (LOG_PLAIN) << "do_ini_thread: " << succeeded << endLog;
+}
+
+static void
+main_wrap ()
+{
+  UserSettings Settings;
+  Settings.load (std::string());
+  main_cli ();
+  Settings.save (); // Clean exit. save user options.
+}
+
+int
+main (int argc, char **argv)
+{
+  LogSingleton::SetInstance (*LogFile::createLogFile ());
+
+  bool help_option = false;
+  bool invalid_option = false;
+
+  if (!GetOption::GetInstance ().Process (argc, argv, NULL))
+      help_option = invalid_option = true;
+    else if (HelpOption)
+      help_option = true;
+
+  if (help_option)
+    {
+      if (invalid_option)
+        Log (LOG_PLAIN) << "\n" << LoadStringUtf8(IDS_HELPTEXT_ERROR) << "\n" << endLog;
+
+      Log (LOG_PLAIN) << "\n" << LoadStringUtf8(IDS_HELPTEXT_HEADER) << "\n" << endLog;
+      GetOption::GetInstance ().ParameterUsage (Log (LOG_PLAIN), LoadStringUtf8);
+
+      Logger ().exit (invalid_option ? 1 : 0, false);
+      return 1;
+    }
+
+  LogSingleton::SetInstance (*LogFile::createLogFile ());
+
+  main_wrap();
+
+  return 0;
+}
+
+/* --- */
+
+#include <windows.h>
+#include "String++.h"
+
+int
+mbox (HWND owner, const char *buf, const char *name, int type)
+{
+  Log (LOG_PLAIN) << "mbox " << name << ": " << buf << endLog;
+
+  // XXX: unattended_result?
+  return IDOK;
+}
+
+int
+mbox(HWND owner, unsigned int format_id, int mb_type, ...)
+{
+  std::wstring fmt = LoadStringWEx(format_id, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
+  if (fmt.empty())
+    fmt = L"Internal error: format string resource not found";
+
+  va_list args;
+  va_start(args, mb_type);
+  std::wstring buf = vformat(fmt, args);
+  va_end(args);
+
+  // write unlocalized to log as UTF8
+  Log (LOG_PLAIN) << "mbox " << ": " << wstring_to_string(buf) << endLog;
+
+  // XXX: unattended_result?
+  return IDOK;
+}
+
+static int
+mbox (HWND owner, const char *name, int type, int id, va_list args)
+{
+  char buf[1000], fmt[1000];
+
+  if (LoadString (GetModuleHandle(NULL), id, fmt, sizeof (fmt)) <= 0)
+    ExitProcess (0);
+
+  vsnprintf (buf, 1000, fmt, args);
+  return mbox(owner, buf, name, type);
+}
+
+void
+note (HWND owner, int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (owner, "note", MB_OK, id, args);
+}
+
+void
+fatal (HWND owner, int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (owner, "fatal", MB_OK, id, args);
+  Logger ().exit (1);
+}
+
+int
+yesno (HWND owner, int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (owner, "yesno", MB_YESNO, id, args);
+  Log (LOG_PLAIN) << "Y/N" << endLog;
+  // XXX: yesno response!!!
+  return IDYES;
+}
-- 
2.43.0


      parent reply	other threads:[~2024-03-08 18:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 18:34 [PATCH setup 00/16] Groundwork for a GUI-less " Jon Turney
2024-03-08 18:34 ` [PATCH setup 01/16] Drop forward declaration of non-existent class IniState Jon Turney
2024-03-08 18:34 ` [PATCH setup 02/16] Move setup_exts[] to the only place it's used Jon Turney
2024-03-08 18:34 ` [PATCH setup 03/16] Split GuiParseFeedback out from ini fetcher Jon Turney
2024-03-08 18:34 ` [PATCH setup 04/16] Split out site into SiteSettings and SitePage Jon Turney
2024-03-08 18:34 ` [PATCH setup 05/16] Don't call Antivirus::AtExit() directly from Logger::exit() Jon Turney
2024-03-08 18:34 ` [PATCH setup 06/16] Simplify invocation of UserSettings::open_settings() Jon Turney
2024-03-08 18:34 ` [PATCH setup 07/16] Split out URL fetching progress reporting Jon Turney
2024-03-08 18:34 ` [PATCH setup 08/16] Instantiate found_ini_list in ini.cc Jon Turney
2024-03-08 18:34 ` [PATCH setup 09/16] Move is_64bit to state Jon Turney
2024-03-08 18:34 ` [PATCH setup 10/16] Move setup.ini pathame components to ini.cc Jon Turney
2024-03-08 18:34 ` [PATCH setup 11/16] Drop hinstance global Jon Turney
2024-03-08 18:34 ` [PATCH setup 12/16] Spit out GetNetAuth from NetIO Jon Turney
2024-03-08 18:34 ` [PATCH setup 13/16] Split out hash checking progress reporting Jon Turney
2024-03-08 18:34 ` [PATCH setup 14/16] Push check_for_cached into package_source Jon Turney
2024-03-08 18:34 ` [PATCH setup 15/16] Put various shared subcomponents into a convenience library Jon Turney
2024-03-08 18:34 ` Jon Turney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240308183440.4263-17-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).