Commit c5df6ded authored by KatolaZ's avatar KatolaZ

Added "inject" function to manage file injection

parent bca2d58f
......@@ -10,7 +10,7 @@
## version 3 of the License or, at your option, any later version.
##
VERSION=0.2
VERSION=0.3
## Error values
ERR_PARAM=2
......@@ -18,6 +18,7 @@ ERR_REPO=4
ERR_BRANCH=8
ERR_STATUS=16
ERR_PROCESS=32
ERR_FILES=64
## Conf variables
CGIT_URL="https://anonscm.debian.org/cgit/"
......@@ -45,6 +46,56 @@ Please commit your changes or ignore untracked files\n"
fi
}
## function
check_branch(){
BRANCH="$1"
IS_BRANCH=$(git branch --list ${BRANCH} | grep -E "${BRANCH}[ ]*$")
if [ -z "${IS_BRANCH}" ]; then
printf "No branch ${BRANCH} found!\n"
exit ${ERR_BRANCH}
fi
}
## function
patch_rules_inject(){
INJECT_BRANCH="$1"
## first, check that debian/rules exists
[ ! -d "debian/" -o ! -f "debian/rules" ] && return ${ERR_FILES}
TO_INJECT=""
while read from to; do
TO_INJECT="\tcp $from $to\n${TO_INJECT}"
done < devuan/inject
##echo "TO_INJECT: \n${TO_INJECT}"
## now we check if debian/rules already has an override_dh_install
HAS_OVERRIDE=$(grep -E -c "^override_dh_install:" debian/rules)
if [ "${HAS_OVERRIDE}" = "0" ]; then
## debian/rules does not have an override_dh_install:
echo "no override_dh_install found"
echo "\noverride_dh_install:\n\tdh_install\n${TO_INJECT}" >> debian/rules
else
## debian/rules already has an override_dh_install:
## (hence, we must put out commends after the last command in override_dh_install)
echo "has_override"
OLD_OVERRIDE=$(sed -n -e '/override_dh_install:/,/^$/p' debian/rules | grep -v "^$" )
sed -r -i -e '/override_dh_install:/,/^$/d' debian/rules
echo "\n${OLD_OVERRIDE}" >> debian/rules
echo "${TO_INJECT}" >> debian/rules
fi
git add devuan
git commit -a -m "Injected files from ${INJECT_BRANCH}"
}
##
## Check if debian/gbp.conf exists for the current suite, otherwise
## recreate it and commit
......@@ -61,6 +112,7 @@ ensure_gbp_conf(){
cat <<EOF > debian/gbp.conf
[DEFAULT]
debian-branch=${SUITE}
ignore-branch=True
EOF
git add debian/gbp.conf
git commit -m "re-creating debian/gbp.conf for suite ${SUITE}"
......@@ -297,7 +349,7 @@ handle_stage(){
check_git "$0"
check_pending_commits
PKG_VERSION=$1
PKG_VERSION="$1"
if [ -z "${PKG_VERSION}" ]; then
echo "$0: you must specify a version number"
......@@ -319,6 +371,8 @@ handle_stage(){
exit ${ERR_PROCESS}
fi
PKG_VERSION=$(echo ${PKG_VERSION} | sed -r -s 's/:/%/g')
git tag "${PKG_VERSION}"
CUR_SUITE=$(git branch | grep -E "^\*" | cut -d " " -f 2)
......@@ -375,6 +429,32 @@ handle_burp(){
}
## try to inject files from the SUITE-inject repo, and to patch
## debian/rules accordingly (and automatically)
## function
handle_inject(){
check_git "$0"
CUR_SUITE=$(git branch | grep -E "^\*" | cut -d " " -f 2 | sed -r -e 's:^suites/::g')
if [ -z "${CUR_SUITE}" ]; then
echo "### no suites available -- use 'd1h prepare' to create one ###" >&2
else
## we should import the devuan/ folder from CUR_SUITE-inject
INJECT_BRANCH="${CUR_SUITE}-inject"
check_branch "${INJECT_BRANCH}"
echo "found branch ${INJECT_BRANCH} -- checking out devuan/"
git checkout "${INJECT_BRANCH}" devuan/
git checkout "${INJECT_BRANCH}" debian/
patch_rules_inject "${INJECT_BRANCH}"
fi
}
## function
show_usage(){
......@@ -477,6 +557,10 @@ case "$1" in
shift 1
handle_burp "$@"
;;
inject)
shift 1
handle_inject "$@"
;;
*)
echo "Unknown command: $1"
exit ${ERR_PARAM};
......
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