Refactor appimage_maker.sh to run directly

This commit is contained in:
XargonWan 2025-03-31 08:55:01 +09:00
parent 750b468d3a
commit 57b0902591

View file

@ -9,91 +9,90 @@ set -e
# $4: (Optional) Additional CMake arguments
# $5...: (Optional) One or more patch file paths to be applied before building
build_appimage() {
local REPO_URL="$1"
local APP_NAME="$2"
local APPIMAGE_OUTPUT="$3"
local CMAKE_ARGS="${4:-}"
shift 4
local PATCH_FILES=("$@") # Remaining arguments are patch files
# Static/temporary names based on the app name:
local CLONE_DIR="$APP_NAME"
local BUILD_DIR="build"
local APPDIR="${APP_NAME}.AppDir"
local REPO_URL="$1"
local APP_NAME="$2"
local APPIMAGE_OUTPUT="$3"
local CMAKE_ARGS="${4:-}"
shift 4
local PATCH_FILES=("$@") # Remaining arguments are patch files
# Save current directory
local CURRENT_DIR
CURRENT_DIR="$(pwd)"
# Static/temporary names based on the app name:
local CLONE_DIR="$APP_NAME"
local BUILD_DIR="build"
local APPDIR="${APP_NAME}.AppDir"
echo "--- AppImage Maker initiated ---"
echo "Building AppImage for $APP_NAME"
echo "Repository: $REPO_URL"
echo "AppImage output: $APPIMAGE_OUTPUT"
echo "CMake arguments: $CMAKE_ARGS"
if [ ${#PATCH_FILES[@]} -gt 0 ]; then
echo "Patch files: ${PATCH_FILES[*]}"
fi
# Save current directory
local CURRENT_DIR
CURRENT_DIR="$(pwd)"
# Clone the repository if not already cloned
if [ ! -d "$CLONE_DIR" ]; then
echo "Cloning repository: $REPO_URL in $CLONE_DIR"
git clone "$REPO_URL" "$CLONE_DIR"
fi
echo "--- AppImage Maker initiated ---"
echo "Building AppImage for $APP_NAME"
echo "Repository: $REPO_URL"
echo "AppImage output: $APPIMAGE_OUTPUT"
echo "CMake arguments: $CMAKE_ARGS"
if [ ${#PATCH_FILES[@]} -gt 0 ]; then
echo "Patch files: ${PATCH_FILES[*]}"
fi
pushd "$CLONE_DIR" > /dev/null
# Clone the repository if not already cloned
if [ ! -d "$CLONE_DIR" ]; then
echo "Cloning repository: $REPO_URL in $CLONE_DIR"
git clone "$REPO_URL" "$CLONE_DIR"
fi
# Optionally checkout a specific branch or commit if desired
# git checkout <branch-or-commit>
pushd "$CLONE_DIR" > /dev/null
# Apply patch files, if provided
if [ ${#PATCH_FILES[@]} -gt 0 ]; then
for patch in "${PATCH_FILES[@]}"; do
if [ -f "$patch" ]; then
echo "Applying patch: $patch"
patch -p1 < "$patch"
else
echo "Warning: Patch file $patch does not exist. Skipping."
fi
done
fi
# Optionally checkout a specific branch or commit if desired
# git checkout <branch-or-commit>
# Create build directory and build the project
mkdir -p "$BUILD_DIR"
pushd "$BUILD_DIR" > /dev/null
echo "Building $APP_NAME in $BUILD_DIR"
cmake .. -DCMAKE_BUILD_TYPE=Release $CMAKE_ARGS
make -j"$(nproc)"
popd > /dev/null
# Apply patch files, if provided
if [ ${#PATCH_FILES[@]} -gt 0 ]; then
for patch in "${PATCH_FILES[@]}"; do
if [ -f "$patch" ]; then
echo "Applying patch: $patch"
patch -p1 < "$patch"
else
echo "Warning: Patch file $patch does not exist. Skipping."
fi
done
fi
# Prepare the AppDir structure
rm -rf "$APPDIR"
mkdir -p "$APPDIR/usr/bin"
# Assumes the built executable is named as the app name and is located in the build directory
cp "$BUILD_DIR/$APP_NAME" "$APPDIR/usr/bin/"
# Create build directory and build the project
mkdir -p "$BUILD_DIR"
pushd "$BUILD_DIR" > /dev/null
echo "Building $APP_NAME in $BUILD_DIR"
cmake .. -DCMAKE_BUILD_TYPE=Release $CMAKE_ARGS
make -j"$(nproc)"
popd > /dev/null
# Copy the desktop file and icon (assumed to be in the repository root with matching names)
cp "${APP_NAME}.desktop" "$APPDIR/"
cp "${APP_NAME}.png" "$APPDIR/"
# Prepare the AppDir structure
rm -rf "$APPDIR"
mkdir -p "$APPDIR/usr/bin"
# Assumes the built executable is named as the app name and is located in the build directory
cp "$BUILD_DIR/$APP_NAME" "$APPDIR/usr/bin/"
# Download appimagetool if not already present (placed one level above the clone directory)
if [ ! -f "../appimagetool" ]; then
echo "Downloading appimagetool..."
wget -O ../appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x ../appimagetool
else
echo "appimagetool already exists. Skipping download."
fi
# Copy the desktop file and icon (assumed to be in the repository root with matching names)
cp "${APP_NAME}.desktop" "$APPDIR/"
cp "${APP_NAME}.png" "$APPDIR/"
# Create the AppImage using appimagetool
echo "Creating AppImage..."
../appimagetool "$APPDIR" "$APPIMAGE_OUTPUT"
# Download appimagetool if not already present (placed one level above the clone directory)
if [ ! -f "../appimagetool" ]; then
echo "Downloading appimagetool..."
wget -O ../appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x ../appimagetool
else
echo "appimagetool already exists. Skipping download."
fi
echo "AppImage created: $APPIMAGE_OUTPUT"
# Create the AppImage using appimagetool
echo "Creating AppImage..."
../appimagetool "$APPDIR" "$APPIMAGE_OUTPUT"
popd > /dev/null
cd "$CURRENT_DIR"
}
echo "AppImage created: $APPIMAGE_OUTPUT"
popd > /dev/null
cd "$CURRENT_DIR"
# Example usage:
# This will clone the repository into a folder named "dolphin-emu",