File indexing completed on 2024-04-28 05:06:08

0001 #!/bin/sh
0002 #
0003 # unpack windows rpm's from opensuse download server, upload files to kde.org and file a related release ticket
0004 #
0005 # Author: Ralf Habacker <ralf.habacker@freenet.de>
0006 #
0007 # requirements:
0008 #
0009 #  osc - opensuse build service command line client
0010 #
0011 # syntax: release-windows-packages [<options>] <mode>
0012 #
0013 # run ./release-windows-packages to see all modes and options
0014 #
0015 NAME=kmymoney5
0016 # package name on download.kde.org
0017 RELEASE_NAME=kmymoney
0018 
0019 PACKAGENAME32=mingw32-$NAME
0020 ROOT32=windows\:mingw\:win32
0021 ARCHOUT32=i686-w64-mingw32
0022 use32=1
0023 
0024 PACKAGENAME64=mingw64-$NAME
0025 ROOT64=windows\:mingw\:win64
0026 ARCHOUT64=x86_64-w64-mingw32
0027 use64=1
0028 
0029 REPO=openSUSE_Leap_42.3
0030 SRCREPO=$REPO
0031 usesrc=0
0032 
0033 PHABURL=https://phabricator.kde.org
0034 oscoptions="-A https://api.opensuse.org"
0035 apitoken=cli-uxo23l4q5qrzoyscbz5kp4zcngqp
0036 options='projectPHIDs[]=PHID-PROJ-3qa4tomwgrmcmp4ym2ow'
0037 
0038 # abort on errors
0039 set -e
0040 
0041 echo2() { printf "%s\n" "$*" >&2; }
0042 
0043 which 7z >/dev/null 2>&1
0044 if test $? -ne 0; then
0045     echo "7z not found, run 'zypper install p7zip'"
0046     exit 1
0047 fi
0048 
0049 self=$(realpath $0)
0050 
0051 if ! test -d "work"; then
0052     mkdir work
0053 fi
0054 
0055 echo2 "running mode $1"
0056 dryrun=0
0057 update=0
0058 update_symlink=0
0059 curl=curl
0060 branch=stable
0061 
0062 # check options
0063 for var in "$@"; do
0064 case $var in
0065 --update-32) ## update i686 variant
0066         use64=0
0067         usesrc=0
0068         update=1
0069         shift
0070         ;;
0071 
0072 --update-64) ## update x86_64 variant
0073         use32=0
0074         usesrc=0
0075         update=1
0076         shift
0077         ;;
0078 
0079 --symlink) ## update 'latest' symbolic link
0080         update_symlink=1
0081         shift
0082         ;;
0083 
0084 --unstable) ## release unstable version
0085         branch=unstable
0086         ROOT32=home\:rhabacker\:branches\:windows\:mingw\:win32\:$NAME
0087         ROOT64=home\:rhabacker\:branches\:windows\:mingw\:win64\:$NAME
0088         shift
0089         ;;
0090 
0091 --dryrun) ## simulate upload only
0092         dryrun=1
0093         curl="echo curl"
0094         shift
0095         ;;
0096 esac
0097 done
0098 
0099 SRCROOT32=${ROOT32}
0100 SRCROOT64=${ROOT64}
0101 
0102 function clean() {
0103         rm -rf work/*
0104 }
0105 
0106 function download() {
0107         cd work
0108         rm -rf binaries
0109         if test $use32 -eq 1; then
0110                 osc $oscoptions getbinaries --multibuild-package=$PACKAGENAME32-installer $ROOT32 $PACKAGENAME32 $REPO x86_64
0111                 VERSION=$(find binaries/ -name "*$PACKAGENAME32-setup*" | sed "s,^.*$PACKAGENAME32-setup-,,g;s,-.*$,,g")
0112                 echo $VERSION > VERSION
0113         fi
0114         if test $use64 -eq 1; then
0115                 osc $oscoptions getbinaries --multibuild-package=$PACKAGENAME64-installer $ROOT64 $PACKAGENAME64 $REPO x86_64
0116                 VERSION=$(find binaries/ -name "*$PACKAGENAME64-setup*" | sed "s,^.*$PACKAGENAME64-setup-,,g;s,-.*$,,g")
0117                 echo $VERSION > VERSION
0118         fi
0119         cd ..
0120         if test $usesrc -eq 1; then
0121                 downloadsrc
0122         fi
0123         touch work/$1.finished
0124 }
0125 
0126 function getversion() {
0127         if ! test -f work/VERSION; then
0128                 echo "no version found"
0129                 exit 1;
0130         fi
0131         VERSION=$(cat work/VERSION)
0132 }
0133 
0134 function downloadsrc() {
0135         cd work
0136         # fetch source package
0137         src32pkg=$(osc $oscoptions ls -b -r $SRCREPO -a x86_64 $SRCROOT32 $PACKAGENAME32 | grep src)
0138         osc $oscoptions getbinaries --sources $SRCROOT32 $PACKAGENAME32 $SRCREPO x86_64 $src32pkg
0139         # we only need once source package
0140         #src64pkg=$(osc $oscoptions ls -b -r $SRCREPO -a x86_64 $SRCROOT64 mingw64-umbrello | grep src)
0141         #osc $oscoptions getbinaries --sources $SRCROOT64 mingw64-umbrello $SRCREPO x86_64 $src64pkg
0142         # fetch debug packages
0143         debug32pkg=$(osc $oscoptions ls -b -r $SRCREPO -a x86_64 $SRCROOT32 $PACKAGENAME32 | grep debug)
0144         osc $oscoptions getbinaries $SRCROOT32 $PACKAGENAME32 $SRCREPO x86_64 $debug32pkg
0145         if test -n "$ROOT64"; then
0146             debug64pkg=$(osc $oscoptions ls -b -r $SRCREPO -a x86_64 $SRCROOT64 $PACKAGENAME64 | grep debug)
0147             osc $oscoptions getbinaries $SRCROOT64 $PACKAGENAME64 $SRCREPO x86_64 $debug64pkg
0148         fi
0149         cd ..
0150         touch $1.finished
0151 }
0152 
0153 function unpack()  {
0154         getversion
0155         cd work
0156         files=$(cd binaries; find -name '*setup*' -o -name '*portable*' -o -name '*src*' -o -name '*debugpackage*' | grep "$VERSION" | sed 's,^.,binaries,g')
0157         if test -d tmp; then
0158                 rm -rf tmp
0159         fi
0160         mkdir -p tmp
0161         for i in $(echo $files); do
0162                 (cd tmp; rpm2cpio ../$i | cpio -idmv)
0163         done
0164         cd ..
0165         touch $1.finished
0166 }
0167 
0168 function movepackage() {
0169         cd work
0170         rm -rf out
0171         mkdir -p out
0172         find tmp/ -type f -name '*.exe' -exec cp {} out \;
0173         find tmp/ -type f -name '*.7z' -exec cp {} out \;
0174         find tmp/ -type f -name '*.xz' -exec cp {} out \;
0175         cd ..
0176         touch $1.finished
0177 }
0178 
0179 function repacksource() {
0180         # repackage source package
0181         srcfile=$(find work/tmp -name "$NAME*.xz")
0182         outfile=$(basename $srcfile | sed 's,\.tar\.xz,\.7z,g')
0183         (mkdir -p work/srctmp; cd work/srctmp; tar -xJf ../../$srcfile; 7za a ../out/$outfile *; cd ..; rm -rf srctmp)
0184         touch work/$1.finished
0185 }
0186 
0187 function createsha() {
0188         (cd work/out; find -type f -name '*.7z' -o -name '*.exe' -o -name '*.xz' | sed 's,\./,,g' | sort | xargs sha256sum > $NAME.sha256sum)
0189         touch work/$1.finished
0190 }
0191 
0192 function upload() {
0193         for i in $(find work/out -name '*.7z' -o -name '*.exe' -o -name '*.xz'); do
0194                 $curl -T $i ftp://upload.kde.org/incoming/
0195                 if test $? -ne 0; then
0196                         echo "upload failed"
0197                         exit 1
0198                 fi
0199         done
0200         touch work/$1.finished
0201 }
0202 
0203 function createdescription() {
0204         getversion
0205         description="Please move the $RELEASE_NAME related files which have been uploaded to upload.kde.org/incoming to download mirror '$branch/$RELEASE_NAME/$VERSION' location"
0206         if test $update -eq 1; then
0207                 description="$description and remove the old files from this directory."
0208         elif test $update_symlink -eq 1; then
0209                 description="$description and update the symbolic link '$branch/$RELEASE_NAME/latest' to '$branch/$RELEASE_NAME/$VERSION'."
0210         else
0211                 description="$description."
0212         fi
0213         sums=$(cat work/out/$NAME.sha256sum | gawk 'BEGIN { print "dir   shasum                                                            file"}  $2 ~ /mingw32/ { print "win32 " $0 } $2 ~ /mingw64/ { print "win64 " $0 } $2 ~ /\-src/ { print "src   " $0 }')
0214         echo -e "$description\n\n$sums" > work/description
0215         cat work/description
0216         touch work/$1.finished
0217 }
0218 
0219 function ticket() {
0220         getversion
0221         description=$(cat work/description)
0222         $curl $PHABURL/api/maniphest.createtask \
0223         -d api.token=$apitoken \
0224         -d "title=tarball move request for $branch/$RELEASE_NAME/$VERSION" \
0225         -d "description=$description" \
0226         -d "$options"
0227         touch work/$1.finished
0228 }
0229 
0230 function sf() {
0231         clean
0232         download
0233         unpack
0234         movepackage
0235         if test $usesrc -eq 1; then
0236                 repacksource
0237         fi
0238         createsha
0239         echo "All release related files are located in work/out"
0240         ls work/out
0241         touch work/$1.finished
0242 }
0243 
0244 function kde() {
0245         clean
0246         download
0247         unpack
0248         movepackage
0249         if test $usesrc -eq 1; then
0250                 repacksource
0251         fi
0252         createsha
0253         upload
0254         echo "Content for ticket creating:"
0255         createdescription
0256         echo run "$0 ticket" to submit ticket
0257         touch work/$1.finished
0258 }
0259 
0260 function help() {
0261         echo "syntax: release-windows-packages [<options>] <mode>"
0262         echo
0263         echo "options:"
0264         gawk '$0 ~ /^--[a-z].*) ##/ { sub(/) ##/,"",$0); a = $1; $1 = ""; printf("    %-20s  - %s\n",a, $0); }' $0
0265         echo
0266         echo "modes:"
0267         gawk '$0 ~ /^[a-z].*) ##/ { sub(/) ##/,"",$0); a = $1; $1 = ""; printf("    %-20s  - %s\n",a, $0); }' $0
0268 
0269 }
0270 
0271 case $1 in
0272 clean) ## clean working area
0273         clean;
0274         ;;
0275 
0276 download) ## download rpm packages
0277         download
0278         ;;
0279 
0280 downloadsrc) ## download source
0281         downloadsrc
0282         ;;
0283 
0284 unpack) ## unpack rpm files
0285         unpack
0286         ;;
0287 
0288 movepackage) ## move windows binary packages into upload folder
0289         movepackage
0290         ;;
0291 
0292 repacksource) ## repackage source tar ball to 7z
0293         repacksource
0294         ;;
0295 
0296 createsha) ## create sha256sums
0297         createsha
0298         ;;
0299 
0300 upload) ## upload files to staging area
0301         upload
0302         ;;
0303 
0304 createdescription) ## create ticket description
0305         createdescription
0306         ;;
0307 
0308 ticket) ## submit phabricator ticket
0309         ticket
0310         ;;
0311 
0312 sf) ## run all required targets for releasing on sourceforge
0313         sf
0314         ;;
0315 
0316 kde) ## run all required targets for releasing on download.kde.org
0317         kde
0318         ;;
0319 *)
0320         help
0321         ;;
0322 esac
0323 
0324 exit 0