web/tools/init.sh

86 lines
1.4 KiB
Bash
Raw Normal View History

2020-07-28 21:27:40 +03:00
#!/bin/bash
#
# Init the evrionment for new user.
#
# v2.5
# https://github.com/cotes2020/jekyll-theme-chirpy
# © 2020 Cotes Chung
# Published under MIT License
set -eu
ACTIONS_WORKFLOW=pages-deploy.yml
help() {
echo "Usage:"
echo
echo " bash /path/to/init.sh [options]"
echo
echo "Options:"
echo " --no-gh Do not deploy to Github."
echo " -h, --help Print this help information."
}
check_init() {
local _has_inited=false
if [[ -d .github ]]; then
2020-09-01 09:54:29 +03:00
if [[ -f .github/workflows/$ACTIONS_WORKFLOW && \
$(find .github/workflows/ -type f -name "*.yml" | wc -l) == 1 ]]; then
2020-07-28 21:27:40 +03:00
_has_inited=true
fi
else
_has_inited=true
fi
2020-09-01 09:54:29 +03:00
if $_has_inited; then
2020-07-28 21:27:40 +03:00
echo "Already initialized."
exit 0
fi
}
init_files() {
2020-09-01 09:54:29 +03:00
if $_no_gh; then
2020-07-28 21:27:40 +03:00
rm -rf .github
else
mv .github/workflows/$ACTIONS_WORKFLOW.hook .
rm -rf .github
mkdir -p .github/workflows
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
fi
rm -f .travis.yml
rm -rf _posts/* docs
2020-09-01 09:54:29 +03:00
git add -A && git add .github -f
2020-07-28 21:27:40 +03:00
git commit -m "[Automation] Initialize the environment." -q
echo "[INFO] Initialization successful!"
}
check_init
_no_gh=false
2020-09-01 09:54:29 +03:00
while (($#)); do
2020-07-28 21:27:40 +03:00
opt="$1"
case $opt in
--no-gh)
_no_gh=true
shift
;;
2020-09-01 09:54:29 +03:00
-h | --help)
2020-07-28 21:27:40 +03:00
help
exit 0
;;
2020-09-01 09:54:29 +03:00
*)
# unknown option
help
exit 1
;;
2020-07-28 21:27:40 +03:00
esac
done
init_files