Compare commits
8 Commits
2025.0526.
...
2025.0527.
Author | SHA1 | Date | |
---|---|---|---|
c836b26657 | |||
7bf624589f | |||
a5e339a358 | |||
029823a6b4 | |||
f79abd346e | |||
940c2a12a1 | |||
6ac651d4f0 | |||
84fd96e74e |
@ -1,4 +1,6 @@
|
|||||||
# can you make this script run in bash, but fall back to sh if bash is not installed?
|
#!/bin/bash
|
||||||
|
|
||||||
|
# set up a remote server for use with dropshell.
|
||||||
|
|
||||||
# check if we are running as root
|
# check if we are running as root
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
@ -46,17 +46,16 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|||||||
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
file(GLOB_RECURSE HEADERS "src/*.hpp")
|
file(GLOB_RECURSE HEADERS "src/*.hpp")
|
||||||
|
|
||||||
# Add custom target to run make_createagent.sh at the start of the build process
|
# Add custom target to run cmake_prebuild.sh at the start of the build process
|
||||||
add_custom_target(run_createagent ALL
|
add_custom_target(run_prebuild_script ALL
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "Running make_createagent.sh..."
|
COMMAND ${CMAKE_COMMAND} -E echo "Running cmake_prebuild.sh..."
|
||||||
COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_CURRENT_SOURCE_DIR}/make_createagent.sh
|
COMMAND ${CMAKE_COMMAND} -E env bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake_prebuild.sh
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
COMMENT "Running make_createagent.sh before build"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add executable
|
# Add executable
|
||||||
add_executable(dropshell ${SOURCES})
|
add_executable(dropshell ${SOURCES})
|
||||||
add_dependencies(dropshell run_createagent)
|
add_dependencies(dropshell run_prebuild_script)
|
||||||
|
|
||||||
# Mark the generated files as GENERATED so CMake knows they'll be created during build
|
# Mark the generated files as GENERATED so CMake knows they'll be created during build
|
||||||
set_source_files_properties(
|
set_source_files_properties(
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# install the dropshell host agent on this computer.
|
||||||
|
# (not for remote servers)
|
||||||
|
|
||||||
SCRIPT_DIR=$(dirname "$0")
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
|
|
||||||
echo "Installing dropshell host agent on this computer..."
|
echo "Installing dropshell host agent on this computer..."
|
||||||
@ -22,27 +25,6 @@ _check_required_env_vars() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks if Docker is installed, running, and user has permission. Returns 1 on failure.
|
|
||||||
_check_docker_installed() {
|
|
||||||
if ! command -v docker &> /dev/null; then
|
|
||||||
echo "Docker is not installed"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check if docker daemon is running
|
|
||||||
if ! docker info &> /dev/null; then
|
|
||||||
echo "Docker daemon is not running"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check if user has permission to run docker
|
|
||||||
if ! docker run --rm hello-world &> /dev/null; then
|
|
||||||
echo "User does not have permission to run docker"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function install_bb64() {
|
function install_bb64() {
|
||||||
# check curl installed
|
# check curl installed
|
||||||
@ -77,7 +59,5 @@ set +a
|
|||||||
_check_required_env_vars "AGENT_LOCAL_PATH"
|
_check_required_env_vars "AGENT_LOCAL_PATH"
|
||||||
echo "Installing host agent into $AGENT_LOCAL_PATH"
|
echo "Installing host agent into $AGENT_LOCAL_PATH"
|
||||||
|
|
||||||
_check_docker_installed || _die "Docker is required."
|
|
||||||
|
|
||||||
install_bb64
|
install_bb64
|
||||||
|
|
||||||
|
@ -53,6 +53,12 @@ if ! command -v docker &> /dev/null; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check rsync installation
|
||||||
|
if ! command -v rsync &> /dev/null; then
|
||||||
|
echo "Rsync is not installed. Rsync is required for agent installation."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1,86 +1,45 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
OUTPUT_DIR=${SCRIPT_DIR}/output
|
||||||
|
INSTALL_DIR=${HOME}/.local/bin
|
||||||
|
mkdir -p ${OUTPUT_DIR}
|
||||||
|
|
||||||
# Exit on error
|
# Exit on error
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Colors for output
|
function build_native() {
|
||||||
RED='\033[0;31m'
|
local BUILDDIR=${SCRIPT_DIR}/build/native
|
||||||
GREEN='\033[0;32m'
|
local PREVDIR=$PWD
|
||||||
YELLOW='\033[1;33m'
|
local JOBS=$(nproc) # Set JOBS to the number of available CPU cores
|
||||||
NC='\033[0m' # No Color
|
mkdir -p ${BUILDDIR}
|
||||||
|
cd ${SCRIPT_DIR}
|
||||||
|
|
||||||
JOBS=4
|
CC="${HOME}/.musl-cross/x86_64-linux-musl-native/bin/x86_64-linux-musl-gcc"
|
||||||
# Determine number of CPU cores for parallel build
|
CXX="${HOME}/.musl-cross/x86_64-linux-musl-native/bin/x86_64-linux-musl-g++"
|
||||||
if command -v nproc >/dev/null 2>&1; then
|
|
||||||
JOBS=$(nproc)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Function to print status messages
|
|
||||||
print_status() {
|
|
||||||
echo -e "${GREEN}[*] $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_error() {
|
cmake -B ${BUILDDIR} -G Ninja \
|
||||||
echo -e "${RED}[!] $1${NC}"
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
}
|
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
|
||||||
|
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||||
|
-DCMAKE_LINKER=mold \
|
||||||
|
-DCMAKE_C_COMPILER=${CC} \
|
||||||
|
-DCMAKE_CXX_COMPILER=${CXX}
|
||||||
|
|
||||||
print_warning() {
|
cd ${BUILDDIR}
|
||||||
echo -e "${YELLOW}[!] $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ensure we have latest dehydrate.
|
|
||||||
dehydrate -u
|
|
||||||
|
|
||||||
# Check if build directory exists, if not create it
|
|
||||||
if [ ! -d "build" ]; then
|
|
||||||
print_status "Creating build directory..."
|
|
||||||
mkdir build
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Enter build directory
|
|
||||||
cd build
|
|
||||||
|
|
||||||
# Check if CMake is installed
|
|
||||||
if ! command -v cmake &> /dev/null; then
|
|
||||||
print_error "CMake is not installed. Please install CMake first."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if Ninja is installed
|
|
||||||
if ! command -v ninja &> /dev/null; then
|
|
||||||
print_error "Ninja is not installed. Please install Ninja first."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if ccache is installed
|
|
||||||
if ! command -v ccache &> /dev/null; then
|
|
||||||
print_warning "ccache is not installed. Builds will be slower without it."
|
|
||||||
print_warning "Consider installing ccache for faster builds."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configure with CMake
|
|
||||||
print_status "Configuring with CMake..."
|
|
||||||
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
|
|
||||||
|
|
||||||
# Build the project
|
|
||||||
print_status "Building project..."
|
|
||||||
ninja -j"$JOBS"
|
ninja -j"$JOBS"
|
||||||
|
|
||||||
# Check if build was successful
|
#upx ${BUILDDIR}/dropshell
|
||||||
if [ $? -eq 0 ]; then
|
cp ${BUILDDIR}/dropshell ${OUTPUT_DIR}/dropshell.native
|
||||||
print_status "Build successful!"
|
|
||||||
else
|
|
||||||
print_error "Build failed!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_status "Auto-installing dropshell locally..."
|
cd ${PREVDIR}
|
||||||
mkdir -p "${HOME}/.local/bin"
|
}
|
||||||
cp "$SCRIPT_DIR/build/dropshell" "${HOME}/.local/bin/dropshell"
|
|
||||||
|
|
||||||
# Return to original directory
|
build_native
|
||||||
cd ..
|
|
||||||
|
|
||||||
print_status "Build process completed!"
|
echo "Auto-installing dropshell locally..."
|
||||||
|
mkdir -p "${INSTALL_DIR}"
|
||||||
|
cp "${OUTPUT_DIR}/dropshell.native" "${INSTALL_DIR}/dropshell"
|
||||||
|
ds version
|
||||||
|
echo "Build process completed!"
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# CMake pre-build script.
|
||||||
|
# Runs before the build process.
|
||||||
|
|
||||||
# This script creates two files:
|
# This script creates two files:
|
||||||
# src/utils/createagent.hpp
|
# src/utils/createagent.hpp
|
||||||
# src/utils/createagent.cpp
|
# src/utils/createagent.cpp
|
||||||
@ -11,9 +14,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
if ! command -v dehydrate &> /dev/null; then
|
if ! command -v dehydrate &> /dev/null; then
|
||||||
echo "dehydrate could not be found - installing"
|
echo "dehydrate could not be found - installing"
|
||||||
curl -fsSL https://gitea.jde.nz/public/dehydrate/releases/download/latest/install.sh | bash
|
curl -fsSL https://gitea.jde.nz/public/dehydrate/releases/download/latest/install.sh | bash
|
||||||
|
else
|
||||||
|
# ensure we have latest dehydrate.
|
||||||
|
dehydrate -u
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "${SCRIPT_DIR}/src/autogen"
|
mkdir -p "${SCRIPT_DIR}/src/autogen"
|
||||||
|
|
||||||
dehydrate "${SCRIPT_DIR}/agent-remote" "${SCRIPT_DIR}/src/autogen"
|
dehydrate "${SCRIPT_DIR}/agent-remote" "${SCRIPT_DIR}/src/autogen"
|
||||||
dehydrate "${SCRIPT_DIR}/agent-local" "${SCRIPT_DIR}/src/autogen"
|
dehydrate "${SCRIPT_DIR}/agent-local" "${SCRIPT_DIR}/src/autogen"
|
@ -37,11 +37,16 @@ fi
|
|||||||
|
|
||||||
print_status "Detected OS: $OS $VER"
|
print_status "Detected OS: $OS $VER"
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------
|
||||||
|
# INSTALL PREREQUISITE PACKAGES
|
||||||
|
#----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Define packages based on distribution
|
# Define packages based on distribution
|
||||||
case $OS in
|
case $OS in
|
||||||
"Ubuntu"|"Debian GNU/Linux")
|
"Ubuntu"|"Debian GNU/Linux")
|
||||||
# Common packages for both Ubuntu and Debian
|
# Common packages for both Ubuntu and Debian
|
||||||
PACKAGES="cmake make g++ devscripts debhelper build-essential upx"
|
PACKAGES="cmake make g++ devscripts debhelper build-essential upx musl-tools wget tar ccache ninja-build"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print_error "Unsupported distribution: $OS"
|
print_error "Unsupported distribution: $OS"
|
||||||
@ -73,19 +78,9 @@ for pkg in $PACKAGES; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Verify all required tools are installed
|
# ----------------------------------------------------------------------------------------------------------
|
||||||
print_status "Verifying installation..."
|
# MUSL CROSS COMPILERS
|
||||||
for tool in cmake make g++; do
|
# ----------------------------------------------------------------------------------------------------------
|
||||||
if ! command -v "$tool" &> /dev/null; then
|
|
||||||
print_error "$tool is not installed properly"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Install other required packages
|
|
||||||
apt install -y musl-tools wget tar ccache ninja-build
|
|
||||||
|
|
||||||
# Set install directory
|
# Set install directory
|
||||||
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
|
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
|
||||||
@ -96,59 +91,58 @@ fi
|
|||||||
INSTALL_DIR="$USER_HOME/.musl-cross"
|
INSTALL_DIR="$USER_HOME/.musl-cross"
|
||||||
mkdir -p "$INSTALL_DIR"
|
mkdir -p "$INSTALL_DIR"
|
||||||
|
|
||||||
MUSL_CC_URL="https://musl.cc"
|
|
||||||
TMPDIR=$(mktemp -d)
|
TMPDIR=$(mktemp -d)
|
||||||
trap 'rm -rf "$TMPDIR"' EXIT
|
trap 'rm -rf "$TMPDIR"' EXIT
|
||||||
|
|
||||||
# x86_64
|
function install_musl_cross() {
|
||||||
if [ ! -d "$INSTALL_DIR/x86_64-linux-musl-cross" ]; then
|
local TOOLCHAIN="$1"
|
||||||
echo "Downloading x86_64 musl cross toolchain..."
|
local MUSL_CC_URL="https://musl.cc"
|
||||||
wget -nc -O "$TMPDIR/x86_64-linux-musl-cross.tgz" $MUSL_CC_URL/x86_64-linux-musl-cross.tgz
|
if [ ! -d "$INSTALL_DIR/$TOOLCHAIN" ]; then
|
||||||
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/x86_64-linux-musl-cross.tgz"
|
echo "Downloading $TOOLCHAIN musl cross toolchain..."
|
||||||
|
wget -nc -O "$TMPDIR/$TOOLCHAIN.tgz" $MUSL_CC_URL/$TOOLCHAIN.tgz
|
||||||
|
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/$TOOLCHAIN.tgz"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# aarch64
|
function check_path() {
|
||||||
if [ ! -d "$INSTALL_DIR/aarch64-linux-musl-cross" ]; then
|
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
|
||||||
echo "Downloading aarch64 musl cross toolchain..."
|
local BASHRC="$USER_HOME/.bashrc"
|
||||||
wget -nc -O "$TMPDIR/aarch64-linux-musl-cross.tgz" $MUSL_CC_URL/aarch64-linux-musl-cross.tgz
|
local TOOLCHAIN="$1"
|
||||||
tar -C "$INSTALL_DIR" -xvf "$TMPDIR/aarch64-linux-musl-cross.tgz"
|
local MUSL_PATH="$INSTALL_DIR/$TOOLCHAIN/bin"
|
||||||
|
if ! echo "$PATH" | grep -q "$MUSL_PATH"; then
|
||||||
|
echo "Adding $MUSL_PATH to PATH in $BASHRC"
|
||||||
|
PATH_LINE="export PATH=\"$MUSL_PATH:\$PATH\""
|
||||||
|
if ! grep -Fxq "$PATH_LINE" "$BASHRC"; then
|
||||||
|
echo "" >> "$BASHRC"
|
||||||
|
echo "# Add musl cross compilers to PATH for dropshell" >> "$BASHRC"
|
||||||
|
echo "$PATH_LINE" >> "$BASHRC"
|
||||||
|
echo "Added musl cross compilers to $BASHRC"
|
||||||
|
echo "You should run 'source ~/.bashrc' to update your PATH"
|
||||||
|
else
|
||||||
|
echo "You should run 'source ~/.bashrc' to update your PATH"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Print instructions for adding to PATH
|
|
||||||
# cat <<EOF
|
|
||||||
|
|
||||||
# To use the musl cross compilers, add the following to your shell:
|
TOOLCHAIN_LIST=(
|
||||||
# export PATH="$INSTALL_DIR/x86_64-linux-musl-cross/bin:$INSTALL_DIR/aarch64-linux-musl-cross/bin:$PATH"
|
"aarch64-linux-musl-cross"
|
||||||
|
"x86_64-linux-musl-cross"
|
||||||
|
"x86_64-linux-musl-native"
|
||||||
|
)
|
||||||
|
|
||||||
# Or run:
|
for TOOLCHAIN in "${TOOLCHAIN_LIST[@]}"; do
|
||||||
# export PATH="$INSTALL_DIR/x86_64-linux-musl-cross/bin:$INSTALL_DIR/aarch64-linux-musl-cross/bin:\$PATH"
|
install_musl_cross "$TOOLCHAIN"
|
||||||
|
check_path "$TOOLCHAIN"
|
||||||
# EOF
|
done
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
rm -rf "$TMPDIR"
|
rm -rf "$TMPDIR"
|
||||||
|
|
||||||
# If run with sudo, add to invoking user's ~/.bashrc
|
# ----------------------------------------------------------------------------------------------------------
|
||||||
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
|
# COMPLETE
|
||||||
BASHRC="$USER_HOME/.bashrc"
|
# ----------------------------------------------------------------------------------------------------------
|
||||||
EXPORT_LINE="export PATH=\"$INSTALL_DIR/x86_64-linux-musl-cross/bin:$INSTALL_DIR/aarch64-linux-musl-cross/bin:\$PATH\""
|
|
||||||
if ! grep -Fxq "$EXPORT_LINE" "$BASHRC"; then
|
|
||||||
echo "" >> "$BASHRC"
|
|
||||||
echo "# Add musl cross compilers to PATH for bb64" >> "$BASHRC"
|
|
||||||
echo "$EXPORT_LINE" >> "$BASHRC"
|
|
||||||
echo "Added musl cross compilers to $BASHRC"
|
|
||||||
else
|
|
||||||
echo "musl cross compiler PATH already present in $BASHRC"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check if dehydrate command is installed
|
|
||||||
if ! command -v dehydrate &> /dev/null; then
|
|
||||||
curl -fsSL https://gitea.jde.nz/public/dehydrate/releases/download/latest/install.sh | bash
|
|
||||||
fi
|
|
||||||
|
|
||||||
dehydrate -u
|
|
||||||
|
|
||||||
|
|
||||||
print_status "All dependencies installed successfully!"
|
print_status "All dependencies installed successfully!"
|
||||||
print_status "You can now run ./build.sh to build the project"
|
print_status "You can now run ./build.sh to build the project"
|
@ -1,11 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
|
||||||
# Create output directory
|
# Create output directory
|
||||||
mkdir -p output
|
mkdir -p ${SCRIPT_DIR}/output
|
||||||
|
|
||||||
|
|
||||||
function build_arch() {
|
function build_arch() {
|
||||||
local arch=$1
|
local arch=$1
|
||||||
|
local PREVDIR=$PWD
|
||||||
|
cd ${SCRIPT_DIR}
|
||||||
|
|
||||||
if [ ! -f "${HOME}/.musl-cross/${arch}-linux-musl-cross/bin/${arch}-linux-musl-c++" ]; then
|
if [ ! -f "${HOME}/.musl-cross/${arch}-linux-musl-cross/bin/${arch}-linux-musl-c++" ]; then
|
||||||
echo "Musl cross compiler for ${arch} not found. Please run install_build_prerequisites.sh first."
|
echo "Musl cross compiler for ${arch} not found. Please run install_build_prerequisites.sh first."
|
||||||
@ -16,14 +20,16 @@ function build_arch() {
|
|||||||
CC="${HOME}/.musl-cross/${arch}-linux-musl-cross/bin/${arch}-linux-musl-gcc"
|
CC="${HOME}/.musl-cross/${arch}-linux-musl-cross/bin/${arch}-linux-musl-gcc"
|
||||||
CXX="${HOME}/.musl-cross/${arch}-linux-musl-cross/bin/${arch}-linux-musl-g++"
|
CXX="${HOME}/.musl-cross/${arch}-linux-musl-cross/bin/${arch}-linux-musl-g++"
|
||||||
|
|
||||||
BUILDDIR=build/${arch}
|
BUILDDIR=${SCRIPT_DIR}/build/${arch}
|
||||||
mkdir -p ${BUILDDIR}
|
mkdir -p ${BUILDDIR}
|
||||||
|
|
||||||
cmake -B ${BUILDDIR} -G Ninja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX}
|
cmake -B ${BUILDDIR} -G Ninja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX}
|
||||||
cmake --build ${BUILDDIR}
|
cmake --build ${BUILDDIR}
|
||||||
|
|
||||||
upx ${BUILDDIR}/dropshell
|
upx ${BUILDDIR}/dropshell
|
||||||
cp ${BUILDDIR}/dropshell output/dropshell.${arch}
|
cp ${BUILDDIR}/dropshell ${SCRIPT_DIR}/output/dropshell.${arch}
|
||||||
|
|
||||||
|
cd ${PREVDIR}
|
||||||
}
|
}
|
||||||
|
|
||||||
build_arch x86_64
|
build_arch x86_64
|
||||||
|
@ -6,16 +6,8 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
echo "Script directory: $SCRIPT_DIR"
|
echo "Script directory: $SCRIPT_DIR"
|
||||||
|
|
||||||
# Check for GITEA_TOKEN_DEPLOY or GITEA_TOKEN
|
# Check for GITEA_TOKEN_DEPLOY or GITEA_TOKEN
|
||||||
if [ -n "$GITEA_TOKEN_DEPLOY" ]; then
|
TOKEN="${GITEA_TOKEN_DEPLOY:-${GITEA_TOKEN}}"
|
||||||
TOKEN="$GITEA_TOKEN_DEPLOY"
|
[ -z "$TOKEN" ] && { echo "Neither GITEA_TOKEN_DEPLOY nor GITEA_TOKEN environment variable set!" >&2; exit 1; }
|
||||||
echo "Using GITEA_TOKEN_DEPLOY"
|
|
||||||
elif [ -n "$GITEA_TOKEN" ]; then
|
|
||||||
TOKEN="$GITEA_TOKEN"
|
|
||||||
echo "Using GITEA_TOKEN"
|
|
||||||
else
|
|
||||||
echo "Neither GITEA_TOKEN_DEPLOY nor GITEA_TOKEN environment variable set!" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
$SCRIPT_DIR/multibuild.sh
|
$SCRIPT_DIR/multibuild.sh
|
||||||
BUILD_DIR=$SCRIPT_DIR/build
|
BUILD_DIR=$SCRIPT_DIR/build
|
||||||
@ -23,18 +15,15 @@ BUILD_DIR=$SCRIPT_DIR/build
|
|||||||
OLD_PWD=$PWD
|
OLD_PWD=$PWD
|
||||||
cd $SCRIPT_DIR
|
cd $SCRIPT_DIR
|
||||||
|
|
||||||
|
# Check for required binaries
|
||||||
if [ ! -f "output/dropshell.x86_64" ]; then
|
REQUIRED_BINARIES=("dropshell.x86_64" "dropshell.aarch64")
|
||||||
echo "output/dropshell.x86_64 not found!" >&2
|
for binary in "${REQUIRED_BINARIES[@]}"; do
|
||||||
echo "Please run multibuild.sh first." >&2
|
if [ ! -f "output/$binary" ]; then
|
||||||
exit 1
|
echo "output/$binary not found!" >&2
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "output/dropshell.aarch64" ]; then
|
|
||||||
echo "output/dropshell.aarch64 not found!" >&2
|
|
||||||
echo "Please run multibuild.sh first." >&2
|
echo "Please run multibuild.sh first." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
TAG=$("$SCRIPT_DIR/output/dropshell.x86_64" --version)
|
TAG=$("$SCRIPT_DIR/output/dropshell.x86_64" --version)
|
||||||
[ -z "$TAG" ] && echo "Failed to get version from dropshell.x86_64" >&2 && exit 1
|
[ -z "$TAG" ] && echo "Failed to get version from dropshell.x86_64" >&2 && exit 1
|
||||||
@ -89,23 +78,35 @@ if [ -z "$RELEASE_ID" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Function to find file in specified locations
|
||||||
|
find_file() {
|
||||||
|
local filename="$1"
|
||||||
|
shift # remove filename from args
|
||||||
|
local locations=("$@") # grab the rest of the args as locations
|
||||||
|
|
||||||
|
for loc in "${locations[@]}"; do
|
||||||
|
if [ -f "$loc/$filename" ]; then
|
||||||
|
echo "$loc/$filename"
|
||||||
|
return 0 # Found the file, return success
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "" # Return empty string if not found
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Upload binaries and install.sh
|
# Upload binaries and install.sh
|
||||||
for FILE in dropshell.x86_64 dropshell.aarch64 install.sh server_autosetup.sh; do
|
for FILE in dropshell.x86_64 dropshell.aarch64 install.sh server_autosetup.sh; do
|
||||||
if [ -f "output/$FILE" ]; then
|
# Pass the locations directly to the find_file function
|
||||||
filetoupload="output/$FILE"
|
filetoupload=$(find_file "$FILE" "output" "../" ".")
|
||||||
elif [ -f "../$FILE" ]; then
|
if [ -z "$filetoupload" ]; then
|
||||||
filetoupload="../$FILE"
|
echo "File $FILE not found in expected locations!" >&2
|
||||||
elif [ -f "$FILE" ]; then
|
|
||||||
filetoupload="$FILE"
|
|
||||||
else
|
|
||||||
echo "File $FILE not found!" >&2
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Auto-detect content type
|
# Auto-detect content type
|
||||||
ctype=$(file --mime-type -b "$filetoupload")
|
ctype=$(file --mime-type -b "$filetoupload")
|
||||||
|
|
||||||
curl -s -X POST "$API_URL/releases/$RELEASE_ID/assets?name=$FILE" \
|
curl -X POST "$API_URL/releases/$RELEASE_ID/assets?name=$FILE" \
|
||||||
-H "Content-Type: $ctype" \
|
-H "Content-Type: $ctype" \
|
||||||
-H "Authorization: token $TOKEN" \
|
-H "Authorization: token $TOKEN" \
|
||||||
--data-binary @"$filetoupload"
|
--data-binary @"$filetoupload"
|
||||||
|
@ -130,6 +130,28 @@ int edit_server(const std::string &server_name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_directory(std::string dir, std::string msg)
|
||||||
|
{
|
||||||
|
bool first=true;
|
||||||
|
std::vector<std::string> directories;
|
||||||
|
for (const auto &file : std::filesystem::directory_iterator(dir))
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
if (!msg.empty())
|
||||||
|
info << msg << std::endl;
|
||||||
|
first=false;
|
||||||
|
}
|
||||||
|
if (std::filesystem::is_directory(file.path()))
|
||||||
|
directories.push_back(file.path());
|
||||||
|
else
|
||||||
|
info << " " << file.path() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &dir : directories)
|
||||||
|
list_directory(dir, "");
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// edit service config
|
// edit service config
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -143,7 +165,14 @@ int edit_service_config(const std::string &server, const std::string &service)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (edit_file(config_file, true) && std::filesystem::exists(config_file))
|
if (edit_file(config_file, true) && std::filesystem::exists(config_file))
|
||||||
info << "To apply your changes, run:\n dropshell install " + server + " " + service << std::endl;
|
info << "Successfully edited service config file at " << config_file << std::endl;
|
||||||
|
|
||||||
|
std::string service_dir = localpath::service(server, service);
|
||||||
|
list_directory(service_dir, "You may wish to edit the other files in " + service_dir);
|
||||||
|
|
||||||
|
info << "Then to apply your changes, run:" << std::endl;
|
||||||
|
info << " dropshell uninstall " + server + " " + service << std::endl;
|
||||||
|
info << " dropshell install " + server + " " + service << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,26 @@ namespace dropshell
|
|||||||
std::string server = server_env.get_server_name();
|
std::string server = server_env.get_server_name();
|
||||||
LocalServiceInfo service_info = get_service_info(server_env.get_server_name(), service);
|
LocalServiceInfo service_info = get_service_info(server_env.get_server_name(), service);
|
||||||
|
|
||||||
if (!SIvalid(service_info) || !service_info.service_template_hash_match)
|
if (!SIvalid(service_info))
|
||||||
|
{
|
||||||
|
error << "Failed to install - service information not valid." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!server_env.is_valid())
|
||||||
|
return false; // should never hit this.
|
||||||
|
|
||||||
|
|
||||||
|
std::string user = server_env.get_user_for_service(service);
|
||||||
|
std::string remote_service_path = remotepath(server,user).service(service);
|
||||||
|
|
||||||
|
if (server_env.check_remote_dir_exists(remote_service_path, user))
|
||||||
|
{ // uninstall the old service before we update the config or template!
|
||||||
|
info << "Service " << service << " is already installed on " << server << std::endl;
|
||||||
|
shared_commands::uninstall_service(server_env, service);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!service_info.service_template_hash_match)
|
||||||
{
|
{
|
||||||
warning << "Service " << service << " is using an old template. Updating. " << std::endl;
|
warning << "Service " << service << " is using an old template. Updating. " << std::endl;
|
||||||
if (!merge_updated_service_template(server_env.get_server_name(), service))
|
if (!merge_updated_service_template(server_env.get_server_name(), service))
|
||||||
@ -88,9 +107,6 @@ namespace dropshell
|
|||||||
|
|
||||||
maketitle("Installing " + service + " (" + service_info.template_name + ") on " + server);
|
maketitle("Installing " + service + " (" + service_info.template_name + ") on " + server);
|
||||||
|
|
||||||
if (!server_env.is_valid())
|
|
||||||
return false; // should never hit this.
|
|
||||||
|
|
||||||
// Check if template exists
|
// Check if template exists
|
||||||
template_info tinfo = gTemplateManager().get_template_info(service_info.template_name);
|
template_info tinfo = gTemplateManager().get_template_info(service_info.template_name);
|
||||||
if (!tinfo.is_set())
|
if (!tinfo.is_set())
|
||||||
@ -103,8 +119,6 @@ namespace dropshell
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create service directory
|
// Create service directory
|
||||||
std::string user = server_env.get_user_for_service(service);
|
|
||||||
std::string remote_service_path = remotepath(server,user).service(service);
|
|
||||||
std::string mkdir_cmd = "mkdir -p " + quote(remote_service_path);
|
std::string mkdir_cmd = "mkdir -p " + quote(remote_service_path);
|
||||||
if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", mkdir_cmd, {}), cMode::Silent))
|
if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", mkdir_cmd, {}), cMode::Silent))
|
||||||
{
|
{
|
||||||
@ -112,14 +126,6 @@ namespace dropshell
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if rsync is installed on remote host
|
|
||||||
std::string check_rsync_cmd = "which rsync";
|
|
||||||
if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", check_rsync_cmd, {}), cMode::Silent))
|
|
||||||
{
|
|
||||||
std::cerr << "rsync is not installed on the remote host" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy template files
|
// Copy template files
|
||||||
debug << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl
|
debug << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl
|
||||||
<< std::string(8, ' ') << "[REMOTE] " << remotepath(server,user).service_template(service) << "/" << std::endl;
|
<< std::string(8, ' ') << "[REMOTE] " << remotepath(server,user).service_template(service) << "/" << std::endl;
|
||||||
|
@ -345,6 +345,8 @@ namespace dropshell
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
env_vars["HOST_NAME"] = get_SSH_HOST();
|
||||||
|
|
||||||
std::string argstr = "";
|
std::string argstr = "";
|
||||||
for (const auto &arg : args)
|
for (const auto &arg : args)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user