solus-packages/common/Scripts/new-package.sh

40 lines
963 B
Bash
Executable file

#!/usr/bin/env bash
# Creates a new package from the package name and tarball
set -euo pipefail
if [[ $# -eq 2 ]]; then
PACKAGE="$1"
TARBALL="$2"
elif [[ $# -gt 0 && $# -ne 2 ]]; then
echo "Usage: $0 <package name> <tarball>"
exit 1
else
read -p "Package name: " prompt
PACKAGE=${prompt}
read -p "Tarball URL: " prompt
TARBALL=${prompt}
fi
YAUTO=$(git rev-parse --show-toplevel)/common/Scripts/yauto.py
# Basic repo name linting check
if [[ ! "${PACKAGE}" =~ ^[a-z0-9.]+(-[a-z0-9.]+)*$ ]]; then
echo "Package names are restricted to US ASCII lowercase letters, numbers, dashes, and, dots."
exit 1
fi
# FIXME: Don't hardcode this case
if [[ ${PACKAGE:0:2} == "py" ]]; then
DIR="packages/py/${PACKAGE}"
else
DIR="packages/${PACKAGE:0:1}/${PACKAGE}"
fi
mkdir -p $(git rev-parse --show-toplevel)/${DIR}
pushd $(git rev-parse --show-toplevel)/${DIR}
$YAUTO ${TARBALL}
printf "\npackage.yml created in ${DIR}\n"