Next: Run Update, Up: Run Create and Update [Index]
This shell script is installed into $DEV/bin and is run by typing the shell command ‘new-org-template <...ARGS>’ from the command-line to set up a new Org project at a particular point in your directory structure. The main code is elisp, described above in Create New Project.
After a new project is installed into the directory structure, a git repo is established, as well as a new GitHub repo, and the initial commit is pushed up.
1 # new-org-template
2 # $1 := project
3 # $2 := title
4 # $3 := author
5 # [$4 := bucket] (default := ${AWS_S3_BUCKET})
6
7 USAGE="$0 <project> <title> <author> [<bucket>]\n"
8 [[ -z $AWS_S3_BUCKET ]] && {
9 # printf goes to standard out by default; redirect this error message to standard error
10 printf "${RED}ERROR: ${YELLOW}The environment variable ${GREEN}\$AWS_S3_BUCKET${YELLOW} needs to be set.${CLEAR}\n" >&2
11 exit 1
12 }
13
14 if [[ $1 =~ ^-(h|-?help)$ || ( $# < 3 || $# > 4 ) ]]; then
15 printf "USAGE:\n$USAGE"
16 exit 0;
17 fi
18
19 # verify command-line args contain only letters, digits, underscores, dashes and spaces
20 RE="^[_a-zA-Z][_a-zA-Z0-9 -.]+$"
21 for arg in "$@"; do
22 printf "$arg..."
23 [[ $arg =~ $RE ]] || { printf ": ERROR\n"; exit 1; }
24 printf "ok\n"
25 done
26
27 # bucket is optional;
28 # if it is supplied, make sure it has a suffix, e.g. '.com' or '.org'
29 # if not, add '.com' as the default;
30 # let this be known on standard error
31 bucket=${4:-${AWS_S3_BUCKET}}
32 [[ ${bucket} == ${bucket%.*} ]] && {
33 bucket=${bucket}.com
34 # printf goes to standard out by default; redirect this error message to standard error
35 printf "${YELLOW}The bucket name has had the suffix ${BLUE}.com${YELLOW} added: ${PURPLE}${bucket}${CLEAR}" >&2
36 }
37
38 ${EDITOR} --eval "(progn
39 (load-file \"/usr/local/dev/bin/org-template.el\")
40 (create-new-project \"$1\" \"$2\" \"$3\" \"$bucket\"))"
41
42 # create a new Git repo and GitHub repo
43 cd "$1"
44 rm *~
45 git init
46 git add -A
47 git commit -m "Initial commit"
48 git log | cat
49 git remote add origin git@github.com:wlharvey4/"$1".git
50
51 curl -i -H "Authorization: token ${GITHUB_TOKEN}" \
52 -d "{\"name\":\"$1\",\"description\":\"$2: v0.0.0/\"}" \
53 https://api.github.com/user/repos
54
55 git push origin master
56
57 cd ..
58 tree -a -L 1 "$1"
Next: Run Update, Up: Run Create and Update [Index]