Advertisement
Guest User

Untitled

a guest
Oct 18th, 2023
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.28 KB | None | 0 0
  1. From b6baef10369cb6fdd1980968845535addbe8ef05 Mon Sep 17 00:00:00 2001
  2. From: Brli <brli@chakralinux.org>
  3. Date: Wed, 18 Oct 2023 17:56:21 +0800
  4. Subject: [PATCH] pkgre +1
  5.  
  6. 1. replace variables with built-in ones
  7. 2. determine mode of files in package() phase instead of git repository
  8. 3. sed files in prepare() phase
  9. 4. complementary with shellcheck
  10. 5. directly install to files instead of create directory then install
  11. 6. change from tab to space
  12. 7. replace architecture-specific variables with $CARCH
  13. ---
  14. .SRCINFO | 17 ++++------
  15. PKGBUILD | 91 ++++++++++++++++++++------------------------------
  16. tor-browser.in | 35 +++++++++++--------
  17. 3 files changed, 64 insertions(+), 79 deletions(-)
  18. mode change 100755 => 100644 tor-browser.in
  19.  
  20. diff --git a/.SRCINFO b/.SRCINFO
  21. index 60b16d6..e07bdb8 100644
  22. --- a/.SRCINFO
  23. +++ b/.SRCINFO
  24. @@ -1,7 +1,7 @@
  25. pkgbase = tor-browser-bin
  26. pkgdesc = Tor Browser Bundle: anonymous browsing using Firefox and Tor
  27. pkgver = 13.0
  28. - pkgrel = 2
  29. + pkgrel = 3
  30. url = https://www.torproject.org/projects/torbrowser.html
  31. install = tor-browser.install
  32. arch = i686
  33. @@ -28,24 +28,19 @@ pkgbase = tor-browser-bin
  34. optdepends = libnotify: Gnome dialog boxes
  35. provides = tor-browser
  36. conflicts = tor-browser
  37. - noextract = tor-browser-linux-i686-13.0.tar.xz
  38. noextract = tor-browser-linux-x86_64-13.0.tar.xz
  39. + source = https://dist.torproject.org/torbrowser/13.0/tor-browser-linux-x86_64-13.0.tar.xz
  40. + source = https://dist.torproject.org/torbrowser/13.0/tor-browser-linux-x86_64-13.0.tar.xz.asc
  41. source = tor-browser.desktop.in
  42. source = tor-browser.in
  43. source = tor-browser.png
  44. source = tor-browser.svg
  45. validpgpkeys = EF6E286DDA85EA2A4BA7DE684E2C6E8793298290
  46. + sha256sums = cdd98f6e6268e450e83a3a1bfbd4c30af0a02a02c7bcb8b76ce32171983c0d53
  47. + sha256sums = SKIP
  48. sha256sums = 5dd2b61bd4edf4d1499a81127f97a1de7ec272a885df97331b61969a5a07f05f
  49. - sha256sums = 1143d23e347605b498b3793992e84e95563efd94aa4da17837b37104a6d4a090
  50. + sha256sums = 41895ac8bd074af57579d9dece1ea66b9c3905d8395d66a5590c6dad554e0199
  51. sha256sums = f25ccf68b47f5eb14c6fec0664c74f30ea9c6c58d42fc6abac3b64670aaa3152
  52. sha256sums = 7b28b5dbe8ad573bb46e61b4d542b33e01ca240825ca640b4893fee6203b021f
  53. - source_i686 = https://dist.torproject.org/torbrowser/13.0/tor-browser-linux-i686-13.0.tar.xz
  54. - source_i686 = https://dist.torproject.org/torbrowser/13.0/tor-browser-linux-i686-13.0.tar.xz.asc
  55. - sha256sums_i686 = 1e5bf1d82e0317fc1c1e8f444be83d51480d1460e8916e4e017dc578ebd1f9f6
  56. - sha256sums_i686 = SKIP
  57. - source_x86_64 = https://dist.torproject.org/torbrowser/13.0/tor-browser-linux-x86_64-13.0.tar.xz
  58. - source_x86_64 = https://dist.torproject.org/torbrowser/13.0/tor-browser-linux-x86_64-13.0.tar.xz.asc
  59. - sha256sums_x86_64 = cdd98f6e6268e450e83a3a1bfbd4c30af0a02a02c7bcb8b76ce32171983c0d53
  60. - sha256sums_x86_64 = SKIP
  61.  
  62. pkgname = tor-browser-bin
  63. diff --git a/PKGBUILD b/PKGBUILD
  64. index 076aefe..a7023f2 100644
  65. --- a/PKGBUILD
  66. +++ b/PKGBUILD
  67. @@ -1,3 +1,4 @@
  68. +# shellcheck disable=SC2034
  69. # Maintainer: grufo <madmurphy333 AT gmail DOT com>
  70. # Maintainer: Sebastian Jug <seb AT stianj DOT ug>
  71. # Contributor: midgard <arch.midgard AT janmaes DOT com>
  72. @@ -19,96 +20,76 @@
  73. _appname='tor-browser'
  74. pkgname="${_appname}-bin"
  75. pkgver='13.0'
  76. -pkgrel=2
  77. +pkgrel=3
  78. pkgdesc='Tor Browser Bundle: anonymous browsing using Firefox and Tor'
  79. url='https://www.torproject.org/projects/torbrowser.html'
  80. arch=('i686' 'x86_64')
  81. license=('GPL')
  82. depends=('libxt' 'startup-notification' 'mime-types' 'dbus-glib'
  83. - 'alsa-lib' 'desktop-file-utils' 'hicolor-icon-theme'
  84. - 'libvpx' 'icu' 'libevent' 'nss' 'hunspell' 'sqlite')
  85. + 'alsa-lib' 'desktop-file-utils' 'hicolor-icon-theme'
  86. + 'libvpx' 'icu' 'libevent' 'nss' 'hunspell' 'sqlite')
  87. optdepends=('zenity: simple dialog boxes'
  88. - 'kdialog: KDE dialog boxes'
  89. - 'gst-plugins-good: H.264 video'
  90. - 'gst-libav: H.264 video'
  91. - 'libpulse: PulseAudio audio driver'
  92. - 'libnotify: Gnome dialog boxes')
  93. + 'kdialog: KDE dialog boxes'
  94. + 'gst-plugins-good: H.264 video'
  95. + 'gst-libav: H.264 video'
  96. + 'libpulse: PulseAudio audio driver'
  97. + 'libnotify: Gnome dialog boxes')
  98. provides=("${_appname}")
  99. conflicts=("${_appname}")
  100. install="${_appname}.install"
  101. validpgpkeys=('EF6E286DDA85EA2A4BA7DE684E2C6E8793298290')
  102.  
  103. -_tag_i686='linux-i686'
  104. -_tag_x86_64='linux-x86_64'
  105. _urlbase="https://dist.torproject.org/torbrowser/${pkgver}"
  106. -_archstr=$([[ "${CARCH}" == 'x86_64' ]] && echo -n "${_tag_x86_64}" || echo -n "${_tag_i686}")
  107.  
  108. # Syntax: _dist_checksum 'linux-i686'/'linux-x86_64'
  109. _dist_checksum() {
  110. -
  111. - (curl --silent --fail "${_urlbase}/sha256sums-signed-build.txt" || \
  112. - curl --silent --fail "${_urlbase}/sha256sums-unsigned-build.txt") | \
  113. - awk "/${_appname}-${1}-${pkgver}.tar.xz$/"'{print $1}'
  114. + (curl --silent --fail "${_urlbase}/sha256sums-signed-build.txt" || \
  115. + curl --silent --fail "${_urlbase}/sha256sums-unsigned-build.txt") | \
  116. + awk "/${_appname}-${1}-${pkgver}.tar.xz$/"'{print $1}'
  117.  
  118. }
  119.  
  120. # Make a string suitable for `sed`, by escaping `[]/&$.*^\` - syntax: `_sed_escape STRING`
  121. _sed_escape() {
  122. - echo "${1}" | sed 's/[]\/&.*$^[]/\\&/g'
  123. + echo "${1}" | sed 's/[]\/&.*$^[]/\\&/g'
  124. }
  125.  
  126. -source_i686=("${_urlbase}/${_appname}-${_tag_i686}-${pkgver}.tar.xz"{,.asc})
  127. -source_x86_64=("${_urlbase}/${_appname}-${_tag_x86_64}-${pkgver}.tar.xz"{,.asc})
  128. -source=("${_appname}.desktop.in"
  129. - "${_appname}.in"
  130. - "${_appname}.png"
  131. - "${_appname}.svg")
  132. +source=("${_urlbase}/${_appname}-linux-${CARCH}-${pkgver}.tar.xz"{,.asc}
  133. + "${_appname}.desktop.in"
  134. + "${_appname}.in"
  135. + "${_appname}.png"
  136. + "${_appname}.svg")
  137.  
  138. ### IMPORTANT #################################################################
  139. # No need for `makepkg -g`: the following sha256sums¸don't need to be updated #
  140. # with each release, everything is done automatically! Leave them like this! #
  141. ###############################################################################
  142. -sha256sums=('5dd2b61bd4edf4d1499a81127f97a1de7ec272a885df97331b61969a5a07f05f'
  143. - '1313484fc0572d82067f5671327540fcab6747fd2d187f216e1fc8edf3581509'
  144. +sha256sums=("$(_dist_checksum linux-${CARCH})"
  145. + 'SKIP'
  146. + '5dd2b61bd4edf4d1499a81127f97a1de7ec272a885df97331b61969a5a07f05f'
  147. + '41895ac8bd074af57579d9dece1ea66b9c3905d8395d66a5590c6dad554e0199'
  148. 'f25ccf68b47f5eb14c6fec0664c74f30ea9c6c58d42fc6abac3b64670aaa3152'
  149. '7b28b5dbe8ad573bb46e61b4d542b33e01ca240825ca640b4893fee6203b021f')
  150. -sha256sums_i686=("$(_dist_checksum "${_tag_i686}")"
  151. - 'SKIP')
  152. -sha256sums_x86_64=("$(_dist_checksum "${_tag_x86_64}")"
  153. - 'SKIP')
  154. -
  155. -noextract=("${_appname}-${_tag_i686}-${pkgver}.tar.xz"
  156. - "${_appname}-${_tag_x86_64}-${pkgver}.tar.xz")
  157. -
  158. -package() {
  159.  
  160. - cd "${srcdir}"
  161. +noextract=("${_appname}-linux-${CARCH}-${pkgver}.tar.xz")
  162.  
  163. - local _sed_subst="
  164. - s/@PACKAGE_NAME@/$(_sed_escape "${_appname}")/g
  165. - s/@PACKAGE_VERSION@/$(_sed_escape "${pkgver}")/g
  166. - s/@PACKAGE_RELEASE@/$(_sed_escape "${pkgrel}")/g
  167. - s/@PACKAGE_ARCH@/$(_sed_escape "${_archstr}")/g
  168. - "
  169. +prepare() {
  170. + sed -i "s/@PACKAGE_NAME@/${_appname}/g
  171. + s/@PACKAGE_VERSION@/${pkgver}/g
  172. + s/@PACKAGE_RELEASE@/${pkgrel}/g
  173. + s/@PACKAGE_ARCH@/linux-${CARCH}/g" "${_appname}"{,.desktop}.in
  174. +}
  175.  
  176. - install -dm755 "${pkgdir}/usr/bin"
  177. - sed "${_sed_subst}" "${_appname}.in" > "${pkgdir}/usr/bin/${_appname}"
  178. - chmod +x "${pkgdir}/usr/bin/${_appname}"
  179. +package() {
  180. + install -Dm755 "${srcdir}/${_appname}.in" "${pkgdir}/usr/bin/${_appname}"
  181.  
  182. - install -dm755 \
  183. - "${pkgdir}/usr/share/icons/hicolor/scalable/apps" \
  184. - "${pkgdir}/usr/share/icons/hicolor/128x128/apps"
  185. + install -Dm644 "${srcdir}/${_appname}.png" "${pkgdir}/usr/share/icons/hicolor/128x128/apps/${_appname}.png"
  186. + install -Dm644 "${srcdir}/${_appname}.svg" "${pkgdir}/usr/share/icons/hicolor/scalable/apps/${_appname}.svg"
  187.  
  188. - install -Dm644 "${srcdir}/${_appname}.png" "${pkgdir}/usr/share/icons/hicolor/128x128/apps/${_appname}.png"
  189. - install -Dm644 "${srcdir}/${_appname}.svg" "${pkgdir}/usr/share/icons/hicolor/scalable/apps/${_appname}.svg"
  190. + install -Dm644 "${srcdir}/${_appname}.desktop.in" "${pkgdir}/usr/share/applications/${_appname}.desktop"
  191.  
  192. - install -dm755 "${pkgdir}/usr/share/applications"
  193. - sed "${_sed_subst}" "${_appname}.desktop.in" > \
  194. - "${pkgdir}/usr/share/applications/${_appname}.desktop"
  195.  
  196. - install -Dm444 "${_appname}-${_archstr}-${pkgver}.tar.xz" \
  197. - "${pkgdir}/opt/${_appname}/${_appname}-${_archstr}-${pkgver}.tar.xz"
  198. + install -Dm444 "${_appname}-linux-${CARCH}-${pkgver}.tar.xz" \
  199. + "${pkgdir}/opt/${_appname}/${_appname}-linux-${CARCH}-${pkgver}.tar.xz"
  200.  
  201. }
  202. -
  203. -
  204. diff --git a/tor-browser.in b/tor-browser.in
  205. old mode 100755
  206. new mode 100644
  207. index ebdaf5d..4dee26e
  208. --- a/tor-browser.in
  209. +++ b/tor-browser.in
  210. @@ -59,9 +59,11 @@ _inform_() {
  211. # syntax: _notify_ "${TITLE}" "${MESSAGE}"
  212. _notify_() {
  213.  
  214. - which notify-send 2>/dev/null && notify-send \
  215. - --app-name="${_TB_PKGNAME_}" --icon="${_TB_PKGNAME_}" "${1}" \
  216. - "${2}" || echo -e "${0}: [${1}] ${2}" >&2
  217. + if ! notify-send --app-name="${_TB_PKGNAME_}" \
  218. + --icon="${_TB_PKGNAME_}" "${1}" "${2}"
  219. + then
  220. + echo -e "${0}: [${1}] ${2}" >&2
  221. + fi
  222.  
  223. }
  224.  
  225. @@ -71,7 +73,7 @@ _compare_ver_() {
  226.  
  227. [[ "${1}" != "${2}" ]] || return 1
  228.  
  229. - [[ "${1}" == "`echo -e "${1}\n${2}" | sort -V | head -n1`" ]]
  230. + [[ "${1}" == "$(echo -e "${1}\n${2}" | sort -V | head -n1)" ]]
  231.  
  232. }
  233.  
  234. @@ -84,18 +86,22 @@ _refresh_local_() {
  235. local DIR_IS_KEPT=0
  236.  
  237. if [[ -d "${KEEP_DIR}" ]]; then
  238. - [[ -d "${KEPT_DIR}" ]] && rm -rf "${KEPT_DIR}" || mkdir -p "${CACHE_DIR}"
  239. + if [[ -d "${KEPT_DIR}" ]]; then
  240. + rm -rf "${KEPT_DIR}"; else
  241. + mkdir -p "${CACHE_DIR}"
  242. + fi
  243. mv "${KEEP_DIR}" "${KEPT_DIR}"
  244. echo "${0}: Preserving files in ${KEPT_DIR}/." >> "${_TB_LOG_FILE_}"
  245. DIR_IS_KEPT=1
  246. fi
  247.  
  248. echo "${0}: Extracting files to ${_TB_APP_DIR_}." >> "${_TB_LOG_FILE_}"
  249. - rm -rf "${_TB_APP_DIR_}"/*
  250. + rm -rf "${_TB_APP_DIR_:?}"/*
  251.  
  252. tar -xJf "/opt/${_TB_PKGNAME_}/tor-browser-${_TB_ARCH_}-${_TB_VERSION_}.tar.xz" \
  253. --strip-components=1 -C "${_TB_APP_DIR_}" >> \
  254. - "${_TB_LOG_FILE_}" 2>&1 && _notify_ 'Tor Browser' \
  255. + "${_TB_LOG_FILE_}" 2>&1
  256. + _notify_ 'Tor Browser' \
  257. 'A new version of Tor Browser has been installed' || \
  258. _inform_ 'Error' \
  259. "The tor-browser archive could not be extracted to your home directory. \
  260. @@ -121,7 +127,8 @@ _aur_update_() {
  261. fi
  262.  
  263. local DO_UPDATE=0
  264. - local TMP_PKGBUILD="$(mktemp -d)"
  265. + local TMP_PKGBUILD
  266. + TMP_PKGBUILD="$(mktemp -d)"
  267.  
  268. cd "${TMP_PKGBUILD}"
  269.  
  270. @@ -133,15 +140,17 @@ _aur_update_() {
  271.  
  272. cd "${TMP_PKGBUILD}/${_TB_PKGNAME_}"
  273.  
  274. - local AUR_VERSION="$(grep 'pkgver' '.SRCINFO' | cut -d = -f2 | sed -e 's/^[[:space:]]*//')"
  275. - local AUR_RELEASE="$(grep 'pkgrel' '.SRCINFO' | cut -d = -f2 | sed -e 's/^[[:space:]]*//')"
  276. + local AUR_VERSION
  277. + local AUR_RELEASE
  278. + AUR_VERSION="$(grep 'pkgver' '.SRCINFO' | cut -d = -f2 | sed -e 's/^[[:space:]]*//')"
  279. + AUR_RELEASE="$(grep 'pkgrel' '.SRCINFO' | cut -d = -f2 | sed -e 's/^[[:space:]]*//')"
  280.  
  281. if _compare_ver_ "${_TB_VERSION_}" "${AUR_VERSION}"; then
  282. echo "Found new version (${_TB_VERSION_} -> ${AUR_VERSION})..."
  283. DO_UPDATE=1
  284. elif [[ "${_TB_VERSION_}" == "${AUR_VERSION}" ]] && \
  285. [[ "${_TB_RELEASE_}" != "${AUR_RELEASE}" ]] && \
  286. - [[ "${_TB_RELEASE_}" == "`echo -e "${_TB_RELEASE_}\n${AUR_RELEASE}" | sort | head -n1`" ]]; then
  287. + [[ "${_TB_RELEASE_}" == "$(echo -e "${_TB_RELEASE_}\n${AUR_RELEASE}" | sort | head -n1)" ]]; then
  288. echo 'Found new PKGBUILD...'
  289. DO_UPDATE=1
  290. else
  291. @@ -200,14 +209,14 @@ _TB_APP_DIR_="${_TB_HOME_DIR_}/app"
  292. cd "${_TB_HOME_DIR_}"
  293.  
  294. # get the installed version
  295. -while read _TB_VER_LINE_; do
  296. +while read -r _TB_VER_LINE_; do
  297. _TB_INSTALLED_VERSION_="${_TB_VER_LINE_}"
  298. done < "${_TB_VER_FILE_}"
  299.  
  300. # start update if old or no tor-browser is installed
  301. if [[ "${_TB_INSTALLED_VERSION_}" == "${_TB_VERSION_}" ]] && [[ ${_TB_REFRESH_} -eq 0 ]]; then
  302. # clear log
  303. - > "${_TB_LOG_FILE_}"
  304. + :>| "${_TB_LOG_FILE_}"
  305. else
  306. echo "${0}: Your version in ${_TB_HOME_DIR_} is outdated or you do not have installed ${_TB_PKGNAME_} yet." > "${_TB_LOG_FILE_}"
  307. _refresh_local_
  308. --
  309. 2.42.0
  310.  
  311.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement