commit 8fc509ce1f50c21fd03efbd0d604f87460b3d0e9 Author: SM9CC Date: Thu Nov 25 14:00:14 2021 +0000 Init diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1766a7c --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +AlignOperands: DontAlign +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: None +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: MultiLine +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Never + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterUnion: true + BeforeCatch: true + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 210 +CompactNamespaces: false +ContinuationIndentWidth: 4 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: ForIndentation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..23fe7dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,343 @@ +Psyris/Resources/Shaders/Build/ + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# CLion +/cmake-build-debug/ +/cmake-build-release/ + +# GDB +/gdb.txt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d99ee44 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +CachyOS-Installer \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..a98cb47 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d324358 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/new-installer.iml b/.idea/new-installer.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/new-installer.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fc94963 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.21) +project(CachyOS-Installer) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_C_COMPILER "/usr/bin/clang") +set(CMAKE_CXX_COMPILER "/usr/bin/clang++") + +set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld") +set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld") +set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld") +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") + +set(CMAKE_C_FLAGS "-fno-rtti -Wno-non-virtual-dtor -Wno-strict-aliasing -Wl,-Bdynamic -Wno-unused-command-line-argument") +set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++20") + +set(CMAKE_C_FLAGS_RELEASE "-flto=thin -gsplit-dwarf -fno-stack-protector -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-math-errno -fno-ident -Wl,--strip-all -Wl,--discard-all") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") + +set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g -O0") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + +file(GLOB_RECURSE SOURCES "${CMAKE_SOURCE_DIR}/include/*.cpp" "${CMAKE_SOURCE_DIR}/resources/*.cpp" "${CMAKE_SOURCE_DIR}/src/*.cpp") + +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) + +find_package(nlohmann_json REQUIRED) +find_package(ftxui REQUIRED) + + +add_executable(CachyOS-Installer ${SOURCES} src/utils.h src/utils.cpp src/definitions.h) + +target_include_directories(CachyOS-Installer PRIVATE ${SDL2_INCLUDE_DIRS} "${CMAKE_SOURCE_DIR}/include/") +target_link_libraries(CachyOS-Installer PRIVATE ftxui::screen PRIVATE ftxui::dom PRIVATE ftxui::component nlohmann_json::nlohmann_json) +target_link_options(CachyOS-Installer PRIVATE LINKER:--no-undefined) diff --git a/src/definitions.h b/src/definitions.h new file mode 100644 index 0000000..705bfdc --- /dev/null +++ b/src/definitions.h @@ -0,0 +1,28 @@ +#ifndef DEFINITIONS_H +#define DEFINITIONS_H + +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +#define output(value) cout << value << endl +#define error(errorString) cout << RED << errorString << RESET << endl +#define warning(warningString) cout << YELLOW << warningString << RESET << endl +#define info(infoString) cout << CYAN << infoString << RESET << endl +#define success(successString) cout << GREEN << successString << RESET << endl + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..1762730 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,36 @@ +#include "definitions.h" +#include "utils.h" +#include +#include + +int main() +{ + if (!Utils::isConnected()) { + warning("It seems you are not connected, waiting for 15s before retrying..."); + sleep(15); + + if (!Utils::isConnected()) { + char type = '\0'; + + while (Utils::promptForChar("An internet connection could not be detected, do you want to connect to a wifi network? [y/n]", type, RED)) { + if (type != 'n') { + + info("\nInstructions to connect to wifi using iwclt:"); + info("1 - Find your wifi device name ex: wlan0"); + info("2 - type `station wlan0 scan`, and wait couple seconds"); + info("3 - type `station wlan0 get-networks` (find your wifi Network name ex. my_wifi)"); + info("4 - type `station wlan0 connect my_wifi` (don't forget to press TAB for auto completion!"); + info("5 - type `station wlan0 show` (status should be connected)"); + info("6 - type `exit`\n"); + + while (Utils::promptForChar("Press a key to continue...", type, CYAN)) { + Utils::exec("iwctl"); + break; + } + } + + break; + } + } + } +} diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..b318fe4 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,48 @@ +#include "utils.h" +#include +#include + +bool Utils::isConnected() +{ + return gethostbyname("google.com"); +} + +string Utils::exec(const string &command) +{ + char buffer[128]; + string result; + + FILE *pipe = popen(command.c_str(), "r"); + + if (!pipe) { + return "popen failed!"; + } + + while (!feof(pipe)) { + if (fgets(buffer, 128, pipe) != nullptr) { + result += buffer; + } + } + + pclose(pipe); + + return result; +} + +bool Utils::promptForChar(const char *prompt, char &read, const char *colour) +{ + std::string tmp; + std::cout << colour << prompt << std::endl; + + if (std::getline(std::cin, tmp)) { + if (tmp.length() == 1) { + read = tmp[0]; + } else { + read = '\0'; + } + + return true; + } + + return false; +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..59df325 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,21 @@ +#ifndef UTILS_H +#define UTILS_H + +#include "definitions.h" +#include + +using namespace std; + + +class Utils +{ +public: + static void printBanner(); + static bool isConnected(); + static std::string exec(const string &command); + static bool promptForChar(const char *prompt, char &read, const char *colour = RESET); + +private: +}; + +#endif//UTILS_H diff --git a/toolbox.sh b/toolbox.sh new file mode 100755 index 0000000..33ef071 --- /dev/null +++ b/toolbox.sh @@ -0,0 +1,102 @@ +#!/bin/bash +clear + +binName="CachyOS-Installer" + +if [[ $EUID -eq 0 ]]; then + echoRed "You cannot run this as root." + exit 1 +fi + +function run() { + sudo $binName +} + +function build() { + echoGreen "Building CachyOS Installer..." + + if [[ ! -d "cmake-build-release" ]]; then + mkdir -p cmake-build-release + fi + + cd cmake-build-release || return + cmake -D CMAKE_BUILD_TYPE=Release .. + make -j "$(nproc --all)" + sudo cp -rf $binName /usr/bin/$binName + cd .. +} + +function buildDebug() { + echoOrange "Building CachyOS Installer in debug..." + + if [[ ! -d "cmake-build-debug" ]]; then + mkdir -p cmake-build-debug + fi + + cd cmake-build-debug || return + cmake -D CMAKE_BUILD_TYPE=Debug .. + make -j "$(nproc --all)" + sudo cp -rf $binName /usr/bin/$binName + cd .. +} + +function pull() { + git pull +} + +function echoOrange() { + echo -e "\\e[33m$*\\e[0m" +} + +function echoRed() { + echo -e "\\e[31m$*\\e[0m" +} + +function echoGreen() { + echo -e "\\e[32m$*\\e[0m" +} + +while [[ $# -gt 0 ]]; do + keys="$1" + case $keys in + -r | --run) + run + shift + ;; + -b | --build) + build + shift + ;; + -bd | --build_debug) + buildDebug + shift + ;; + -p | --pull) + pull + shift + ;; + -h | --help) + echo " +Toolbox script for Polis +============================================================================================= +| Argument | Description | +| -------------------- | -------------------------------------------------------------------| +| -r (--run) | Run the built binary. | +| -b (--build) | Build and install. | +| -bd (--build_debug) | Build and install as debug. | +| -p (--pull) | Update from repo. | +| -h (--help) | Show help. | +============================================================================================= + +All args are executed in the order they are written in, for +example, \"-p -b -r\" would update the software, then build it, and +then run it. +" + exit + ;; + *) + echo "Unknown arg $1, use -h for help" + exit + ;; + esac +done