Initial
This commit is contained in:
377
build-package
Executable file
377
build-package
Executable file
@@ -0,0 +1,377 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
cd $(dirname $(realpath $0))/..
|
||||
|
||||
edit_config_files=()
|
||||
force=false
|
||||
no_package_update=false
|
||||
force_package_update=false
|
||||
delete_old=false
|
||||
|
||||
erro(){
|
||||
echo -e "\e[31m$*\e[0m"
|
||||
}
|
||||
info(){
|
||||
echo -e "\e[36m$*\e[0m"
|
||||
}
|
||||
light(){
|
||||
echo -e "\e[37m$*\e[0m"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo
|
||||
light "Usage: $0 [-pfFUuhD] [-v <VERSION>] [-c <CALLBACK FILE>, ...] [-e <EDIT CONFIG FILE>, ...]"
|
||||
echo
|
||||
echo " OPTIONS:"
|
||||
echo
|
||||
info " -v <VERSION>"
|
||||
echo " Forces the <VERSION>"
|
||||
echo
|
||||
info " -f Force"
|
||||
echo " Upload without asking to git-packages"
|
||||
echo
|
||||
info " -F Force all"
|
||||
echo " Like '-f -U' Do package-update and upload without asking to git-packages"
|
||||
echo " Also deletes ALL previous Version"
|
||||
echo
|
||||
info " -D Delete previous"
|
||||
echo " Deletes ALL previous Version"
|
||||
echo
|
||||
info " -U Package Update"
|
||||
echo " Force Package Update Process without asking"
|
||||
echo
|
||||
info " -u No Package Update"
|
||||
echo " Disables asking for Update and ommits"
|
||||
echo
|
||||
info " -e <EDIT CONFIG FILE>"
|
||||
echo " These files may be edited before ./bin/package-update"
|
||||
echo " Multiple are possible"
|
||||
erro " If ./bin/package-update.d/configs exists, the files in this file are edited (too)"
|
||||
echo
|
||||
info " -h Help"
|
||||
echo " Print this help and exit"
|
||||
}
|
||||
|
||||
while getopts "uUDhfFv:e:" opt; do
|
||||
case ${opt} in
|
||||
u)
|
||||
no_package_update=true
|
||||
;;
|
||||
U)
|
||||
force_package_update=true
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
e)
|
||||
edit_config_files+=("$OPTARG")
|
||||
;;
|
||||
f)
|
||||
force=true
|
||||
;;
|
||||
F)
|
||||
force=true
|
||||
force_package_update=true
|
||||
delete_old=true
|
||||
;;
|
||||
v)
|
||||
version="$OPTARG"
|
||||
;;
|
||||
D)
|
||||
delete_old=true
|
||||
;;
|
||||
\?)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
$no_package_update && $force_package_update && ( force_package_update=false; no_package_update=false )
|
||||
|
||||
|
||||
|
||||
[[ ! -f apt.conf.sh ]] && echo "No apt.conf.sh in $(pwd) - aborting" && exit 1
|
||||
[[ ! -d .git ]] && echo "No .git - aborting" && exit 1
|
||||
|
||||
if [[ ! -z "$(git status -s)" ]]; then
|
||||
echo -e "\e[3;31mCommitte bitte erst die Änderungen\e[0m"
|
||||
git status -s
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git fetch --tags
|
||||
git pull --all
|
||||
|
||||
|
||||
|
||||
. apt.conf.sh
|
||||
|
||||
# from apt.conf.sh:
|
||||
[[ -z "$PACKAGE_NAME" ]] && echo "Must have 'PACKAGE_NAME=...' in apt.conf" && exit 2
|
||||
[[ -z "$INSTALLDIR" ]] && echo "Must have 'INSTALLDIR=...' in apt.conf" && exit 2
|
||||
[[ ! "$INSTALLDIR" =~ ^/ ]] && echo "$INSTALLDIR be absolute" && exit 2
|
||||
[[ -z "$DESCRIPTION" ]] && echo "Must have 'DESCRIPTION=...' in apt.conf" && exit 2
|
||||
|
||||
[[ -f version-affix.txt ]] && PACKAGE_NAME+="-$(cat version-affix.txt)"
|
||||
|
||||
|
||||
REPO_NAME='stable'
|
||||
MAIN_VERSION=""
|
||||
temp_changelog="/tmp/changelog-$PACKAGE_NAME.txt"
|
||||
temp_packageupdate="/tmp/packageupdate-$PACKAGE_NAME.log"
|
||||
|
||||
[[ -f main-version.txt ]] && MAIN_VERSION=$(cat main-version.txt)
|
||||
|
||||
branch=$(git branch -q | grep '*' | sed 's/\* *//')
|
||||
|
||||
# Das erlaubt uns zB ein Odoo 18.0 zu packen (18.0 ist dann main)
|
||||
if [[ "$branch" != 'main' ]] && [[ "$branch" != "$MAIN_VERSION" ]]; then
|
||||
echo -e "\e[3;31mDu bist nicht auf \e[1;29mmain \e[3;31m - nach \e[1;29mtesting \e[3;31m deployen?"
|
||||
read -p "Bitte eingeben [N,y]: " ok
|
||||
[[ "$ok" =~ y|Y ]] || echo "Steige aus" && exit 0
|
||||
REPO_NAME='testing'
|
||||
echo "Die Funktion gibt es noch nicht - es kann nur main oder MAIN_VERSION gepackt werden :(" && exit
|
||||
fi
|
||||
|
||||
# we have to do the update process here because it may change the main-version.txt
|
||||
PACKAGE_UPDATE=$force_package_update
|
||||
if $no_package_update; then
|
||||
PACKAGE_UPDATE=false
|
||||
elif ! $force_package_update; then
|
||||
if [[ -f bin/package-update ]]; then
|
||||
read -p "Soll ein package-update gemacht werden? [N,y]: " _PU
|
||||
[[ "$_PU" =~ y|Y ]] && PACKAGE_UPDATE=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if $PACKAGE_UPDATE; then
|
||||
if [[ -f bin/package-update.d/configs ]]; then
|
||||
info "Edit configfiles in package-update.d/configs"
|
||||
while read cfgf; do
|
||||
[[ ! -f "$cfgf" ]] && erro "$cfgf does not exist" && continue
|
||||
read -p "Edit $cfgf? [N,y]: " _edok
|
||||
[[ "$_edok" =~ y|Y ]] || continue
|
||||
vi $cfgf
|
||||
git add $cfgf
|
||||
while [[ -z "$commit_msg" ]]; do
|
||||
read -p $(info "Commit Message: ") commit_msg
|
||||
done
|
||||
git commit -m "$commit_msg"
|
||||
done < bin/package-update.d/configs
|
||||
fi
|
||||
if [[ ! -z "$edit_config_files" ]]; then
|
||||
info "Edit configfiles from params (-e)"
|
||||
for cfgf in "${edit_config_files[@]}"; do
|
||||
[[ ! -f "$cfgf" ]] && erro "$cfgf does not exist" && continue
|
||||
vi $cfgf
|
||||
git add $cfgf
|
||||
while [[ -z "$commit_msg" ]]; do
|
||||
read -p $(info "Commit Message: ") commit_msg
|
||||
done
|
||||
git commit -m "$commit_msg"
|
||||
done
|
||||
fi
|
||||
|
||||
./bin/package-update 2>&1 | tee -a $temp_packageupdate
|
||||
|
||||
if [[ "${PIPESTATUS[0]}" != "0" ]]; then
|
||||
read -p "Das ging irgendwie schief (s. Ausgabe) - trotzdem packen? [N,y]: " proceed
|
||||
[[ "$proceed" =~ y|Y ]] || error "Steige aus" && exit 16
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
ARCHITECTURE="all"
|
||||
get_version() {
|
||||
[[ ! -z "$version" ]] && echo -n "" && return 0
|
||||
git tag | grep -Pe '^build-' | sort -V | tail -1 | sed 's/^build-//'
|
||||
}
|
||||
VERSION=$(get_version)
|
||||
|
||||
if [[ -z $VERSION ]]; then
|
||||
VERSION=${version-0.0.1}
|
||||
[[ ! -z "$MAIN_VERSION" ]] && VERSION="${MAIN_VERSION}-${VERSION}"
|
||||
update=0
|
||||
else
|
||||
# get "real" version without main version
|
||||
_update=1
|
||||
if [[ "$VERSION" =~ - ]]; then
|
||||
_MAIN_VERSION=$(echo $VERSION | perl -pe 's/^([^\-]+)-.*/\1/')
|
||||
VERSION=$(echo $VERSION | perl -pe 's/^[^\-]+-(\d+\.\d+\.\d+).*/\1/')
|
||||
if [[ ! -z "$MAIN_VERSION" ]]; then
|
||||
_HIGHER_VERSION=$((echo "$_MAIN_VERSION" && echo "$MAIN_VERSION") | sort -V | tail -1)
|
||||
[[ "$_HIGHER_VERSION" != "$MAIN_VERSION" ]] && echo "Main version aus file ist kleiner als die aus den tags ($MAIN_VERSION < $_MAIN_VERSION)" && exit 2
|
||||
if [[ "$_MAIN_VERSION" != "$MAIN_VERSION" ]]; then
|
||||
# Upgrade Main Version
|
||||
VERSION="${MAIN_VERSION}-0.0.1"
|
||||
_update=0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
update=$_update
|
||||
fi
|
||||
|
||||
if [ $update -eq 1 ]; then
|
||||
echo "Welche Art von Update?"
|
||||
echo "1) Major (x.0.0) - Für große Änderungen"
|
||||
echo "2) Minor (0.x.0) - Für neue Features"
|
||||
echo "3) Patch (0.0.x) - Für Bugfixes"
|
||||
read -p "Wähle (1-3): " update_type
|
||||
|
||||
IFS='.' read -r -a version_parts <<< "$VERSION"
|
||||
major="${version_parts[0]}"
|
||||
minor="${version_parts[1]}"
|
||||
patch="${version_parts[2]}"
|
||||
|
||||
[[ -z "$update_type" ]] && update_type=3
|
||||
|
||||
case $update_type in
|
||||
1) # major
|
||||
major=$((major + 1))
|
||||
minor=0
|
||||
patch=0
|
||||
;;
|
||||
2) # minor
|
||||
minor=$((minor + 1))
|
||||
patch=0
|
||||
;;
|
||||
3) # patch
|
||||
patch=$((patch + 1))
|
||||
;;
|
||||
esac
|
||||
|
||||
NEW_VERSION="${major}.${minor}.${patch}"
|
||||
[[ -z $MAIN_VERSION ]] || NEW_VERSION="${MAIN_VERSION}-${NEW_VERSION}"
|
||||
else
|
||||
NEW_VERSION=$VERSION
|
||||
fi
|
||||
|
||||
relevant=()
|
||||
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" =~ build- ]]; then
|
||||
echo -e "\e[1;31m$line\e[0m" 1>&2
|
||||
break
|
||||
fi
|
||||
relevant+=("$line") # Füge die relevante Zeile zum Array hinzu
|
||||
done < <(git log --oneline --decorate)
|
||||
|
||||
echo "$PACKAGE_NAME ($NEW_VERSION) stable; urgency=medium" > $temp_changelog
|
||||
echo "----------------------------------------------------------------------" >> $temp_changelog
|
||||
for line in "${relevant[@]}"; do
|
||||
echo -e "* $line\n" >> $temp_changelog
|
||||
done
|
||||
echo >> $temp_changelog
|
||||
if grep -qi 'extracting archive' $temp_packageupdate ; then
|
||||
grep -i "extracting archive" $temp_packageupdate | sed 's/extracting archive *//' >> $temp_changelog
|
||||
echo >> $temp_changelog
|
||||
fi
|
||||
echo >> $temp_changelog
|
||||
echo "-- $(git config user.name) <$(git config user.email)> $(date -R)" >> $temp_changelog
|
||||
echo "----------------------------------------------------------------------" >> $temp_changelog
|
||||
|
||||
cat debian/changelog >> $temp_changelog
|
||||
|
||||
BUILD_DIR="build"
|
||||
rm -rf $BUILDDIR
|
||||
DEBIAN_DIR="${BUILD_DIR}/DEBIAN"
|
||||
INSTALL_DIR="${BUILD_DIR}${INSTALLDIR}"
|
||||
|
||||
mkdir -p "${DEBIAN_DIR}"
|
||||
mkdir -p "${INSTALL_DIR}"
|
||||
|
||||
CONTROLFILE="${DEBIAN_DIR}/control"
|
||||
|
||||
cat > $CONTROLFILE << EOF
|
||||
Package: ${PACKAGE_NAME}
|
||||
Version: ${NEW_VERSION}
|
||||
Section: web
|
||||
Priority: optional
|
||||
Architecture: ${ARCHITECTURE}
|
||||
Pre-Depends: $DEPENDENCIES
|
||||
EOF
|
||||
if [[ ! -z "$SUGGESTS" ]]; then
|
||||
echo "Suggests: $SUGGESTS" >> $CONTROLFILE
|
||||
fi
|
||||
cat >> $CONTROLFILE << EOF
|
||||
Maintainer: $(git config user.name) <$(git config user.email)>
|
||||
Description: $DESCRIPTION
|
||||
EOF
|
||||
|
||||
|
||||
for inst_script in preinst conffiles; do
|
||||
[[ ! -f debscripts/$inst_script ]] && echo "No $inst_script - continue" 1>&2 && continue
|
||||
cp debscripts/$inst_script $DEBIAN_DIR
|
||||
chmod 755 $DEBIAN_DIR/$inst_script
|
||||
done
|
||||
postinst=debscripts/postinst
|
||||
POSTINST=$DEBIAN_DIR/postinst
|
||||
|
||||
echo "Create postinst"
|
||||
echo '#!/bin/bash' > $POSTINST
|
||||
find src/ -type f -path '*/etc/sudoers.d/*' -exec bash -c 'fn={};echo chown -v root:root ${fn/src/}' \; >> $POSTINST
|
||||
find src/ -type f -path '*/etc/sudoers.d/*' -exec bash -c 'fn={};echo chmod -v 440 ${fn/src/}' \; >> $POSTINST
|
||||
find src/ -type f -path '*/etc/cron.*/*' -exec bash -c 'fn={};echo chmod -v 700 ${fn/src/};' \; >> $POSTINST
|
||||
|
||||
if [[ -f $postinst ]]; then
|
||||
if head -n 1 $postinst | grep -q 'bash'; then
|
||||
echo "Extend postinst"
|
||||
cat $postinst >> $POSTINST
|
||||
else
|
||||
echo "no bash script - taking original"
|
||||
cat $postinst > $POSTINST
|
||||
fi
|
||||
fi
|
||||
chmod 755 $POSTINST
|
||||
|
||||
[[ -f debscripts/before-copy ]] && . debscripts/before-copy
|
||||
|
||||
if [[ -f debscripts/src-to-builddir ]]; then
|
||||
. debscripts/src-to-builddir
|
||||
else
|
||||
rsync -av --exclude .gitignore src/ $INSTALL_DIR
|
||||
fi
|
||||
|
||||
# find $INSTALL_DIR -path '*/etc/sudoers.d*' -type f -exec bash -c "sudo chown root:root {};sudo chmod 400 {};" \;
|
||||
|
||||
[[ -f debscripts/after-copy ]] && . debscripts/after-copy
|
||||
|
||||
cp $temp_changelog "${DEBIAN_DIR}/changelog"
|
||||
gzip -9 -n "${DEBIAN_DIR}/changelog"
|
||||
|
||||
distfile="dists/$REPO_NAME/main/binary-amd64/${PACKAGE_NAME}_${NEW_VERSION}_${ARCHITECTURE}.deb"
|
||||
mkdir -p "dists/$REPO_NAME/main/binary-amd64"
|
||||
|
||||
[[ -f debscripts/before-build ]] && . debscripts/before-build
|
||||
|
||||
dpkg-deb --build "${BUILD_DIR}" $distfile
|
||||
# ME=$(whoami)
|
||||
# sudo chown -R $ME:$ME $distfile $BUILD_DIR
|
||||
|
||||
[[ -f debscripts/after-build ]] && . debscripts/after-build
|
||||
|
||||
echo "Paket wurde erstellt: $distfile"
|
||||
|
||||
rm -rf "${BUILD_DIR}"
|
||||
|
||||
if [[ -z $DEBBUILD_ASSUME_YES ]] && ! $force; then
|
||||
read -p "Auf git-packages hochladen? [Y,n]: " upload
|
||||
[[ "$upload" =~ n|N ]] && exit 0
|
||||
fi
|
||||
|
||||
[[ -f debscripts/before-deploy ]] && . debscripts/before-deploy
|
||||
|
||||
. $(dirname $0)/deploy-package
|
||||
|
||||
[[ -f debscripts/after-deploy ]] && . debscripts/after-deploy
|
||||
|
||||
echo "$NEW_VERSION" > version.txt
|
||||
mv $temp_changelog debian/changelog
|
||||
git add version.txt debian/changelog
|
||||
git commit -m "Deploy $NEW_VERSION"
|
||||
git tag -a "build-$NEW_VERSION" -m "Deploy builded $NEW_VERSION"
|
||||
git push
|
||||
git push --tags
|
||||
Reference in New Issue
Block a user