retropkg 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #!/bin/sh
  2. # Slackware script to package the libretro cores for SBo.
  3. # The libretro git SlackBuilds are required for use.
  4. # Pacakges all of the libretro cores by default.
  5. # ./retropkg foo will package the foo core.
  6. # Copyright 2016-2018 orbea
  7. # All rights reserved.
  8. #
  9. # Redistribution and use of this script, with or without modification, is
  10. # permitted provided that the following conditions are met:
  11. #
  12. # 1. Redistributions of this script must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  16. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  18. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. REMOTE=${REMOTE:-ovhtoo:~/web/stuff/slackbuilds/src/libretro}
  26. SRCURL=${SRCURL:-http://ks392457.kimsufi.com/orbea/stuff/slackbuilds/src/libretro}
  27. GITURL=${GITURL:-https://raw.githubusercontent.com/libretro/libretro-super/master/dist/info}
  28. GITDIR=${GITDIR:-/media/gittings/orbea/SlackBuilds-git}
  29. OUTPUT=${OUTPUT:-/media/data/home/backup/SBo/libretro/gittings}
  30. SLKBLD=${SLKBLD:-/media/gittings/orbea/SlackBuilds}
  31. SRCDIR=${SRCDIR:-/media/data/home/src/SBo}
  32. SUBMIT=${SUBMIT:-/tmp/SBo_submit}
  33. SRC=${SRC:-/media/data/home/backup/SBo/libretro/src}
  34. set -e
  35. mkdir -p "$OUTPUT" "$SUBMIT" "$SRC"
  36. trap 'rm -rf -- $OUTPUT' EXIT
  37. core_info () {
  38. PRGNAM="$(sed -n 's/^PRGNAM=//p' "$core.info" | tr -d '\"')"
  39. BRANCH="$(sed -n 's/^BRANCH=//p' "$core.info" | tr -d '\"')"
  40. DOWNLOAD="$(sed -n 's/^DOWNLOAD=//p' "$core.info" | tr -d '\"' | sed 's/\s.*$//')"
  41. eval "LIBNAM=$(sed -n 's/^LIBNAM=//p' "$core.SlackBuild")"
  42. }
  43. core_libretro () {
  44. case "$PKGDIR" in
  45. libretro )
  46. COREDIR="$(basename "$(dirname "$(dirname "$(dirname "$core")")")")/libretro"
  47. ;;
  48. * )
  49. COREDIR="$PKGDIR"
  50. ;;
  51. esac
  52. }
  53. core_dir () {
  54. PKGDIR="$(basename "$(dirname "$(dirname "$core")")")"
  55. core_libretro
  56. NEWDIR=$GITDIR/$COREDIR
  57. SBODIR=$SLKBLD/$COREDIR
  58. SBO=$SRCDIR/$COREDIR
  59. }
  60. core_version () {
  61. COMMIT="$(git rev-parse --short HEAD)"
  62. DATE="$(git show -s --format=%ad --date=format:%Y.%m.%d)"
  63. VERSION="${DATE}_$COMMIT"
  64. }
  65. core_submodule () {
  66. if git config --file .gitmodules --name-only --get-regexp path >/dev/null 2>&1; then
  67. git submodule update --init
  68. fi
  69. }
  70. core_libnam () {
  71. case "$PRGNAM" in
  72. beetle-psx-libretro )
  73. PROFILE='psx psx_hw'
  74. CORECMD='$(printf %s $LIBNAM | sed "s/psx/$profile/")'
  75. ;;
  76. bsnes-libretro|bsnes-mercury )
  77. PROFILE='accuracy balanced performance'
  78. CORECMD='${LIBNAM}_${profile}_libretro'
  79. ;;
  80. libretro-samples )
  81. PROFILE="testaudio_callback testaudio_no_callback \\
  82. testaudio_playback_wav button_test cruzes testgl_compute_shaders \\
  83. testgl_ff testgl freebasic pascal_pong testsw testsw_vram test \\
  84. advanced_tests testvulkan_async_compute testvulkan"
  85. CORECMD='${profile}_libretro'
  86. ;;
  87. mame2014-libretro )
  88. PROFILE='mame mess ume'
  89. CORECMD='${profile}2014_libretro'
  90. ;;
  91. parallel-n64 )
  92. PROFILE='parallel_n64 parallel_n64_debug'
  93. CORECMD='${profile}_libretro'
  94. ;;
  95. * )
  96. PROFILE="$LIBNAM"
  97. CORECMD='$profile'
  98. ;;
  99. esac
  100. }
  101. core_curl () {
  102. eval "set -- $PROFILE"
  103. for profile do
  104. eval "CORENAM=$CORECMD"
  105. curl -O "$GITURL/$CORENAM.info"
  106. done
  107. }
  108. core_clone () {
  109. git clone --depth=1 -b "$BRANCH" "$DOWNLOAD" "$OUTPUT/$PRGNAM"
  110. cd -- "$OUTPUT/$PRGNAM"
  111. core_version
  112. core_submodule
  113. find . -name '.git*' | xargs rm -rf
  114. core_libnam
  115. core_curl
  116. cd - >/dev/null 2>&1
  117. ( cd "$OUTPUT"; rename "$PRGNAM" "$PRGNAM-$VERSION" "$PRGNAM" )
  118. }
  119. core_clean () {
  120. for src in $SRC/$PRGNAM-*.tar.xz; do
  121. if [ -f "$src" ]; then
  122. mv -- "$src" "$SRC/.old"
  123. rm -f -- "$SBO/$PRGNAM/$PRGNAM-*.tar.xz"
  124. rm -f -- "$SUBMIT/$PRGNAM-*.tar.gz"
  125. fi
  126. done
  127. }
  128. core_var () {
  129. SED_INFO="s|BRANCH=.*|VERSION=\"$VERSION\"|;s|DOWNLOAD=.*|DOWNLOAD=\"$SRCURL/$PRGNAM-$VERSION.tar.xz\"|"
  130. SED_MAINTAINER="s|MAINTAINER=.*|MAINTAINER=\"$MAINTAINER\"|"
  131. SED_BRANCH="s|BRANCH=.*|VERSION=\${VERSION:-$VERSION}|;s|# Copyright.*|# Copyright $(date +"%Y") $MAINTAINER $LOCATION|"
  132. SED_GIT='s|git clone.*|tar xvf $CWD/$PRGNAM-$VERSION.tar.xz|;s|_git|_SBo|'
  133. SED_MAKE='s|$PRGNAM-${VERSION}_$BRANCH-$ARCH|$PRGNAM-$VERSION-$ARCH|'
  134. SED_PRGNAM='s|rm -rf $PRGNAM|rm -rf $PRGNAM-$VERSION|;s|cd $PRGNAM|cd $PRGNAM-$VERSION|'
  135. SED_BUILD="s|^VERSION=.*|VERSION=\${VERSION:-$VERSION}|"
  136. SED_VERSION="s|VERSION=.*|VERSION=\"$VERSION\"|"
  137. SED_GITVERS='/DEBUG=$DEBUG/s/$/ GIT_VERSION="\${VERSION#*_}"/'
  138. SED_LIBNAM='/install -Dm0644 $LIBNAM.so/a install -Dm0644 $LIBNAM.info $PKG/usr/lib${LIBDIRSUFFIX}/libretro/info/$LIBNAM.info'
  139. MD5SUM=$(md5sum "$SRC/$PRGNAM-$VERSION.tar.xz" | cut -d ' ' -f 1)
  140. }
  141. core_sed () {
  142. sed -e "$SED_INFO;$SED_MAINTAINER" \
  143. -e '/DOWNLOAD=.*/a MD5SUM=""\nDOWNLOAD_x86_64=""\nMD5SUM_x86_64=""' \
  144. -i "$SBO/$PRGNAM/$PRGNAM.info"
  145. sed -e "$SED_BRANCH;$SED_GIT;$SED_MAKE;$SED_PRGNAM" \
  146. -e '/SRCNAM/d;/COMMIT/d;/DATE/d;/HEAD/d' \
  147. -e '/install -Dm0644 $LIBNAM.so/{n;N;N;N;d}' \
  148. -e "$SED_GITVERS;$SED_LIBNAM" \
  149. -i "$SBO/$PRGNAM/$PRGNAM.SlackBuild"
  150. }
  151. core_convert () {
  152. if [ ! -d "$SBO/$PRGNAM" ]; then
  153. cp -a "$NEWDIR/$PRGNAM" "$SBO"
  154. core_sed
  155. chmod 0755 "$SBO/$PRGNAM/$PRGNAM.SlackBuild"
  156. fi
  157. }
  158. core_new () {
  159. if [ ! -d "$SBODIR/$PRGNAM" ]; then
  160. core_convert
  161. mkdir -p "$SBODIR/$PRGNAM"
  162. DIFF="-uN"
  163. MSG="$(awk -F "[()]" '{ for (i=2; i<NF; i+=2) print $i }' \
  164. "$SBO/$PRGNAM/slack-desc" | head -1)"
  165. GIT="$COREDIR/$PRGNAM: Added ($MSG)."
  166. else
  167. DIFF="-u"
  168. GIT="$COREDIR/$PRGNAM: Upgraded to $VERSION."
  169. fi
  170. }
  171. core_hack () {
  172. # hack for bluemsx
  173. if grep -q '\\$' "$SBO/$PRGNAM/$PRGNAM.info"; then
  174. SED_HACK="s|$PRGNAM-.*.tar.xz.*|$PRGNAM-$VERSION.tar.xz \\\\|;s|MD5SUM=.*|MD5SUM=\"$MD5SUM \\\\|"
  175. # hack for x86_64 only scripts
  176. elif grep -q UNSUPPORTED "$SBO/$PRGNAM/$PRGNAM.info"; then
  177. SED_HACK="s|$PRGNAM-.*.tar.xz\"|$PRGNAM-$VERSION.tar.xz\"|;s|MD5SUM_x86_64=.*|MD5SUM_x86_64=\"$MD5SUM\"|"
  178. else
  179. SED_HACK="s|$PRGNAM-.*.tar.xz\"|$PRGNAM-$VERSION.tar.xz\"|;s|MD5SUM=.*|MD5SUM=\"$MD5SUM\"|"
  180. fi
  181. }
  182. core_newline () {
  183. for file in $(find "$SBO/$PRGNAM" -type f -exec grep -Iq . {} \; -and -print); do
  184. if [ -s "$file" ] && [ "$(tail -c1 "$file"; echo x)" != $'\nx' ]; then
  185. sed -i '$a\' "$file"
  186. fi
  187. done
  188. }
  189. core_date () {
  190. copyright="$(grep '# Copyright' "$SBO/$PRGNAM/$PRGNAM.SlackBuild")"
  191. year="$(date +'%Y')"
  192. prev="$((year-1))"
  193. case "$copyright" in
  194. *$year* )
  195. return
  196. ;;
  197. *-$prev* )
  198. new_copy="$(printf %s "$copyright" | sed "s/-${prev}/-${year}/")"
  199. ;;
  200. *$prev* )
  201. new_copy="$(printf %s "$copyright" | sed "s/${prev}/${prev}-${year}/")"
  202. ;;
  203. esac
  204. sed -i "s|$copyright|$new_copy|" "$SBO/$PRGNAM/$PRGNAM.SlackBuild"
  205. }
  206. core_edit () {
  207. core_var
  208. core_new
  209. core_hack
  210. core_newline
  211. core_date
  212. sed -i "$SED_BUILD" "$SBO/$PRGNAM/$PRGNAM.SlackBuild"
  213. sed -i "$SED_VERSION;$SED_HACK" "$SBO/$PRGNAM/$PRGNAM.info"
  214. }
  215. core_commit () {
  216. ( cd -- "$SBO"
  217. diff $DIFF "$SBODIR/$PRGNAM" "$PRGNAM" | \
  218. tee "$OUTPUT/$PRGNAM.patch" >/dev/null 2>&1
  219. )
  220. ( cd -- "$SBODIR/$PRGNAM"
  221. patch -p1 -i "$OUTPUT/$PRGNAM.patch"
  222. git add .
  223. git commit -m "$GIT"
  224. )
  225. }
  226. core_submit () {
  227. cp -a "$SBODIR/$PRGNAM" "$SUBMIT"
  228. ( cd "$SUBMIT"
  229. chmod 755 "$PRGNAM/$PRGNAM.SlackBuild"
  230. tar cvzf "$PRGNAM.tar.gz" "$PRGNAM" >/dev/null 2>&1
  231. rm -rf "$PRGNAM"
  232. printf %s\\n "Uploading $PRGNAM-$VERSION.tar.xz now..."
  233. scp "$SRC/$PRGNAM-$VERSION.tar.xz" "$REMOTE"
  234. )
  235. }
  236. core_pkg () {
  237. if [ ! -f "$SRC/$PRGNAM-$VERSION.tar.xz" ]; then
  238. core_clean
  239. printf %s\\n "Compressing $PRGNAM-$VERSION.tar.xz now..."
  240. ( cd "$OUTPUT"
  241. tar cf - "$PRGNAM-$VERSION" | xz -c9 - > "$SRC/$PRGNAM-$VERSION.tar.xz"
  242. )
  243. core_edit
  244. cp -a "$SRC/$PRGNAM-$VERSION.tar.xz" "$SBO/$PRGNAM"
  245. core_commit
  246. core_submit
  247. fi
  248. }
  249. core_name () {
  250. if [ -z "$1" ]; then
  251. CORE="*"
  252. INFO="games/libretro"
  253. else
  254. CORE="$1"
  255. INFO=""
  256. fi
  257. }
  258. core_all () {
  259. for core in $(find "$GITDIR/$INFO" -type f -name "$CORE.info" | rev | \
  260. cut -f2 -d"." | rev | sort); do
  261. core_info
  262. core_dir
  263. core_clone
  264. core_pkg
  265. done
  266. }
  267. core_notify () {
  268. if [ -x /usr/bin/notify-send ]; then
  269. notify-send 'Libertro cores are ready to send to SBo'
  270. else
  271. echo 'Liberetro cores are ready to send to SBo.'
  272. fi
  273. }
  274. core_name "$1"
  275. core_all
  276. core_notify