From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-041.btinternet.com (mailomta14-re.btinternet.com [213.120.69.107]) by sourceware.org (Postfix) with ESMTPS id 1A08C385E03D for ; Fri, 8 Mar 2024 18:36:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A08C385E03D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1A08C385E03D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.107 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709923017; cv=none; b=KIkYOBqvzaUWR23rPip0I4LvaxhmJw6S8rOxxql0wzRVvJuSt8yVHcU1fHNywwOAaQ8YGi9hHCL7Bi0Nb/sjuo9IYHtsiEp32XvDy5LSFdFTQ9bL/RaVSp4r2PEkuNMsnHntyFeZdr6Qr0uz+INqsvScn7s4Sk8qBKiEUyVovP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709923017; c=relaxed/simple; bh=o2cEQG/3IaUsyx93b8tx3O5GD3GzfCQPrKWChWFE/YY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hn6rG+CMyqwtaPV8hEglxSPxbEjrTFI3286qzkKTwGanv2A1fT8eMng+fgLjBHsTtWRIijbXbD26Jaxo/kaEFn61fhR/lNghqn/5WGmSHqso9sLSDfnxgtLRfSMHQszsoOHsY9sn40rWWLcbEKEgUMHL7wigGRABTYvmKypy7co= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-041.btinternet.com with ESMTP id <20240308183653.UJQN21578.re-prd-fep-041.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Fri, 8 Mar 2024 18:36:53 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 6577B87C0AB06D7C X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdduudegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepudevleegtdduudeltedugeeuhefgteegkeeuhfeukeetkeduteekvdfgiefguddvnecuffhomhgrihhnpehgnhhurdhorhhgnecukfhppeekuddrudehfedrleekrddukeehnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekuddrudehfedrleekrddukeehpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekuddqudehfedqleekqddukeehrdhrrghnghgvkeduqdduheefrdgsthgtvghnthhrrghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhi nhhtvghrnhgvthdrtghomhdpghgvohfkrfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (81.153.98.185) by re-prd-rgout-004.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B87C0AB06D7C; Fri, 8 Mar 2024 18:36:53 +0000 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 16/16] Add beginnings of a command line installation tool Date: Fri, 8 Mar 2024 18:34:35 +0000 Message-ID: <20240308183440.4263-17-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk> References: <20240308183440.4263-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 +#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