Commit 2b3e5da2 authored by KatolaZ's avatar KatolaZ

shellcheck-ed d1h

parent c840df76
......@@ -26,7 +26,6 @@ CACHE_FILE=${D1H_DIR}/cache
## function
check_git(){
CMD=$1
git status 2>/dev/null
if [ $? != 0 ]; then
echo "$1: need to be into a proper git repository"
......@@ -40,7 +39,7 @@ check_pending_commits(){
IS_CLEAN=$(git status 2>&1 | grep -c -E "working.+clean")
if [ "${IS_CLEAN}" = "0" ]; then
echo "There are uncommitted changes or untracked files present.\n\
printf "There are uncommitted changes or untracked files present.\n\
Please commit your changes or ignore untracked files"
exit ${ERR_STATUS}
fi
......@@ -90,12 +89,12 @@ handle_import(){
fi
PASTWD=$(pwd)
[ ! -d "${DESTDIR}" ] && mkdir -p ${DESTDIR}
[ ! -d "${DESTDIR}" ] && mkdir -p "${DESTDIR}"
[ $? = 0 ] || (echo "Unable to create directory ${DESTDIR}" && exit 3)
cd ${DESTDIR}
git clone ${REPONAME}
cd ${PASTWD}
cd "${DESTDIR}"
git clone "${REPONAME}"
cd "${PASTWD}"
}
......@@ -107,33 +106,33 @@ handle_import(){
## function
handle_link(){
check_git $0
check_git "$0"
if [ $# -le 0 ]; then
echo "Usage: d1h_link <remote>"
exit ${ERR_PARAM}
exit "${ERR_PARAM}"
fi
## FIXME -- SOME SANITISING NEEDED ON REMOTENAME --
REMOTENAME="$1"
NUM_ORIG=$(git remote | grep "^origin" | sort | head -1 | grep "^origin$" | wc -l)
NUM_ORIG=$(git remote | grep "^origin" | sort | head -1 | grep -c "^origin$")
if [ "$NUM_ORIG" = 1 ]; then
## rename the current origin
LAST_ORIG_NUM=$(git remote | grep "^origin" | sort | tail -1 | sed -r -e 's/[-a-zA-Z]//')
if [ -z ${LAST_ORIG_NUM} ]; then
if [ -z "${LAST_ORIG_NUM}" ]; then
NEW_ORIG_NUM=1
else
NEW_ORIG_NUM=$((${LAST_ORIG_NUM} + 1))
NEW_ORIG_NUM=$((LAST_ORIG_NUM + 1))
fi
NEW_LAST_ORIG="origin${NEW_ORIG_NUM}"
git remote rename origin ${NEW_LAST_ORIG}
fi
git remote add origin ${REMOTENAME}
git remote add origin "${REMOTENAME}"
if [ "$?" != 0 ]; then
echo "d1h_link: error in linking remote ${REMOTENAME}"
exit ${ERR_REPO}
exit "${ERR_REPO}"
fi
git push -u origin --all
git push -u origin --tags
......@@ -153,12 +152,12 @@ handle_link(){
handle_cache(){
if [ ! -d ${D1H_DIR} ]; then
mkdir -p ${D1H_DIR}
if [ ! -d "${D1H_DIR}" ]; then
mkdir -p "${D1H_DIR}"
fi
echo "## $(date)" > ${CACHE_FILE}
curl ${CGIT_URL} | parse_alioth >> ${CACHE_FILE}
echo "## $(date)" > "${CACHE_FILE}"
curl "${CGIT_URL}" | parse_alioth >> "${CACHE_FILE}"
exit $?
......@@ -168,7 +167,7 @@ handle_cache(){
## function
handle_search(){
if [ ! -f ${CACHE_FILE} ]; then
if [ ! -f "${CACHE_FILE}" ]; then
echo "No cache found! Run 'd1h cache' to update the cache"
exit 1
fi
......@@ -179,19 +178,19 @@ handle_search(){
SEARCH_CMD="${SEARCH_CMD} | grep ${i}"
done
LAST_UPDATE=$(head -1 ${CACHE_FILE} | sed -r -e 's/#//g')
LAST_UPDATE=$(head -1 "${CACHE_FILE}" | sed -r -e 's/#//g')
echo "##########################" >&2
echo "#### cache last updated on ${LAST_UPDATE} " >&2
echo "##########################" >&2
eval ${SEARCH_CMD}
eval "${SEARCH_CMD}"
exit 0;
}
## function
handle_prepare(){
check_git $0
check_git "$0"
if [ "$#" -le 0 ]; then
echo "Usage: d1h_prepare <suite>"
......@@ -207,13 +206,13 @@ handle_prepare(){
exit 0
fi
git branch ${SUITE}
git branch "${SUITE}"
if [ $? != 0 ]; then
echo "$0: error creating suite \"${SUITE}\""
exit ${ERR_BRANCH}
exit "${ERR_BRANCH}"
fi
git checkout ${SUITE} 1>&2 2>/dev/null
git checkout "${SUITE}" 1>&2 2>/dev/null
cat <<EOF > debian/gbp.conf
[DEFAULT]
debian-branch=${SUITE}
......@@ -221,7 +220,7 @@ EOF
git add --all
git commit -m "creating suite ${SUITE}"
echo "[= suite \"${CUR_BRANCH}\" ready =]" >&2
git checkout ${CUR_BRANCH}
git checkout "${CUR_BRANCH}"
exit 0;
}
......@@ -229,7 +228,7 @@ EOF
## function
handle_switch(){
check_git $0
check_git "$0"
if [ "$#" -le 0 ]; then
echo "Usage: d1h_switch <suite>"
......@@ -237,7 +236,7 @@ handle_switch(){
SUITE="suites/$1"
git checkout ${SUITE} 1>&2 2>/dev/null
git checkout "${SUITE}" 1>&2 2>/dev/null
RET=$?
CUR_BRANCH=$(git branch | grep -E "^\*" | cut -d " " -f 2 | sed -r -e "s/^suites\///g")
......@@ -250,7 +249,7 @@ handle_switch(){
## function
handle_dismiss(){
check_git $0
check_git "$0"
if [ "$#" -le 0 ]; then
echo "Usage: d1h_dismiss <suite>"
......@@ -258,7 +257,7 @@ handle_dismiss(){
SUITE="suites/$1"
git branch -D ${SUITE}
git branch -D "${SUITE}"
exit $?
......@@ -267,7 +266,7 @@ handle_dismiss(){
## function
handle_testbuild(){
check_git $0
check_git "$0"
check_pending_commits
......@@ -285,14 +284,14 @@ handle_testbuild(){
## Now we reset the repo to the last commit, and clean
git reset --hard 1>&2 2>/dev/null
git clean -d -f 1>&2 2>/dev/null
echo ${BUILD_STATUS}
echo "${BUILD_STATUS}"
}
## function
handle_stage(){
check_git $0
check_git "$0"
check_pending_commits
PKG_VERSION=$1
......@@ -302,7 +301,7 @@ handle_stage(){
exit ${ERR_PARAM}
fi
gbp dch -a -R -N ${PKG_VERSION}
gbp dch -a -R -N "${PKG_VERSION}"
[ "$?" != "0" ] && echo "$0: Error in gbp dch " && exit ${ERR_PROCESS}
......@@ -317,12 +316,12 @@ handle_stage(){
exit ${ERR_PROCESS}
fi
git tag ${PKG_VERSION}
git tag "${PKG_VERSION}"
CUR_SUITE=$(git branch | grep -E "^\*" | cut -d " " -f 2)
git push --set-upstream origin ${CUR_SUITE}
git push --set-upstream origin "${CUR_SUITE}"
git push --tags
}
......@@ -335,7 +334,7 @@ handle_suites(){
if [ -z "${SUITES}" ]; then
echo "### no suites available -- use 'd1h prepare' to create one ###" >&2
else
echo ${SUITES}
echo "${SUITES}"
fi
}
......@@ -357,7 +356,7 @@ handle_current(){
show_usage(){
echo "d1h ${VERSION} -- Devuan Package workflow helper"
echo "Usage: $(basename $0) command [options]"
echo "Usage: $(basename "$0") command [options]"
echo
echo "d1h is a helper which guides developers through the "
echo "Devuan package management workflow"
......@@ -382,7 +381,7 @@ show_usage(){
## main -- the script starts here --
case $(basename $0) in
case $(basename "$0") in
"d1h")
if [ "$#" -eq 0 ]; then
show_usage
......@@ -390,10 +389,10 @@ case $(basename $0) in
fi
;;
"d1h_import")
handle_import $@
handle_import "$@"
;;
"d1h_link")
handle_link $@
handle_link "$@"
;;
*)
echo "Unknown command: $0"
......@@ -408,40 +407,40 @@ case "$1" in
;;
search)
shift 1
handle_search $@
handle_search "$@"
exit
;;
import)
## Import a new package -- possibly from alioth.debian.org
shift 1
handle_import $@
handle_import "$@"
;;
link)
## link the current repo to the corresponding one in
## git.devuan.org and set the "origin" accordingly, renaming
## the previous origin
shift 1
handle_link $@
handle_link "$@"
;;
prepare)
shift 1
handle_prepare $@
handle_prepare "$@"
;;
switch)
shift 1
handle_switch $@
handle_switch "$@"
;;
dismiss)
shift 1
handle_dismiss $@
handle_dismiss "$@"
;;
testbuild)
shift 1
handle_testbuild $@
handle_testbuild "$@"
;;
stage)
shift 1
handle_stage $@
handle_stage "$@"
;;
suites)
handle_suites
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment