From d9f779f071ee8a331cfea21109da95da50445eca Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 16 Oct 2023 21:57:57 -0700 Subject: [PATCH] initial import --- .gitignore | 5 ++ CMakeLists.txt | 38 +++++++++++ proto/header.proto | 11 ++++ proto/homedir.proto | 11 ++++ proto/path.proto | 31 +++++++++ scripts/install-depdendencies.sh | 106 +++++++++++++++++++++++++++++++ sgard.cc | 25 ++++++++ 7 files changed, 227 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 proto/header.proto create mode 100644 proto/homedir.proto create mode 100644 proto/path.proto create mode 100755 scripts/install-depdendencies.sh create mode 100644 sgard.cc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf2b2b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o + +build +cmake-build-* +sgard diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..50a7e66 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.22) + +project(sgard VERSION 0.0.1 + LANGUAGES CXX + DESCRIPTION "Shimmer Clarity Gardener: A dot-files manager.") + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_VERBOSE_MAKEFILES TRUE) + +find_package(Protobuf REQUIRED) +find_package(scsl REQUIRED) + +file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto") +PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${SCSL_INCLUDE_DIRS}) + +add_library(protolib STATIC ${ProtoSources} ${ProtoHeaders}) +target_link_libraries(protolib INTERFACE ${Protobuf_LIBRARIES}) + +add_compile_options( + "-static" + "-Werror" "-Wextra" "-Wall" + "-Weffc++" +) + +if (CMAKE_BUILD_TYPE STREQUAL Debug) + add_compile_options("-g" "-fsanitize=address") +endif () + +set(HEADER_FILES + +) + +set(SOURCE_FILES sgard.cc) + +add_executable(sgard ${SOURCE_FILES}) +target_link_libraries(sgard protolib ${SCSL_LIBRARIES}) diff --git a/proto/header.proto b/proto/header.proto new file mode 100644 index 0000000..b8cb3bf --- /dev/null +++ b/proto/header.proto @@ -0,0 +1,11 @@ +syntax = 'proto3'; +package sgardpb; + +import "google/protobuf/timestamp.proto"; + +// Header defines common metadata for messages in sgard. +message Header { + uint32 version = 1; + google.protobuf.Timestamp created = 2; + google.protobuf.Timestamp updated = 3; +} diff --git a/proto/homedir.proto b/proto/homedir.proto new file mode 100644 index 0000000..a2a8da4 --- /dev/null +++ b/proto/homedir.proto @@ -0,0 +1,11 @@ +syntax = 'proto3'; +package sgardpb; + +import 'header.proto'; +import 'path.proto'; + +message HomeDir { + Header header = 1; + + map files = 5; +}; diff --git a/proto/path.proto b/proto/path.proto new file mode 100644 index 0000000..8b388d3 --- /dev/null +++ b/proto/path.proto @@ -0,0 +1,31 @@ +syntax = 'proto3'; +package sgardpb; + +import 'header.proto'; +import "google/protobuf/timestamp.proto"; + +enum PathType { + PATHTYPE_UNSPECIFIED = 0; + PATHTYPE_FILE = 1; + PATHTYPE_DIRECTORY = 2; + PATHTYPE_LINK = 3; +}; + +message FilePath { + Header header = 1; + + string source_path = 2; + string dest_path = 3; + // todo: add mode, action (e.g. copy vs link) +}; + + +message Source { + Header header = 1; + PathType path_type = 2; + + oneof path { + FilePath file = 5; + }; +}; + diff --git a/scripts/install-depdendencies.sh b/scripts/install-depdendencies.sh new file mode 100755 index 0000000..d043163 --- /dev/null +++ b/scripts/install-depdendencies.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash + +##################################################################### +# This script attempts to install the appopriate build dependencies # +# for the host system. # +# # +# For platforms marked as unverified, it means that I was able to # +# start a Docker container for that platform and could look up the # +# right package names. I haven't actually tried building on these # +# platforms. # +# # +# This is primarily developed on the latest Ubuntu LTS release and # +# MacOS; other platforms are best-effort. # +##################################################################### + +set -eu + +install_debianesque () { + echo "[+] distribution is ${DISTRIB_ID}, choosing Debianesque install." + + echo "[+] installing tools" + sudo apt-get install git cmake clang scdoc + + echo "[+] installing protobuf libraries and development headers" + sudo apt-get install protobuf-compiler libprotobuf-dev + + echo "[+] installing gRPC libraries and development headers" + sudo apt-get install protobuf-compiler-grpc grpc-proto libgrpc++-dev +} + +install_redhat () { + echo "[+] distribution is ${DISTRIB_ID}, choosing Redhat install." + echo "[!] WARNING: installation for Redhat systems is unverified." + + echo "[+] installing tools" + sudo dnf install git cmake clang scdoc + + echo "[+] installing libraries and development headers" + sudo dnf install protobuf-compiler libprotobuf-dev +} + +install_alpine () { + echo "[+] distribution is ${DISTRIB_ID}, choosing Alpine install." + echo "[!] WARNING: installation for Alpine systems is unverified." + + echo "[+] installing tools" + sudo dnf install git cmake clang scdoc + + echo "[+] installing libraries and development headers" + sudo dnf install sdl2-dev freetype-dev protobuf-compiler-grpc +} + +install_macos () { + # TODO: consider supporting macports? + echo "[+] host system is MacOS" + + echo "[+] installing tools" + brew install git cmake scdoc + + echo "[+] installing libraries and development headers" + # TODO: look up proper package names in homebrew +} + + +install_linux () { + echo "[+] host system is Linux" + [[ -f "/etc/lsb-release" ]] && source /etc/lsb-release + if [ -z "${DISTRIB_ID}" ] + then + if [ -d /etc/apt ] + then + DISTRIB_ID="apt-based" + elif [ -f /etc/alpine-release ] + then + DISTRIB_ID=Alpine + elif [ -d /etc/dnf -o /etc/yum.repos.d ] + then + # I don't use Fedora, this is based on a cursory + # glance at the filesystem on a Docker image. + DISTRIB_ID="Fedora" + fi + fi + + case ${DISTRIB_ID} in + Ubuntu) install_debianesque ;; + Debian) install_debianesque ;; + apt-based) install_debianesque ;; + Fedora) install_redhat ;; + Alpine) install_alpine ;; + + *) + echo "[!] distribution ${DISTRIB_ID} isn't supported in this script." > /dev/null + ;; + esac +} + + +case "$(uname -s)" in + Linux) install_linux ;; + Darwin) install_macos ;; + *) + echo "[!] platform $(uname -s) isn't supported in this script." > /dev/null + ;; +esac + + diff --git a/sgard.cc b/sgard.cc new file mode 100644 index 0000000..83e6b72 --- /dev/null +++ b/sgard.cc @@ -0,0 +1,25 @@ +/// +/// \file sgard.cc +/// \author K. Isom +/// \date 2023-10-17 +/// \brief Shimmering Clarity Gardener: dot-file management. +/// + +#include + +#include + + +int +main(int argc, char *argv[]) +{ + auto flag = new scsl::Flags("sgard", "Shimmering Clarity Gardener: dot-file management"); + + auto parseResult = flag->Parse(argc, argv); + if (parseResult != scsl::Flags::ParseStatus::OK) { + std::cerr << "failed to parse flags: " + << scsl::Flags::ParseStatusToString(parseResult) + << "\n"; + flag->Usage(std::cerr, 1); + } +}