aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile40
-rw-r--r--docs.json6
-rwxr-xr-xsetupdocs.sh109
3 files changed, 119 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 4646799..8892612 100644
--- a/Makefile
+++ b/Makefile
@@ -1,37 +1,23 @@
-DOCTOOLS=doctools
-DOCBUILD=$(DOCTOOLS)/docbuild
+DOCBUILD=doctools/docbuild
VERBOSE=--verbose
FETCHTS=.fetch.ts
LOCALFETCH=.LocalFetch.ts
-define GetFromConfig
-$(shell node -p "require('./docs.json').$(1)")
-endef
-
-DOCTOOLSREPO := $(call GetFromConfig,doctools.url)
-DOCTOOLSBRANCH := $(call GetFromConfig,doctools.version)
-
all: help
help:
@echo "Usage:"
- @echo "- make distclean: clean all generated files and repos"
@echo "- make clean: clean all generated files"
- @echo "- make doctools: clone doctools repository"
@echo "- make fetch: fetch the site if necessary"
@echo "- make localFetch: fetch the site if necessary but use local file."
@echo "- make build: build the site"
@echo "- make push: push the built site"
@echo "- make serve: serve the site"
-.PHONY: distclean
-distclean: clean
- rm -fr $(DOCTOOLS)
-
.PHONY: clean
-clean: doctools
+clean:
$(DOCBUILD) $(VERBOSE) --clean
rm -f $(FETCHTS)
rm -f $(LOCALFETCH)
@@ -45,29 +31,23 @@ $(FETCHTS): $(wildcard content/toc/*/fetched_files.yml)
$(DOCBUILD) $(VERBOSE) $(LOCAL_FETCHTS) --fetch --force
touch $@
-prebuild:
- @node -v && [ $$? -eq 0 ] || (echo "Please, make sure nodejs is installed" && false)
- @jekyll -v && [ $$? -eq 0 ] || (echo "Please, make sure jekyll is installed" && false)
-
-.PHONY: doctools
-doctools: prebuild
- echo $(DOCTOOLSREPO)
- @test ! -d $(DOCTOOLS) && git clone -b $(DOCTOOLSBRANCH) $(DOCTOOLSREPO) $(DOCTOOLS) || true
- @cd $(DOCTOOLS) && npm install
-
.PHONY: fetch
-fetch: doctools $(FETCHTS)
+fetch: $(FETCHTS)
@echo "Fetched files up to date."
+.PHONY: localFetch
+localFetch: $(LOCALFETCH) $(FETCHTS)
+ @echo "Fetched files up to date and copy local file."
+
.PHONY: build
-build: doctools $(FETCHTS)
+build: $(FETCHTS)
$(DOCBUILD) $(VERBOSE) --build
.PHONY: push
-push: doctools $(FETCHTS)
+push: $(FETCHTS)
$(DOCBUILD) $(VERBOSE) --build --push
.PHONY: serve
-serve: doctools $(FETCHTS)
+serve: $(FETCHTS)
$(DOCBUILD) $(VERBOSE) --build --serve
diff --git a/docs.json b/docs.json
deleted file mode 100644
index 89a1930..0000000
--- a/docs.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "doctools": {
- "url": "https://github.com/automotive-grade-linux/docs-tools.git",
- "version": "master"
- }
-}
diff --git a/setupdocs.sh b/setupdocs.sh
new file mode 100755
index 0000000..f09e137
--- /dev/null
+++ b/setupdocs.sh
@@ -0,0 +1,109 @@
+#!/bin/bash
+
+PROGNAME=${0##*/}
+DESTINATION="."
+NOGIT=0
+DOCTOOLSDIR="doctools"
+docswebtemplates="https://github.com/automotive-grade-linux/docs-webtemplate.git"
+doctools="https://github.com/automotive-grade-linux/docs-tools.git"
+
+#default branch
+branch_doctools="master"
+branch_docswebtemplates="master"
+
+pushd() {
+ command pushd "$@" &> /dev/null
+}
+popd() {
+ command popd "$@" &> /dev/null
+}
+
+function usage() {
+ echo "Usage: setupdocs.sh [OPTIONS]... [DIRECTORY]"
+ echo " -d, --directory=[DST] directory destination"
+ echo " -h, --help print this help"
+ echo " -t, --doctools-branch=[BRANCH] doctools branch; BRANCH can be master or master-next"
+ echo " -w, --webtemplates-branch=[BRANCH] webtemplates branch; BRANCH can be master or master-next"
+ exit 1
+}
+
+
+SHORTOPTS="w:t:d:h"
+LONGOPTS="webtemplates-branch:,doctools-branch:,directory:,help"
+ARGS=$(getopt -s bash --options $SHORTOPTS \
+ --longoptions $LONGOPTS --name $PROGNAME -- "$@" )
+if [ ! $? -eq 0 ]; then
+ exit 1
+fi
+eval set -- "$ARGS"
+
+while [ "$#" -gt "1" ]; do
+ case "$1" in
+ -w|--webtemplates-branch)
+ branch_docswebtemplates=$2;shift 2;;
+ -t|--doctools-branch)
+ branch_doctools=$2; shift 2;;
+ -d|--directory)
+ DESTINATION=$2;shift 2;;
+ -h|--help)
+ usage;;
+ *)
+ usage;;
+ esac
+done
+
+#check writable dir
+if [ ! -w $DESTINATION ]; then
+ echo "$DESTINATION is not a writable directory"
+ exit 2
+fi
+
+#make sure nodejs and jekyll are installed
+node -v && jekyll -v
+if [ ! $? -eq 0 ]; then
+ echo "please, make sure nodejs and jekyll are installed"
+ exit 3
+fi
+
+#cloning repos
+pushd $DESTINATION
+#Checking if current dir is docwebtemplates repo
+currentremote=$(git remote -v 2> /dev/null)
+if [ $? -eq 0 ]; then #within a git
+ #check in remote there is docswebtemplate
+ echo $currentremote | grep $(basename $docswebtemplates) &> /dev/null
+ if [ $? -eq 0 ]; then
+ NOGIT=1
+ fi
+fi
+
+if [ $NOGIT -eq 0 ]; then
+ echo "Cloning docwebtemplates and doctools in $DESTINATION"
+ git clone -b $branch_docswebtemplates $docswebtemplates &> /dev/null
+ pushd $(basename $docswebtemplates | sed "s/\..*//")
+ git clone -b $branch_doctools $doctools $DOCTOOLSDIR &> /dev/null
+ pushd $DOCTOOLSDIR
+ npm install
+ popd
+ popd
+ echo "docwebtemplates and doctools cloned in $DESTINATION"
+else
+ echo "you are in docs-webtemplate in branch $(git branch | grep "*"): process $DOCTOOLSDIR"
+ echo "so no process will be done in docs-webtemplate"
+ if [ -d $DOCTOOLSDIR ]; then
+ echo "$DOCTOOLSDIR already exits: process update with branch=$branch_doctools"
+ pushd $DOCTOOLSDIR
+ git checkout $branch_doctools &> /dev/null
+ git pull $doctools $branch_doctools &> /dev/null
+ npm install
+ popd
+ else
+ echo "cloning $DOCTOOLSDIR"
+ git clone -b $branch_doctools $doctools $DOCTOOLSDIR &> /dev/null
+ pushd $DOCTOOLSDIR
+ npm install
+ popd
+ fi
+ echo "doctools updated"
+fi
+popd