arxpkg 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #!/bin/sh
  2. # Slackware script to package programs from git for SBo.
  3. # The git SlackBuilds is required for use.
  4. # https://notabug.org/orbea/SlackBuilds-git
  5. # Copyright 2016 orbea
  6. # All rights reserved.
  7. #
  8. # Redistribution and use of this script, with or without modification, is
  9. # permitted provided that the following conditions are met:
  10. #
  11. # 1. Redistributions of this script must retain the above copyright
  12. # notice, this list of conditions and the following disclaimer.
  13. #
  14. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  15. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  17. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  22. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  23. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. # Dependencies:
  25. # -------------
  26. # awk
  27. # coreutils
  28. # findutils
  29. # diffutils
  30. # git
  31. # grep
  32. # openssh
  33. # patch
  34. # sed
  35. # tar
  36. # xz
  37. #
  38. # Optional:
  39. # ---------
  40. # libnotify
  41. #
  42. REMOTE=${REMOTE:-ovhtoo:~/web/stuff/slackbuilds/src}
  43. SRCURL=${SRCURL:-http://ks392457.kimsufi.com/orbea/stuff/slackbuilds/src}
  44. GITDIR=${GITDIR:-/media/gittings/orbea/SlackBuilds-git}
  45. OUTPUT=${OUTPUT:-/media/data/home/backup/SBo/gittings}
  46. SLKBLD=${SLKBLD:-/media/gittings/orbea/SlackBuilds}
  47. SRCDIR=${SRCDIR:-/media/data/home/src/SBo}
  48. SUBMIT=${SUBMIT:-/tmp/SBo_submit}
  49. SRC=${SRC:-/media/data/home/backup/SBo/src}
  50. set -e
  51. mkdir -p $OUTPUT $SUBMIT $SRC
  52. trap 'rm -rf $OUTPUT' EXIT
  53. arx_info () {
  54. PRGNAM="$(sed -n 's/^PRGNAM=//p' $arx.info | tr -d '\"')"
  55. BRANCH="$(sed -n 's/^BRANCH=//p' $arx.info | tr -d '\"')"
  56. DOWNLOAD="$(sed -n 's/^DOWNLOAD=//p' $arx.info | tr -d '\"' | sed 's/\s.*$//')"
  57. }
  58. arx_dir () {
  59. PKGDIR=$(basename $(dirname $(dirname $arx)))
  60. NEWDIR=$GITDIR/$PKGDIR
  61. SBODIR=$SLKBLD/$PKGDIR
  62. SBO=$SRCDIR/$PKGDIR
  63. }
  64. arx_version () {
  65. COMMIT="$(git rev-parse --short HEAD)"
  66. DATE="$(git show -s --format=%ad --date=format:%Y.%m.%d)"
  67. VERSION="${DATE}_$COMMIT"
  68. }
  69. arx_submodule () {
  70. if git config --file .gitmodules --name-only --get-regexp path 2>&1 >/dev/null; then
  71. git submodule update --init
  72. fi
  73. }
  74. arx_clone () {
  75. git clone --depth=1 -b "$BRANCH" "$DOWNLOAD" "$OUTPUT/$PRGNAM"
  76. cd -- "$OUTPUT/$PRGNAM"
  77. arx_version
  78. arx_submodule
  79. find . -name ".git*" | xargs rm -rf
  80. cd - 2>&1 >/dev/null
  81. ( cd $OUTPUT; rename $PRGNAM $PRGNAM-$VERSION $PRGNAM )
  82. }
  83. arx_clean () {
  84. if [ -f $SRC/$PRGNAM-*.tar.xz ]; then
  85. mv $SRC/$PRGNAM-*.tar.xz $SRC/.old
  86. rm -f $SBO/$PRGNAM/$PRGNAM-*.tar.xz
  87. rm -f $SUBMIT/$PRGNAM-*.tar.gz
  88. fi
  89. }
  90. arx_var () {
  91. SED_INFO="s|BRANCH=.*|VERSION=\"$VERSION\"|;s|DOWNLOAD=.*|DOWNLOAD=\"$SRCURL/$PRGNAM-$VERSION.tar.xz\"|"
  92. SED_MAINTAINER="s|MAINTAINER=.*|MAINTAINER=\"$MAINTAINER\"|"
  93. SED_BRANCH="s|BRANCH=.*|VERSION=\${VERSION:-$VERSION}|;s|# Copyright.*|# Copyright $(date +"%Y") $MAINTAINER $LOCATION|"
  94. SED_GIT='s|git clone.*|tar xvf $CWD/$PRGNAM-$VERSION.tar.xz|;s|_git|_SBo|'
  95. SED_MAKE='s|$PRGNAM-${VERSION}_$BRANCH-$ARCH|$PRGNAM-$VERSION-$ARCH|'
  96. SED_PRGNAM='s|rm -rf $PRGNAM|rm -rf $PRGNAM-$VERSION|;s|cd $PRGNAM|cd $PRGNAM-$VERSION|'
  97. SED_BUILD="s|VERSION=.*|VERSION=\${VERSION:-$VERSION}|"
  98. SED_VERSION="s|VERSION=.*|VERSION=\"$VERSION\"|;s|$PRGNAM-.*.tar.xz\"|$PRGNAM-$VERSION.tar.xz\"|"
  99. MD5SUM=$(md5sum $SRC/$PRGNAM-$VERSION.tar.xz | cut -d ' ' -f 1)
  100. }
  101. arx_sed () {
  102. sed -i "$SED_INFO;$SED_MAINTAINER" $SBO/$PRGNAM/$PRGNAM.info
  103. sed -i '/DOWNLOAD=.*/a MD5SUM=""\nDOWNLOAD_x86_64=""\nMD5SUM_x86_64=""' $SBO/$PRGNAM/$PRGNAM.info
  104. sed -i "$SED_BRANCH;$SED_GIT;$SED_MAKE;$SED_PRGNAM" $SBO/$PRGNAM/$PRGNAM.SlackBuild
  105. sed -i '/COMMIT/d;/DATE/d;/HEAD/d' $SBO/$PRGNAM/$PRGNAM.SlackBuild
  106. }
  107. arx_convert () {
  108. if [ ! -d $SBO/$PRGNAM ]; then
  109. cp -a $NEWDIR/$PRGNAM $SBO
  110. arx_sed
  111. chmod 755 $SBO/$PRGNAM/$PRGNAM.SlackBuild
  112. fi
  113. }
  114. arx_new () {
  115. if [ ! -d $SBODIR/$PRGNAM ]; then
  116. arx_convert
  117. mkdir -p $SBODIR/$PRGNAM
  118. DIFF="-uN"
  119. MSG=$(awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' $SBO/$PRGNAM/slack-desc | head -1)
  120. GIT="$PKGDIR/$PRGNAM: Added ($MSG)"
  121. else
  122. DIFF="-u"
  123. GIT="$PKGDIR/$PRGNAM: Upgraded to $VERSION"
  124. fi
  125. }
  126. arx_hack () {
  127. # hack for x86_64 only scripts
  128. if grep -q 'DOWNLOAD="UNSUPPORTED"' $SBO/$PRGNAM/$PRGNAM.info; then
  129. SED_HACK="s|MD5SUM_x86_64=.*|MD5SUM_x86_64=\"$MD5SUM\"|"
  130. else
  131. SED_HACK="s|MD5SUM=.*|MD5SUM=\"$MD5SUM\"|"
  132. fi
  133. }
  134. arx_newline () {
  135. for file in $(find $SBO/$PRGNAM -type f -exec grep -Iq . {} \; -and -print); do
  136. if [ -s "$file" ] && [ "$(tail -c1 "$file"; echo x)" != $'\nx' ]; then
  137. sed -i '$a\' $file
  138. fi
  139. done
  140. }
  141. arx_date () {
  142. copyright="$(grep '# Copyright' $SBO/$PRGNAM/$PRGNAM.SlackBuild)"
  143. year="$(date +'%Y')"
  144. prev="$((year-1))"
  145. case "$copyright" in
  146. *$year* ) return ;;
  147. *-$prev* ) new_copy="$(printf %s "$copyright" | sed "s/-${prev}/-${year}/")" ;;
  148. *$prev* ) new_copy="$(printf %s "$copyright" | sed "s/${prev}/${prev}-${year}/")" ;;
  149. esac
  150. sed -i "s|$copyright|$new_copy|" $SBO/$PRGNAM/$PRGNAM.SlackBuild
  151. }
  152. arx_edit () {
  153. arx_var
  154. arx_new
  155. arx_hack
  156. arx_newline
  157. arx_date
  158. sed -i "$SED_BUILD" $SBO/$PRGNAM/$PRGNAM.SlackBuild
  159. sed -i "$SED_VERSION;$SED_HACK" $SBO/$PRGNAM/$PRGNAM.info
  160. }
  161. arx_commit () {
  162. ( cd $SBO; diff $DIFF $SBODIR/$PRGNAM $PRGNAM | tee $OUTPUT/$PRGNAM.patch 2>&1 >/dev/null )
  163. cd $SBODIR/$PRGNAM
  164. patch -p1 -i $OUTPUT/$PRGNAM.patch
  165. git add .
  166. git commit -m "$GIT"
  167. cd - 2>&1 >/dev/null
  168. }
  169. arx_submit () {
  170. cp -a $SBODIR/$PRGNAM $SUBMIT
  171. cd $SUBMIT
  172. chmod 755 $PRGNAM/$PRGNAM.SlackBuild
  173. tar cvzf $PRGNAM.tar.gz $PRGNAM 2>&1 >/dev/null
  174. rm -rf $PRGNAM
  175. scp $SRC/$PRGNAM-$VERSION.tar.xz $REMOTE
  176. cd - 2>&1 >/dev/null
  177. }
  178. arx_pkg () {
  179. if [ ! -f $SRC/$PRGNAM-$VERSION.tar.xz ]; then
  180. arx_clean
  181. echo "Compressing $PRGNAM-$VERSION.tar.xz now..."
  182. cd $OUTPUT; tar cf - $PRGNAM-$VERSION | xz -c9 - > $SRC/$PRGNAM-$VERSION.tar.xz; cd - 2>&1 >/dev/null
  183. arx_edit
  184. cp -a $SRC/$PRGNAM-$VERSION.tar.xz $SBO/$PRGNAM
  185. arx_commit
  186. arx_submit
  187. fi
  188. }
  189. arx_name () {
  190. if [ ! -z $1 ]; then
  191. ARX="$1"
  192. else
  193. echo "Specify the program you want to package with ./arxpkg foo"
  194. exit 1
  195. fi
  196. }
  197. arx_all () {
  198. for arx in $(find $GITDIR -type f -name "$ARX.info" | rev | cut -f2 -d"." | rev); do
  199. arx_info
  200. arx_dir
  201. arx_clone
  202. arx_pkg
  203. done
  204. }
  205. arx_notify () {
  206. if [ -x /usr/bin/notify-send ]; then
  207. notify-send "$PRGNAM is ready to send to SBo"
  208. else
  209. echo "$PRGNAM is ready to send to SBo"
  210. fi
  211. }
  212. arx_name $1
  213. arx_all
  214. arx_notify