:-'Generic Commit'
This commit is contained in:
parent
e37beca85e
commit
254609facd
109
dropshell-tool/CMakeLists.txt
Normal file
109
dropshell-tool/CMakeLists.txt
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
set(PROJECT_EXE_NAME dropshell-tool)
|
||||||
|
project(${PROJECT_EXE_NAME} VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
# Force static linking globally
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||||
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
|
||||||
|
set(ZLIB_USE_STATIC_LIBS "ON")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Set default build type to Release if not specified
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configure build-specific compiler flags
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
|
||||||
|
|
||||||
|
# Configure version information
|
||||||
|
string(TIMESTAMP CURRENT_YEAR "%Y")
|
||||||
|
string(TIMESTAMP CURRENT_MONTH "%m")
|
||||||
|
string(TIMESTAMP CURRENT_DAY "%d")
|
||||||
|
string(TIMESTAMP CURRENT_HOUR "%H")
|
||||||
|
string(TIMESTAMP CURRENT_MINUTE "%M")
|
||||||
|
set(PROJECT_VERSION "${CURRENT_YEAR}.${CURRENT_MONTH}${CURRENT_DAY}.${CURRENT_HOUR}${CURRENT_MINUTE}")
|
||||||
|
string(TIMESTAMP RELEASE_DATE "%Y-%m-%d")
|
||||||
|
|
||||||
|
# Configure version.hpp file
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/src/autogen/version.hpp"
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set CMAKE_MODULE_PATH to include our custom find modules
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
|
# Auto-detect source files
|
||||||
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
|
file(GLOB_RECURSE HEADERS "src/*.hpp")
|
||||||
|
|
||||||
|
# Add custom target to run cmake_prebuild.sh at the start of the build process
|
||||||
|
add_custom_target(run_prebuild_script ALL
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo "Running cmake_prebuild.sh..."
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add executable
|
||||||
|
add_executable(${PROJECT_EXE_NAME} ${SOURCES})
|
||||||
|
add_dependencies(${PROJECT_EXE_NAME} run_prebuild_script)
|
||||||
|
|
||||||
|
# Set include directories
|
||||||
|
# build dir goes first so that we can use the generated version.hpp
|
||||||
|
target_include_directories(${PROJECT_EXE_NAME} PRIVATE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/autogen>
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
# Configure libassert
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
libassert
|
||||||
|
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert.git
|
||||||
|
GIT_TAG v2.1.5
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(libassert)
|
||||||
|
|
||||||
|
# Add cpptrace
|
||||||
|
FetchContent_Declare(
|
||||||
|
cpptrace
|
||||||
|
GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
|
||||||
|
GIT_TAG v0.8.3
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(cpptrace)
|
||||||
|
|
||||||
|
# Add nlohmann/json
|
||||||
|
FetchContent_Declare(
|
||||||
|
nlohmann_json
|
||||||
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||||
|
GIT_TAG v3.11.3
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(nlohmann_json)
|
||||||
|
|
||||||
|
# Link libraries
|
||||||
|
target_link_libraries(${PROJECT_EXE_NAME} PRIVATE
|
||||||
|
libassert::assert
|
||||||
|
cpptrace::cpptrace
|
||||||
|
nlohmann_json::nlohmann_json
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set static linking flags
|
||||||
|
set_target_properties(${PROJECT_EXE_NAME} PROPERTIES
|
||||||
|
LINK_FLAGS "-static"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Install targets
|
||||||
|
install(TARGETS ${PROJECT_EXE_NAME}
|
||||||
|
RUNTIME DESTINATION $ENV{HOME}/.local/bin
|
||||||
|
)
|
||||||
|
|
3
dropshell-tool/cmake_prebuild.sh
Executable file
3
dropshell-tool/cmake_prebuild.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "cmake_prebuild.sh complete."
|
55
dropshell-tool/src/main.cpp
Normal file
55
dropshell-tool/src/main.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
dropshell-tool
|
||||||
|
|
||||||
|
dropshell-tool install <tool_name>
|
||||||
|
- confirms dropshell-tool is fully initialised:
|
||||||
|
- adds a line to the user's .bashrc file to source the dropshell-tool ~/.bashrc_dropshell_tool script, if it doesn't exist
|
||||||
|
- creates an empty ~/.bashrc_dropshell_tool script if it doesn't exist
|
||||||
|
- creates the ~/.config/dropshell-tool directory, if it does not exist
|
||||||
|
- creates the ~/.local/bin/dropshell-tool directory, if it does not exist
|
||||||
|
|
||||||
|
- removes the tool from the user's system if it is already installed, and the tool's entries in the ~/.bashrc_dropshell_tool script
|
||||||
|
- downloads the tool archive (tgz) from getbin.xyz (tool_name:ARCH), where ARCH is the architecture of the user's system, and unpacks it to the new tool directory: ~/.local/bin/dropshell-tool/<tool_name>/
|
||||||
|
- sets the PATH to include the tool directory, by modifying the ~/.bashrc_dropshell_tool script
|
||||||
|
- adds an entry for autocompletion for the tool to the ~/.bashrc_dropshell_tool script, where autocomplete just runs <tool_name> autocomplete <args>
|
||||||
|
- creates a ~/.config/dropshell-tool/tool_name.json file, which contains the tool's name, version (by running <tool_name> version), hash from getbin.xyz, and architecture
|
||||||
|
- reads the json file from the tgz called dropshell-tool-config.json:
|
||||||
|
- for each alias in the aliases array:
|
||||||
|
- check if another command is using the alias, and continue only if not
|
||||||
|
- check that the alias is not already in the ~/.bashrc_dropshell_tool script and continue only if not
|
||||||
|
- add an entry to the ~/.bashrc_dropshell_tool script to run the tool via the alias
|
||||||
|
- if the json file has a setup_script entry, run the script named in the entry in the tool directory - using sudo if the entry has sudo set to true.
|
||||||
|
|
||||||
|
dropshell-tool publish <tool_name:ARCH> <folder>
|
||||||
|
- checks that dropshell-tool-config.json exists in the folder, and is valid (see above)
|
||||||
|
- creates a tgz archive of the folder, and uploads it to getbin.xyz's simple object storage server.
|
||||||
|
- prints the URL and hash of the uploaded archive
|
||||||
|
- uses the token ~/.config/getbin.xyz/write_token.txt, or prompts the user for a token if it is not found and writes it to the file
|
||||||
|
|
||||||
|
dropshell-tool update <tool_name>
|
||||||
|
- compares the hash from the ~/.config/dropshell-tool/tool_name.json file with the hash from getbin.xyz (tool_name:ARCH), and continues only if they are different
|
||||||
|
- checks the version from the ~/.config/dropshell-tool/tool_name.json file with the version from getbin.xyz (tool_name:ARCH), and continues only if the remote version is newer (installed is older)
|
||||||
|
- installs the tool as per the install command
|
||||||
|
|
||||||
|
dropshell-tool update all
|
||||||
|
- runs update on all installed tools
|
||||||
|
|
||||||
|
dropshell-tool autocomplete <args>
|
||||||
|
- shows autocomplete for dropshell-tool, and then exits
|
||||||
|
- the tool list to choose from when calling install is hard coded in the autocomplete function
|
||||||
|
|
||||||
|
dropshell-tool version
|
||||||
|
- prints the version of dropshell-tool
|
||||||
|
|
||||||
|
dropshell-tool create <tool_name>
|
||||||
|
- creates a new tool source directory in relative path <tool_name> if it doesn't exist
|
||||||
|
- creates a dropshell-tool-config.json file in the tool source directory if it doesn't exist, with the following entries:
|
||||||
|
- aliases: an array of aliases for the tool
|
||||||
|
- setup_script: the name of the setup script to run (setup_script.sh)
|
||||||
|
- creates a setup_script.sh file in the tool source directory if it doesn't exist, that just prints a completion message and exits
|
||||||
|
|
||||||
|
dropshell-tool help
|
||||||
|
- shows this help message
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
4
install.sh
Normal file
4
install.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# install dropshell-tools!
|
Loading…
x
Reference in New Issue
Block a user