-
Notifications
You must be signed in to change notification settings - Fork 4
/
create-app.sh
executable file
·57 lines (45 loc) · 1.91 KB
/
create-app.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#set -x
#
# Creates an initial simple hello world application from template, with all required build files etc.
# Once created, you should be able to type "make" to fully compile for all targets the application.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ $# -ne 2 ] ; then
echo "Usage: $(basename $0) APP_NAME PATH/TO/ROOT"
echo " APP_NAME : name of directory created, and the app name for project"
echo " PATH/TO/ROOT : path the the folder that APP_NAME directory will be created in"
exit 1
fi
APP_NAME="$1"
ROOT_DIR_PATH="$2"
if [ ! -d "${ROOT_DIR_PATH}" ] ; then
echo "Could not find root directory to create app in. Please create it first to confirm it is correct"
read -p "Do you want to create the directory now? (y/n): " choice
if [[ ! "$choice" =~ ^(y|Y)$ ]] ; then
echo "Exiting..."
exit 1
else
mkdir -p "${ROOT_DIR_PATH}"
fi
fi
TARGET_APP_DIR="${ROOT_DIR_PATH}/${APP_NAME}"
while [ -d "${TARGET_APP_DIR}" ] ; do
echo "Target directory ${TARGET_APP_DIR} already exists. Please move/delete it, or choose new name."
read -p "New APP_NAME (leave blank to quit): " NEW_APP_NAME
if [[ -z "${NEW_APP_NAME}" ]]; then
exit 1
fi
APP_NAME="${NEW_APP_NAME}"
TARGET_APP_DIR="${ROOT_DIR_PATH}/${APP_NAME}"
done
echo "Creating ${TARGET_APP_DIR}"
# copy files into new project dir
cp -r "${SCRIPT_DIR}/template-app" "${TARGET_APP_DIR}"
sed "s#__TEMPLATE_APP__#${APP_NAME}#g" "${SCRIPT_DIR}/template-app/README.md" > "${TARGET_APP_DIR}/README.md"
cp -r makefiles "${TARGET_APP_DIR}/"
cp -r apple-tools "${TARGET_APP_DIR}/"
# create project Makefile
mv "${TARGET_APP_DIR}/makefiles/Makefile_sample_change" "${TARGET_APP_DIR}/Makefile"
sed -i.bu "s#../../fujinet-build-tools#.#g;s#__APP_NAME__#${APP_NAME}#g" "${TARGET_APP_DIR}/Makefile"
# remove any backup files created by sed because macos
find "${TARGET_APP_DIR}" -name \*.bu -exec rm {} \;