56 lines
1.5 KiB
Bash
Executable File
56 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: scripts/new-package.sh <AppName> [--id <com.example.app>] [--title <Title>] [--port <port>]
|
|
|
|
Creates CloudronPackages/<AppName> from PackageTemplate and replaces placeholders:
|
|
__APP_ID__, __APP_TITLE__, __HTTP_PORT__
|
|
|
|
Examples:
|
|
scripts/new-package.sh MyApp --id com.example.myapp --title "My App" --port 3000
|
|
EOF
|
|
}
|
|
|
|
if [[ $# -lt 1 ]]; then
|
|
usage; exit 1
|
|
fi
|
|
|
|
APP_NAME="$1"; shift
|
|
APP_ID="com.example.${APP_NAME,,}"
|
|
APP_TITLE="$APP_NAME"
|
|
HTTP_PORT="3000"
|
|
BASE_TAG="5.0.0"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--id) APP_ID="$2"; shift 2;;
|
|
--title) APP_TITLE="$2"; shift 2;;
|
|
--port) HTTP_PORT="$2"; shift 2;;
|
|
--base) BASE_TAG="$2"; shift 2;;
|
|
-h|--help) usage; exit 0;;
|
|
*) echo "Unknown argument: $1"; usage; exit 1;;
|
|
esac
|
|
done
|
|
|
|
SRC_DIR="CloudronPackages/PackageTemplate"
|
|
DEST_DIR="CloudronPackages/${APP_NAME}"
|
|
|
|
[[ -d "$SRC_DIR" ]] || { echo "Template not found: $SRC_DIR"; exit 1; }
|
|
[[ -e "$DEST_DIR" ]] && { echo "Destination already exists: $DEST_DIR"; exit 1; }
|
|
|
|
mkdir -p "$DEST_DIR"
|
|
cp -a "$SRC_DIR"/. "$DEST_DIR"/
|
|
|
|
# Replace placeholders in text files
|
|
find "$DEST_DIR" -type f \( -name "*" ! -name "*.png" \) -print0 | while IFS= read -r -d '' f; do
|
|
sed -i "s#__APP_ID__#${APP_ID}#g" "$f"
|
|
sed -i "s#__APP_TITLE__#${APP_TITLE}#g" "$f"
|
|
sed -i "s#__HTTP_PORT__#${HTTP_PORT}#g" "$f"
|
|
sed -i "s#__CLOUDRON_BASE__#${BASE_TAG}#g" "$f"
|
|
done
|
|
|
|
echo "Created package at: $DEST_DIR"
|
|
echo "Next steps: edit Dockerfile and start.sh to run your app. Add logo.png if desired."
|