Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
902e68069a | |||
0aafc2cc1e | |||
2067caf253 | |||
4d500cbddd | |||
884609f661 | |||
a5a36c179b | |||
42b51ef0be | |||
f094d532cf | |||
fffa88482a | |||
54af706032 | |||
ef7470dcce | |||
d18f875c0e | |||
6f525b4f6c | |||
ed13bdb5b5 |
16
README.md
16
README.md
@ -60,6 +60,8 @@ getpkg version
|
|||||||
|
|
||||||
### Information
|
### Information
|
||||||
|
|
||||||
|
- **`getpkg list`** - List all available packages with status
|
||||||
|
- **`getpkg clean`** - Clean up orphaned configs and symlinks
|
||||||
- **`getpkg version`** - Show getpkg version
|
- **`getpkg version`** - Show getpkg version
|
||||||
- **`getpkg help`** - Show detailed help
|
- **`getpkg help`** - Show detailed help
|
||||||
- **`getpkg autocomplete`** - Show available commands for completion
|
- **`getpkg autocomplete`** - Show available commands for completion
|
||||||
@ -99,14 +101,14 @@ Tools are automatically downloaded for your architecture, with fallback to unive
|
|||||||
### Installing Popular Tools
|
### Installing Popular Tools
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install development tools
|
# Install available tools
|
||||||
getpkg whatsdirty # Fast grep alternative
|
getpkg install dehydrate # File to C++ code generator
|
||||||
getpkg fd # Fast find alternative
|
getpkg install bb64 # Bash base64 encoder/decoder
|
||||||
getpkg bat # Cat with syntax highlighting
|
|
||||||
|
|
||||||
# Install system utilities
|
# Development tools (for repository development)
|
||||||
getpkg whatsdirty # Check git repo status
|
getpkg install whatsdirty # Check git repo status
|
||||||
getpkg sos # Simple object storage client
|
getpkg install sos # Simple object storage client
|
||||||
|
getpkg install gp # Git push utility
|
||||||
```
|
```
|
||||||
|
|
||||||
### Publishing Your Own Tools
|
### Publishing Your Own Tools
|
||||||
|
@ -5,7 +5,8 @@ if(NOT DEFINED PROJECT_NAME)
|
|||||||
message(FATAL_ERROR "PROJECT_NAME is not defined. Pass it via -DPROJECT_NAME=<name>")
|
message(FATAL_ERROR "PROJECT_NAME is not defined. Pass it via -DPROJECT_NAME=<name>")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(${PROJECT_NAME})
|
string(TIMESTAMP PROJECT_VERSION "%Y.%m%d.%H%M")
|
||||||
|
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES CXX)
|
||||||
|
|
||||||
# Build configuration
|
# Build configuration
|
||||||
set(CMAKE_CXX_STANDARD 23)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
@ -21,6 +22,8 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/b64ed.cpp
|
src/b64ed.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Configure version.hpp
|
||||||
|
configure_file("src/version.hpp.in" "src/autogen/version.hpp" @ONLY)
|
||||||
|
|
||||||
# Include directories
|
# Include directories
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
|
@ -26,6 +26,8 @@ Usage:
|
|||||||
bb64 -[i|d] BASE64COMMAND Displays the decoded command
|
bb64 -[i|d] BASE64COMMAND Displays the decoded command
|
||||||
bb64 -e COMMAND Encodes the command and prints the result
|
bb64 -e COMMAND Encodes the command and prints the result
|
||||||
bb64 -u Updates bb64 to the latest version (uses docker)
|
bb64 -u Updates bb64 to the latest version (uses docker)
|
||||||
|
bb64 -v Prints the version number
|
||||||
|
bb64 version Prints the version number
|
||||||
```
|
```
|
||||||
|
|
||||||
# Implementation Notes
|
# Implementation Notes
|
||||||
|
@ -12,19 +12,10 @@ if [ "$ARCH" = "aarch64" ]; then
|
|||||||
ARCH_ALIAS="arm64"
|
ARCH_ALIAS="arm64"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increment version
|
# Get version from CMake timestamp
|
||||||
VERSION_FILE="${SCRIPT_DIR}/src/version.h"
|
VERSION=$(date +"%Y.%m%d.%H%M")
|
||||||
if [ ! -f "${VERSION_FILE}" ]; then
|
TAG="v$VERSION"
|
||||||
echo "${VERSION_FILE} not found!" >&2
|
echo "Building version $VERSION" >&2
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
v=$(cat "${VERSION_FILE}" | grep -o 'static const char \*VERSION = "[0-9.]*";' | cut -d'"' -f2)
|
|
||||||
oldv=$v
|
|
||||||
v=$((v+1))
|
|
||||||
echo "Incrementing version from $oldv to $v" >&2
|
|
||||||
echo "static const char *VERSION = \"$v\";" > "${VERSION_FILE}"
|
|
||||||
fi
|
|
||||||
TAG="v$v"
|
|
||||||
|
|
||||||
# build release version
|
# build release version
|
||||||
export CMAKE_BUILD_TYPE="Release"
|
export CMAKE_BUILD_TYPE="Release"
|
||||||
@ -77,24 +68,68 @@ if [ -z "$RELEASE_WRITE_TOKEN" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Creating release $TAG on Gitea..."
|
# Create and push git tag
|
||||||
RELEASE_RESPONSE=$(curl -s -X POST "$API_URL/releases" \
|
echo "Creating git tag $TAG..."
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-H "Authorization: token $RELEASE_WRITE_TOKEN" \
|
|
||||||
-d "$RELEASE_DATA")
|
|
||||||
|
|
||||||
echo "Release API response: $RELEASE_RESPONSE"
|
# Configure git identity if not set (for CI environments)
|
||||||
|
if ! git config user.email >/dev/null 2>&1; then
|
||||||
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
git config user.email "ci@gitea.jde.nz"
|
||||||
|
git config user.name "CI Bot"
|
||||||
if [ -z "$RELEASE_ID" ]; then
|
|
||||||
echo "Failed to create release on Gitea." >&2
|
|
||||||
echo "API URL: $API_URL/releases" >&2
|
|
||||||
echo "Release data: $RELEASE_DATA" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Created release with ID: $RELEASE_ID"
|
# Check if tag already exists locally
|
||||||
|
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||||
|
echo "Tag $TAG already exists locally, deleting it first..."
|
||||||
|
git tag -d "$TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if tag exists on remote
|
||||||
|
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
|
||||||
|
echo "Tag $TAG already exists on remote - this is expected for multi-architecture builds"
|
||||||
|
echo "Skipping tag creation and proceeding with release attachment..."
|
||||||
|
else
|
||||||
|
echo "Creating new tag $TAG..."
|
||||||
|
git tag -a "$TAG" -m "Release $TAG"
|
||||||
|
if ! git push origin "$TAG"; then
|
||||||
|
echo "Failed to push tag $TAG to origin" >&2
|
||||||
|
# Try to delete local tag if push failed
|
||||||
|
git tag -d "$TAG"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Successfully created and pushed tag $TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Getting or creating release $TAG on Gitea..."
|
||||||
|
|
||||||
|
# First try to get existing release
|
||||||
|
EXISTING_RELEASE=$(curl -s -X GET "$API_URL/releases/tags/$TAG" \
|
||||||
|
-H "Authorization: token $RELEASE_WRITE_TOKEN")
|
||||||
|
|
||||||
|
if echo "$EXISTING_RELEASE" | grep -q '"id":[0-9]*'; then
|
||||||
|
# Release already exists, get its ID
|
||||||
|
RELEASE_ID=$(echo "$EXISTING_RELEASE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
echo "Release $TAG already exists with ID: $RELEASE_ID"
|
||||||
|
else
|
||||||
|
# Create new release
|
||||||
|
echo "Creating new release $TAG on Gitea..."
|
||||||
|
RELEASE_RESPONSE=$(curl -s -X POST "$API_URL/releases" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token $RELEASE_WRITE_TOKEN" \
|
||||||
|
-d "$RELEASE_DATA")
|
||||||
|
|
||||||
|
echo "Release API response: $RELEASE_RESPONSE"
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
|
||||||
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Failed to create release on Gitea." >&2
|
||||||
|
echo "API URL: $API_URL/releases" >&2
|
||||||
|
echo "Release data: $RELEASE_DATA" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Created new release with ID: $RELEASE_ID"
|
||||||
|
fi
|
||||||
|
|
||||||
# Upload binaries and install.sh
|
# Upload binaries and install.sh
|
||||||
echo "Uploading assets to release..."
|
echo "Uploading assets to release..."
|
||||||
@ -125,7 +160,7 @@ for FILE in ${PROJECT}.${ARCH_ALIAS} ${PROJECT}.${ARCH} install.sh; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Published bb64 version $v to $REPO_URL (tag $TAG) with binaries for $ARCH_ALIAS / $ARCH."
|
echo "Published bb64 version $VERSION to $REPO_URL (tag $TAG) with binaries for $ARCH_ALIAS / $ARCH."
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include "version.h"
|
#include "version.hpp"
|
||||||
#include "b64ed.hpp"
|
#include "b64ed.hpp"
|
||||||
|
|
||||||
// Recursively decode and print if nested bb64 command is found
|
// Recursively decode and print if nested bb64 command is found
|
||||||
@ -150,6 +150,7 @@ Usage:
|
|||||||
bb64 -u Updates bb64 to the latest version (uses docker)
|
bb64 -u Updates bb64 to the latest version (uses docker)
|
||||||
|
|
||||||
bb64 -v Prints the version number
|
bb64 -v Prints the version number
|
||||||
|
bb64 version Prints the version number
|
||||||
|
|
||||||
)" << std::endl;
|
)" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
@ -161,7 +162,7 @@ Usage:
|
|||||||
{
|
{
|
||||||
if (mode == "-u")
|
if (mode == "-u")
|
||||||
return update_bb64();
|
return update_bb64();
|
||||||
else if (mode == "-v")
|
else if (mode == "-v" || mode == "version")
|
||||||
{
|
{
|
||||||
std::cout << VERSION << std::endl;
|
std::cout << VERSION << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1 +0,0 @@
|
|||||||
static const char *VERSION = "39";
|
|
1
bb64/src/version.hpp.in
Normal file
1
bb64/src/version.hpp.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
static const char *VERSION = "@PROJECT_VERSION@";
|
135
bb64/test.sh
Executable file
135
bb64/test.sh
Executable file
@ -0,0 +1,135 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
PROJECT="bb64"
|
||||||
|
BB64="$SCRIPT_DIR/output/$PROJECT"
|
||||||
|
TEST_DIR="$SCRIPT_DIR/test_temp"
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Test counters
|
||||||
|
TESTS_PASSED=0
|
||||||
|
TESTS_FAILED=0
|
||||||
|
|
||||||
|
# Function to print test results
|
||||||
|
print_test_result() {
|
||||||
|
local test_name="$1"
|
||||||
|
local result="$2"
|
||||||
|
if [ "$result" -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}✓${NC} $test_name"
|
||||||
|
TESTS_PASSED=$((TESTS_PASSED + 1))
|
||||||
|
else
|
||||||
|
echo -e "${RED}✗${NC} $test_name"
|
||||||
|
TESTS_FAILED=$((TESTS_FAILED + 1))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to cleanup test artifacts
|
||||||
|
cleanup() {
|
||||||
|
echo -e "\n${YELLOW}Cleaning up test artifacts...${NC}"
|
||||||
|
rm -rf "$TEST_DIR"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up trap to ensure cleanup runs
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
# Create test directory
|
||||||
|
mkdir -p "$TEST_DIR"
|
||||||
|
|
||||||
|
echo -e "${YELLOW}Running bb64 tests...${NC}\n"
|
||||||
|
|
||||||
|
# Check if bb64 binary exists
|
||||||
|
if [ ! -f "$BB64" ]; then
|
||||||
|
echo -e "${RED}Error: bb64 binary not found at $BB64${NC}"
|
||||||
|
echo "Please run ./build.sh first to build bb64"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$BB64" ]; then
|
||||||
|
echo -e "${RED}Error: bb64 binary is not executable${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Using bb64 binary: $BB64"
|
||||||
|
|
||||||
|
# Test 1: Version command with -v flag
|
||||||
|
echo "Test 1: Version command (-v flag)"
|
||||||
|
VERSION_OUTPUT=$("$BB64" -v 2>&1 || true)
|
||||||
|
# Version output should be just the version number
|
||||||
|
VERSION=$(echo "$VERSION_OUTPUT" | head -n 1)
|
||||||
|
if [[ "$VERSION" =~ ^[0-9]{4}\.[0-9]{4}\.[0-9]{4}$ ]]; then
|
||||||
|
print_test_result "Version format with -v flag (YYYY.MMDD.HHMM)" 0
|
||||||
|
else
|
||||||
|
print_test_result "Version format with -v flag (YYYY.MMDD.HHMM)" 1
|
||||||
|
echo " Expected: YYYY.MMDD.HHMM format, got: '$VERSION'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test 2: Version command with 'version' argument
|
||||||
|
printf "\nTest 2: Version command (version argument)\n"
|
||||||
|
VERSION_OUTPUT2=$("$BB64" version 2>&1 || true)
|
||||||
|
# Version output should be just the version number
|
||||||
|
VERSION2=$(echo "$VERSION_OUTPUT2" | head -n 1)
|
||||||
|
if [[ "$VERSION2" =~ ^[0-9]{4}\.[0-9]{4}\.[0-9]{4}$ ]]; then
|
||||||
|
print_test_result "Version format with 'version' argument (YYYY.MMDD.HHMM)" 0
|
||||||
|
else
|
||||||
|
print_test_result "Version format with 'version' argument (YYYY.MMDD.HHMM)" 1
|
||||||
|
echo " Expected: YYYY.MMDD.HHMM format, got: '$VERSION2'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test 3: Both version commands should return the same version
|
||||||
|
printf "\nTest 3: Version consistency\n"
|
||||||
|
if [ "$VERSION" = "$VERSION2" ]; then
|
||||||
|
print_test_result "Both -v and version return same version" 0
|
||||||
|
else
|
||||||
|
print_test_result "Both -v and version return same version" 1
|
||||||
|
echo " -v returned: '$VERSION'"
|
||||||
|
echo " version returned: '$VERSION2'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test 4: Basic encoding test
|
||||||
|
echo -e "\nTest 4: Basic encoding test"
|
||||||
|
TEST_STRING="hello world"
|
||||||
|
ENCODED_OUTPUT=$("$BB64" -e <<< "$TEST_STRING" 2>&1 || true)
|
||||||
|
if [ -n "$ENCODED_OUTPUT" ]; then
|
||||||
|
print_test_result "Basic encoding produces output" 0
|
||||||
|
else
|
||||||
|
print_test_result "Basic encoding produces output" 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test 5: Basic decoding test (using -d flag)
|
||||||
|
echo -e "\nTest 5: Basic decoding test"
|
||||||
|
# Encode "echo hello" and then decode it
|
||||||
|
ENCODED_ECHO=$(echo "echo hello" | "$BB64" -e)
|
||||||
|
if [ -n "$ENCODED_ECHO" ]; then
|
||||||
|
DECODED_OUTPUT=$("$BB64" -d "$ENCODED_ECHO" 2>&1 || true)
|
||||||
|
if [[ "$DECODED_OUTPUT" == *"echo hello"* ]]; then
|
||||||
|
print_test_result "Basic decoding works correctly" 0
|
||||||
|
else
|
||||||
|
print_test_result "Basic decoding works correctly" 1
|
||||||
|
echo " Expected to contain 'echo hello', got: '$DECODED_OUTPUT'"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_test_result "Basic decoding works correctly" 1
|
||||||
|
echo " Failed to encode test string"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
# Print summary
|
||||||
|
echo -e "\n${YELLOW}Test Summary:${NC}"
|
||||||
|
echo -e "Tests passed: ${GREEN}${TESTS_PASSED}${NC}"
|
||||||
|
echo -e "Tests failed: ${RED}${TESTS_FAILED}${NC}"
|
||||||
|
|
||||||
|
if [ "$TESTS_FAILED" -eq 0 ]; then
|
||||||
|
echo -e "\n${GREEN}All tests passed!${NC}"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo -e "\n${RED}Some tests failed!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
@ -2,6 +2,15 @@
|
|||||||
set -uo pipefail # Remove -e to handle errors manually
|
set -uo pipefail # Remove -e to handle errors manually
|
||||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
|
docker builder prune -f
|
||||||
|
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
# Arrays to track results
|
# Arrays to track results
|
||||||
declare -A BUILD_RESULTS
|
declare -A BUILD_RESULTS
|
||||||
declare -A TEST_RESULTS
|
declare -A TEST_RESULTS
|
||||||
@ -106,13 +115,35 @@ function buildtestpublish() {
|
|||||||
cd "$dir" || echo "Failed to cd to $dir"
|
cd "$dir" || echo "Failed to cd to $dir"
|
||||||
|
|
||||||
subtitle "🔨 BUILDING $TOOLNAME_UPPER 🔨"
|
subtitle "🔨 BUILDING $TOOLNAME_UPPER 🔨"
|
||||||
dothis build "$dir" "$TOOLNAME"
|
if dothis build "$dir" "$TOOLNAME"; then
|
||||||
|
BUILD_SUCCESS=true
|
||||||
|
else
|
||||||
|
BUILD_SUCCESS=false
|
||||||
|
fi
|
||||||
|
|
||||||
subtitle "🔍 TESTING $TOOLNAME_UPPER 🔍"
|
subtitle "🔍 TESTING $TOOLNAME_UPPER 🔍"
|
||||||
dothis test "$dir" "$TOOLNAME"
|
if [ "$BUILD_SUCCESS" = true ]; then
|
||||||
|
if dothis test "$dir" "$TOOLNAME"; then
|
||||||
|
TEST_SUCCESS=true
|
||||||
|
else
|
||||||
|
TEST_SUCCESS=false
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Skipping tests - build failed"
|
||||||
|
TEST_RESULTS["$TOOLNAME"]="SKIP"
|
||||||
|
TEST_SUCCESS=false
|
||||||
|
fi
|
||||||
|
|
||||||
subtitle "📦 PUBLISHING $TOOLNAME_UPPER 📦"
|
subtitle "📦 PUBLISHING $TOOLNAME_UPPER 📦"
|
||||||
dothis publish "$dir" "$TOOLNAME"
|
if [ "$BUILD_SUCCESS" = true ] && [ "$TEST_SUCCESS" = true ]; then
|
||||||
|
dothis publish "$dir" "$TOOLNAME"
|
||||||
|
elif [ "$BUILD_SUCCESS" = true ] && [ "${TEST_RESULTS[$TOOLNAME]}" = "SKIP" ]; then
|
||||||
|
# If tests are skipped (no test script), allow publish if build succeeded
|
||||||
|
dothis publish "$dir" "$TOOLNAME"
|
||||||
|
else
|
||||||
|
echo "Skipping publish - build or tests failed"
|
||||||
|
PUBLISH_RESULTS["$TOOLNAME"]="SKIP"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Done"
|
echo "Done"
|
||||||
}
|
}
|
||||||
@ -166,9 +197,36 @@ function print_summary() {
|
|||||||
local test_status="${TEST_RESULTS[$project]:-'-'}"
|
local test_status="${TEST_RESULTS[$project]:-'-'}"
|
||||||
local publish_status="${PUBLISH_RESULTS[$project]:-'-'}"
|
local publish_status="${PUBLISH_RESULTS[$project]:-'-'}"
|
||||||
|
|
||||||
printf "│ %-*s │ %-7s │ %-7s │ %-7s │\n" \
|
# Format status with proper spacing and colors for Unicode characters
|
||||||
|
local build_col test_col publish_col
|
||||||
|
|
||||||
|
# Format build status with colors
|
||||||
|
case "$build_status" in
|
||||||
|
"✓") build_col=$(printf " %s✓%s " "$GREEN" "$NC") ;;
|
||||||
|
"✗") build_col=$(printf " %s✗%s " "$RED" "$NC") ;;
|
||||||
|
"SKIP") build_col=$(printf " %s-%s " "$YELLOW" "$NC") ;;
|
||||||
|
*) build_col=" - " ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Format test status with colors
|
||||||
|
case "$test_status" in
|
||||||
|
"✓") test_col=$(printf " %s✓%s " "$GREEN" "$NC") ;;
|
||||||
|
"✗") test_col=$(printf " %s✗%s " "$RED" "$NC") ;;
|
||||||
|
"SKIP") test_col=$(printf " %s-%s " "$YELLOW" "$NC") ;;
|
||||||
|
*) test_col=" - " ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Format publish status with colors
|
||||||
|
case "$publish_status" in
|
||||||
|
"✓") publish_col=$(printf " %s✓%s " "$GREEN" "$NC") ;;
|
||||||
|
"✗") publish_col=$(printf " %s✗%s " "$RED" "$NC") ;;
|
||||||
|
"SKIP") publish_col=$(printf " %s-%s " "$YELLOW" "$NC") ;;
|
||||||
|
*) publish_col=" - " ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
printf "│ %-*s │%b│%b│%b│\n" \
|
||||||
$max_project_width "$project" \
|
$max_project_width "$project" \
|
||||||
"$build_status" "$test_status" "$publish_status"
|
"$build_col" "$test_col" "$publish_col"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Print bottom border
|
# Print bottom border
|
||||||
|
@ -17,12 +17,19 @@ Examples:
|
|||||||
dehydrate src/ output/ Creates _src.cpp and _src.hpp in output/
|
dehydrate src/ output/ Creates _src.cpp and _src.hpp in output/
|
||||||
dehydrate -u Updates dehydrate to the latest version
|
dehydrate -u Updates dehydrate to the latest version
|
||||||
dehydrate -v Shows version number
|
dehydrate -v Shows version number
|
||||||
|
dehydrate version Shows version number
|
||||||
)";
|
)";
|
||||||
|
|
||||||
Args parse_args(int argc, char* argv[]) {
|
Args parse_args(int argc, char* argv[]) {
|
||||||
Args args;
|
Args args;
|
||||||
int idx = 1;
|
int idx = 1;
|
||||||
|
|
||||||
|
// Check for "version" as first argument (no dash)
|
||||||
|
if (argc > 1 && std::string(argv[1]) == "version") {
|
||||||
|
args.version = true;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse flags
|
// Parse flags
|
||||||
while (idx < argc && argv[idx][0] == '-') {
|
while (idx < argc && argv[idx][0] == '-') {
|
||||||
std::string flag = argv[idx];
|
std::string flag = argv[idx];
|
||||||
|
@ -16,39 +16,48 @@ rm -f dehydrate_test
|
|||||||
|
|
||||||
# Build the test program using Docker
|
# Build the test program using Docker
|
||||||
# The Docker container supports both amd64 and arm64 architectures
|
# The Docker container supports both amd64 and arm64 architectures
|
||||||
docker run --rm \
|
echo "Building dehydrate test executable..."
|
||||||
-v "$PROJECT_DIR":/workdir \
|
|
||||||
-w /workdir/test \
|
# Use docker cp approach since volume mounting may not work in CI
|
||||||
|
CONTAINER_NAME="dehydrate-test-build-$$"
|
||||||
|
|
||||||
|
# Start container in detached mode
|
||||||
|
docker run -d --name "$CONTAINER_NAME" \
|
||||||
gitea.jde.nz/public/dropshell-build-base:latest \
|
gitea.jde.nz/public/dropshell-build-base:latest \
|
||||||
bash -c "
|
sleep 60
|
||||||
# Verify we can find the source file
|
|
||||||
if [ ! -f dehydrate_test.cpp ]; then
|
# Copy source file into container
|
||||||
echo 'ERROR: dehydrate_test.cpp not found in current directory'
|
docker cp dehydrate_test.cpp "$CONTAINER_NAME":/dehydrate_test.cpp
|
||||||
echo 'Working directory:' && pwd
|
|
||||||
echo 'Available files:' && ls -la
|
# Compile in container
|
||||||
exit 1
|
docker exec "$CONTAINER_NAME" bash -c "
|
||||||
fi
|
echo 'Compiling dehydrate test...'
|
||||||
|
if ! g++ -std=c++23 -static /dehydrate_test.cpp -o /dehydrate_test; then
|
||||||
# Clean any existing binary and compile
|
echo 'ERROR: Compilation failed'
|
||||||
rm -f dehydrate_test
|
exit 1
|
||||||
if ! g++ -std=c++23 -static dehydrate_test.cpp -o dehydrate_test; then
|
fi
|
||||||
echo 'ERROR: Compilation failed'
|
|
||||||
exit 1
|
# Verify binary was created
|
||||||
fi
|
if [ ! -f /dehydrate_test ]; then
|
||||||
|
echo 'ERROR: Binary was not created'
|
||||||
# Verify binary was created and is executable
|
exit 1
|
||||||
if [ ! -f dehydrate_test ]; then
|
fi
|
||||||
echo 'ERROR: Binary was not created'
|
|
||||||
exit 1
|
# Quick architecture check
|
||||||
fi
|
if ! file /dehydrate_test | grep -q 'executable'; then
|
||||||
|
echo 'ERROR: Generated file is not an executable'
|
||||||
# Quick architecture check - just verify the binary format
|
file /dehydrate_test
|
||||||
if ! file dehydrate_test | grep -q 'executable'; then
|
exit 1
|
||||||
echo 'ERROR: Generated file is not an executable'
|
fi
|
||||||
file dehydrate_test
|
|
||||||
exit 1
|
echo 'Compilation successful'
|
||||||
fi
|
"
|
||||||
"
|
|
||||||
|
# Copy binary back to host
|
||||||
|
docker cp "$CONTAINER_NAME":/dehydrate_test ./dehydrate_test
|
||||||
|
|
||||||
|
# Clean up container
|
||||||
|
docker rm -f "$CONTAINER_NAME"
|
||||||
|
|
||||||
# Check if compilation succeeded
|
# Check if compilation succeeded
|
||||||
if [ ! -f "./dehydrate_test" ]; then
|
if [ ! -f "./dehydrate_test" ]; then
|
||||||
|
@ -326,75 +326,163 @@ int update_tool(int argc, char* argv[]) {
|
|||||||
std::string home = get_home();
|
std::string home = get_home();
|
||||||
std::filesystem::path configDir = std::filesystem::path(home) / ".config/getpkg";
|
std::filesystem::path configDir = std::filesystem::path(home) / ".config/getpkg";
|
||||||
|
|
||||||
// Collect all installed tools
|
// Structure to hold tool information
|
||||||
std::vector<std::tuple<std::string, std::string, std::string>> updateResults; // name, status, version
|
struct ToolInfo {
|
||||||
|
std::string name;
|
||||||
// Capture stdout to process install_tool output
|
std::string localHash;
|
||||||
auto processToolUpdate = [&](const std::string& toolName) -> std::tuple<std::string, std::string> {
|
std::string remoteHash;
|
||||||
// Redirect stdout and stderr to capture output
|
std::string arch;
|
||||||
std::stringstream buffer;
|
std::string version;
|
||||||
std::stringstream errBuffer;
|
bool needsUpdate = false;
|
||||||
std::streambuf* oldOut = std::cout.rdbuf(buffer.rdbuf());
|
std::string status = "Up to date";
|
||||||
std::streambuf* oldErr = std::cerr.rdbuf(errBuffer.rdbuf());
|
|
||||||
|
|
||||||
char* toolArgv[] = {argv[0], (char*)"install", (char*)toolName.c_str()};
|
|
||||||
int result = install_tool(3, toolArgv);
|
|
||||||
|
|
||||||
// Restore stdout and stderr
|
|
||||||
std::cout.rdbuf(oldOut);
|
|
||||||
std::cerr.rdbuf(oldErr);
|
|
||||||
|
|
||||||
std::string output = buffer.str();
|
|
||||||
std::string status = "Failed";
|
|
||||||
std::string version = "-";
|
|
||||||
|
|
||||||
if (result == 0) {
|
|
||||||
if (output.find("is already up to date") != std::string::npos) {
|
|
||||||
status = "Up to date";
|
|
||||||
} else if (output.find("Installed " + toolName + " successfully") != std::string::npos) {
|
|
||||||
// Check if it was an update or fresh install
|
|
||||||
if (output.find("Updating " + toolName) != std::string::npos) {
|
|
||||||
status = "Updated";
|
|
||||||
} else {
|
|
||||||
status = "Installed";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get version from config
|
|
||||||
std::filesystem::path toolInfoPath = configDir / (toolName + ".json");
|
|
||||||
if (std::filesystem::exists(toolInfoPath)) {
|
|
||||||
std::ifstream tfile(toolInfoPath);
|
|
||||||
json toolInfo;
|
|
||||||
tfile >> toolInfo;
|
|
||||||
version = toolInfo.value("version", "-");
|
|
||||||
if (!version.empty() && version.back() == '\n') version.pop_back();
|
|
||||||
// If version is empty, try to show something useful
|
|
||||||
if (version.empty() || version == "-") {
|
|
||||||
version = "installed";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_tuple(status, version);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// First update getpkg itself
|
std::vector<ToolInfo> tools;
|
||||||
auto [getpkgStatus, getpkgVersion] = processToolUpdate("getpkg");
|
|
||||||
updateResults.push_back(std::make_tuple("getpkg", getpkgStatus, getpkgVersion));
|
|
||||||
|
|
||||||
// Then update all other installed tools
|
// Collect all installed tools
|
||||||
if (std::filesystem::exists(configDir)) {
|
if (std::filesystem::exists(configDir)) {
|
||||||
for (const auto& entry : std::filesystem::directory_iterator(configDir)) {
|
for (const auto& entry : std::filesystem::directory_iterator(configDir)) {
|
||||||
if (entry.path().extension() == ".json") {
|
if (entry.path().extension() == ".json") {
|
||||||
std::string tname = entry.path().stem();
|
std::string tname = entry.path().stem();
|
||||||
if (tname != "getpkg") { // Skip getpkg since we already did it
|
|
||||||
auto [status, version] = processToolUpdate(tname);
|
ToolInfo tool;
|
||||||
updateResults.push_back(std::make_tuple(tname, status, version));
|
tool.name = tname;
|
||||||
|
|
||||||
|
// Read local tool info
|
||||||
|
std::ifstream tfile(entry.path());
|
||||||
|
if (tfile.good()) {
|
||||||
|
json toolInfo;
|
||||||
|
tfile >> toolInfo;
|
||||||
|
tool.localHash = toolInfo.value("hash", "");
|
||||||
|
tool.arch = toolInfo.value("arch", get_arch());
|
||||||
|
tool.version = toolInfo.value("version", "-");
|
||||||
|
if (!tool.version.empty() && tool.version.back() == '\n') {
|
||||||
|
tool.version.pop_back();
|
||||||
|
}
|
||||||
|
if (tool.version.empty() || tool.version == "-") {
|
||||||
|
tool.version = "installed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tools.push_back(tool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tools.empty()) {
|
||||||
|
std::cout << "No tools installed." << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 1: Check for updates (with progress)
|
||||||
|
std::cout << "Checking " << tools.size() << " tools for updates..." << std::endl;
|
||||||
|
|
||||||
|
GetbinClient getbin;
|
||||||
|
for (size_t i = 0; i < tools.size(); ++i) {
|
||||||
|
auto& tool = tools[i];
|
||||||
|
|
||||||
|
// Show progress
|
||||||
|
std::cout << "\r[" << (i + 1) << "/" << tools.size() << "] Checking " << tool.name << "..." << std::flush;
|
||||||
|
|
||||||
|
// Check remote hash
|
||||||
|
std::string remoteHash;
|
||||||
|
if (getbin.getHash(tool.name, tool.arch, remoteHash) && !remoteHash.empty()) {
|
||||||
|
tool.remoteHash = remoteHash;
|
||||||
|
if (tool.localHash != remoteHash) {
|
||||||
|
tool.needsUpdate = true;
|
||||||
|
tool.status = "Needs update";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tool.status = "Check failed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "\r" << std::string(50, ' ') << "\r" << std::flush; // Clear progress line
|
||||||
|
|
||||||
|
// Step 2: Update tools that need updating
|
||||||
|
std::vector<std::tuple<std::string, std::string, std::string>> updateResults;
|
||||||
|
|
||||||
|
// First update getpkg if it needs updating
|
||||||
|
auto getpkgIt = std::find_if(tools.begin(), tools.end(),
|
||||||
|
[](const ToolInfo& t) { return t.name == "getpkg"; });
|
||||||
|
|
||||||
|
if (getpkgIt != tools.end() && getpkgIt->needsUpdate) {
|
||||||
|
std::cout << "Updating getpkg..." << std::flush;
|
||||||
|
|
||||||
|
// Use install_tool for actual update
|
||||||
|
std::stringstream buffer, errBuffer;
|
||||||
|
std::streambuf* oldOut = std::cout.rdbuf(buffer.rdbuf());
|
||||||
|
std::streambuf* oldErr = std::cerr.rdbuf(errBuffer.rdbuf());
|
||||||
|
|
||||||
|
char* toolArgv[] = {argv[0], (char*)"install", (char*)"getpkg"};
|
||||||
|
int result = install_tool(3, toolArgv);
|
||||||
|
|
||||||
|
std::cout.rdbuf(oldOut);
|
||||||
|
std::cerr.rdbuf(oldErr);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
getpkgIt->status = "Updated";
|
||||||
|
std::cout << " Updated" << std::endl;
|
||||||
|
} else {
|
||||||
|
getpkgIt->status = "Failed";
|
||||||
|
std::cout << " Failed" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update other tools
|
||||||
|
int toolsToUpdate = std::count_if(tools.begin(), tools.end(),
|
||||||
|
[](const ToolInfo& t) { return t.needsUpdate && t.name != "getpkg"; });
|
||||||
|
|
||||||
|
if (toolsToUpdate > 0) {
|
||||||
|
std::cout << "Updating " << toolsToUpdate << " tools..." << std::endl;
|
||||||
|
|
||||||
|
int updatedCount = 0;
|
||||||
|
for (auto& tool : tools) {
|
||||||
|
if (tool.needsUpdate && tool.name != "getpkg") {
|
||||||
|
updatedCount++;
|
||||||
|
std::cout << "[" << updatedCount << "/" << toolsToUpdate << "] Updating " << tool.name << "..." << std::flush;
|
||||||
|
|
||||||
|
// Use install_tool for actual update
|
||||||
|
std::stringstream buffer, errBuffer;
|
||||||
|
std::streambuf* oldOut = std::cout.rdbuf(buffer.rdbuf());
|
||||||
|
std::streambuf* oldErr = std::cerr.rdbuf(errBuffer.rdbuf());
|
||||||
|
|
||||||
|
char* toolArgv[] = {argv[0], (char*)"install", (char*)tool.name.c_str()};
|
||||||
|
int result = install_tool(3, toolArgv);
|
||||||
|
|
||||||
|
std::cout.rdbuf(oldOut);
|
||||||
|
std::cerr.rdbuf(oldErr);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
tool.status = "Updated";
|
||||||
|
std::cout << " Updated" << std::endl;
|
||||||
|
|
||||||
|
// Re-read version after update
|
||||||
|
std::filesystem::path toolInfoPath = configDir / (tool.name + ".json");
|
||||||
|
if (std::filesystem::exists(toolInfoPath)) {
|
||||||
|
std::ifstream tfile(toolInfoPath);
|
||||||
|
json toolInfo;
|
||||||
|
tfile >> toolInfo;
|
||||||
|
tool.version = toolInfo.value("version", tool.version);
|
||||||
|
if (!tool.version.empty() && tool.version.back() == '\n') {
|
||||||
|
tool.version.pop_back();
|
||||||
|
}
|
||||||
|
if (tool.version.empty() || tool.version == "-") {
|
||||||
|
tool.version = "installed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tool.status = "Failed";
|
||||||
|
std::cout << " Failed" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare results for display
|
||||||
|
for (const auto& tool : tools) {
|
||||||
|
updateResults.push_back(std::make_tuple(tool.name, tool.status, tool.version));
|
||||||
|
}
|
||||||
|
|
||||||
// Display results in a table
|
// Display results in a table
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "+" << std::string(25, '-') << "+" << std::string(15, '-') << "+" << std::string(20, '-') << "+" << std::endl;
|
std::cout << "+" << std::string(25, '-') << "+" << std::string(15, '-') << "+" << std::string(20, '-') << "+" << std::endl;
|
||||||
|
Reference in New Issue
Block a user