cosmopolitan/examples/package/new.sh

41 lines
979 B
Bash
Raw Normal View History

#!/bin/sh
#
# SYNOPSIS
#
# Creates new package in repository.
#
# EXAMPLE
#
# examples/package/new.sh com/github/user/project
DIR=${1:?need directory arg}
VAR=$(echo "$DIR" | tr a-z A-Z | tr / _)
2020-06-16 02:59:12 +00:00
DIRNAME=${DIR%/*}
BASENAME=${DIR##*/}
FILENAME="$DIR/$BASENAME"
MAKEFILE="$DIR/$BASENAME.mk"
if [ -d "$DIR" ]; then
echo "already exists: $DIR" >&2
exit 1
fi
mkdir -p "$DIR" &&
2020-06-16 02:59:12 +00:00
cp -R examples/package/* "$DIR" &&
rm -f "$DIR/new.sh" &&
find "$DIR" -type f |
xargs sed -i -e "
2020-06-16 02:59:12 +00:00
s~EXAMPLES_PACKAGE~$VAR~g
s~examples/package/package~$FILENAME~g
s~examples/package~$DIR~g
s~%AUTHOR%~$(git config user.name) <$(git config user.email)>~g
" &&
sed -i -e "
2020-06-16 02:59:12 +00:00
s~include $DIR/build.mk~# XXX: include $DIR/build.mk~
s~include $DIR/lib/build.mk~# XXX: include $DIR/lib/build.mk~
/#-φ-examples\/package\/new\.sh/i\
2020-06-16 02:59:12 +00:00
include $DIR/lib/build.mk
/#-φ-examples\/package\/new\.sh/i\
include $DIR/build.mk
" Makefile