Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

makeInstallerLinux.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. #!/bin/sh
  2. #
  3. # This script generates a .run file that will install DMDirc
  4. #
  5. # DMDirc - Open Source IRC Client
  6. # Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining a copy
  9. # of this software and associated documentation files (the "Software"), to deal
  10. # in the Software without restriction, including without limitation the rights
  11. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. # copies of the Software, and to permit persons to whom the Software is
  13. # furnished to do so, subject to the following conditions:
  14. #
  15. # The above copyright notice and this permission notice shall be included in
  16. # all copies or substantial portions of the Software.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. # SOFTWARE.
  25. # Final Name of the installer (without file extention)
  26. INSTALLERNAME=DMDirc-Setup
  27. # full name of the file to output to
  28. RUNNAME="${PWD}/${INSTALLERNAME}.run"
  29. # Are we a git working copy, or SVN?
  30. if [ -e ".svn" ]; then
  31. isSVN=1
  32. else
  33. isSVN=0
  34. fi;
  35. # Find out what params we should pass to things.
  36. # Solaris has a nice and ancient version of grep in /usr/bin
  37. grep -na "" /dev/null >/dev/null 2>&1
  38. if [ $? -eq 2 ]; then
  39. GREPOPTS="-n"
  40. else
  41. GREPOPTS="-na"
  42. fi;
  43. # Solaris also has a crappy version of tail!
  44. tail -n +1 /dev/null >/dev/null 2>&1
  45. if [ $? -eq 2 ]; then
  46. TAILOPTS="+"
  47. else
  48. TAILOPTS="-n +"
  49. fi;
  50. # Check the which command exists, and if so make sure it behaves how we want
  51. # it to...
  52. WHICH=`which which 2>/dev/null`
  53. if [ "" = "${WHICH}" ]; then
  54. echo "which command not found. Aborting.";
  55. exit 0;
  56. else
  57. # Solaris sucks
  58. BADWHICH=`which /`
  59. if [ "${BADWHICH}" != "" ]; then
  60. echo "Replacing bad which command.";
  61. # "Which" on solaris gives non-empty results for commands that don't exist
  62. which() {
  63. OUT=`${WHICH} ${1}`
  64. if [ $? -eq 0 ]; then
  65. echo ${OUT}
  66. else
  67. echo ""
  68. fi;
  69. }
  70. fi;
  71. fi
  72. # Compress stuff!
  73. compress() {
  74. tar cvfh - $@ | gzip - 2>/dev/null >>${RUNNAME} || {
  75. echo "Compression failed."
  76. kill -15 $$;
  77. };
  78. }
  79. WGET=`which wget`
  80. FETCH=`which fetch`
  81. CURL=`which curl`
  82. getFile() {
  83. URL=${1}
  84. OUTPUT=${2}
  85. if [ "${WGET}" != "" ]; then
  86. ${WGET} -O ${OUTPUT} ${URL}
  87. elif [ "${FETCH}" != "" ]; then
  88. ${FETCH} -o ${OUTPUT} ${URL}
  89. elif [ "${CURL}" != "" ]; then
  90. ${CURL} -o ${OUTPUT} ${URL}
  91. fi;
  92. }
  93. # Go!
  94. echo "-----------"
  95. if [ -e "${RUNNAME}" ]; then
  96. echo "Removing existing .run file"
  97. rm -Rf ./*.run
  98. fi
  99. showHelp() {
  100. echo "This will generate a DMDirc installer for a unix based system."
  101. echo "The following command line arguments are known:"
  102. echo "---------------------"
  103. echo "-h, --help Help information"
  104. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b as well)"
  105. echo "-b, --branch Release in -r is a branch "
  106. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  107. echo "-c, --compile Recompile the .jar file"
  108. echo " --jre Include the JRE in this installer"
  109. echo " --jre64 Include the 64-Bit JRE in this installer"
  110. echo " --jar <file> use <file> as DMDirc.jar"
  111. echo " --current Use the current folder as the base for the build"
  112. echo "-e, --extra <tag> Tag to add to final exe name to distinguish this build from a standard build"
  113. echo "-k, --keep Keep the existing source tree when compiling"
  114. echo " (don't svn update beforehand)"
  115. echo "---------------------"
  116. exit 0;
  117. }
  118. # Check for some CLI params
  119. compileJar="false"
  120. updateSVN="true"
  121. isRelease=""
  122. finalTag=""
  123. BRANCH="0"
  124. plugins=""
  125. if [ $isSVN -eq 1 ]; then
  126. location="../../../"
  127. current=""
  128. else
  129. location="../../"
  130. current="1"
  131. fi;
  132. jarfile=""
  133. jre=""
  134. jrename="jre" # Filename for JRE without the .bin
  135. TAGGED=""
  136. while test -n "$1"; do
  137. case "$1" in
  138. --plugins|-p)
  139. shift
  140. plugins=${1}
  141. ;;
  142. --jar)
  143. shift
  144. jarfile=${1}
  145. ;;
  146. --jre)
  147. jre="http://www.dmdirc.com/getjava/linux/i686"
  148. ;;
  149. --jre64)
  150. jre="http://www.dmdirc.com/getjava/linux/x86_64"
  151. jrename="jre64"
  152. ;;
  153. --current)
  154. location="../../"
  155. current="1"
  156. ;;
  157. --compile|-c)
  158. compileJar="true"
  159. ;;
  160. --release|-r)
  161. shift
  162. isRelease=${1}
  163. ;;
  164. --extra|-e)
  165. shift
  166. finalTag=${1}
  167. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.run"
  168. ;;
  169. --keep|-k)
  170. updateSVN="false"
  171. ;;
  172. --help|-h)
  173. showHelp;
  174. ;;
  175. --branch|-b)
  176. BRANCH="1"
  177. ;;
  178. --tag|-t)
  179. shift
  180. if [ ${isSVN} -eq 1 ]; then
  181. REGEX="^[0-9]+(\.[0-9]+(\.[0-9]+)?)?$"
  182. CHECKTAG=`echo ${1} | egrep "${REGEX}"`
  183. if [ "" = "${CHECKTAG}" ]; then
  184. echo "Specified tag ("${1}") is invalid."
  185. exit 1;
  186. fi;
  187. TAGGED="${1}"
  188. else
  189. TAGGED=`git describe --tags`
  190. TAGGED=${TAGGED%%-*}
  191. fi;
  192. ;;
  193. esac
  194. shift
  195. done
  196. if [ "" = "${current}" ]; then
  197. jarPath="${location}trunk"
  198. else
  199. jarPath="${location}"
  200. fi
  201. if [ "${isRelease}" != "" ]; then
  202. if [ $isSVN -eq 1 ]; then
  203. if [ "${BRANCH}" != "0" ]; then
  204. if [ -e "${location}/${isRelease}" ]; then
  205. jarPath="${location}/${isRelease}"
  206. else
  207. echo "Branch "${isRelease}" not found."
  208. exit 1;
  209. fi
  210. else
  211. if [ -e "${location}/${isRelease}" ]; then
  212. jarPath="${location}/${isRelease}"
  213. else
  214. echo "Tag "${isRelease}" not found."
  215. exit 1;
  216. fi
  217. fi
  218. fi;
  219. fi
  220. if [ "" = "${jarfile}" ]; then
  221. jarfile=${jarPath}"/dist/DMDirc.jar"
  222. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  223. echo "Creating jar.."
  224. OLDPWD=${PWD}
  225. cd ${jarPath}
  226. if [ "${updateSVN}" = "true" ]; then
  227. svn update
  228. fi
  229. rm -Rf build dist
  230. ant jar
  231. if [ ! -e "dist/DMDirc.jar" ]; then
  232. echo "There was an error creating the .jar file. Aborting."
  233. exit 1;
  234. fi;
  235. cd ${OLDPWD}
  236. fi;
  237. elif [ ! -e "${jarfile}" ]; then
  238. echo "Requested Jar file (${jarfile}) does not exist."
  239. exit 1;
  240. fi;
  241. if [ "" = "${plugins}" ]; then
  242. echo "Linking jar (${jarfile}).."
  243. ln -sf ${jarfile} "./DMDirc.jar"
  244. else
  245. echo "Copying jar (${jarfile}).."
  246. cp ${jarfile} "./DMDirc.jar"
  247. echo "Adding plugins to jar"
  248. ln -sf ${jarPath}"/plugins"
  249. pluginList=""
  250. for plugin in ${plugins}; do
  251. pluginList=${pluginList}" plugins/${plugin}"
  252. done
  253. jar -uvf "DMDirc.jar" ${pluginList}
  254. rm -Rf plugins;
  255. fi
  256. echo "Creating .run file"
  257. echo "Adding stub.."
  258. grep -na "" /dev/null >/dev/null 2>&1
  259. if [ $? -eq 2 ]; then
  260. GREPOPTS="-n"
  261. else
  262. GREPOPTS="-na"
  263. fi;
  264. # Solaris also has a crappy version of tail!
  265. tail -n +1 /dev/null >/dev/null 2>&1
  266. if [ $? -eq 2 ]; then
  267. TAILOPTS="+"
  268. else
  269. TAILOPTS="-n +"
  270. fi;
  271. FUNCTIONSLINE=`grep ${GREPOPTS} "^###FUNCTIONS_FILE###$" installerstub.sh`
  272. FUNCTIONSLINE=$((${FUNCTIONSLINE%%:*} + 0))
  273. head -n ${FUNCTIONSLINE} installerstub.sh > ${RUNNAME}
  274. cat functions.sh >> ${RUNNAME}
  275. echo "" >> ${RUNNAME}
  276. tail ${TAILOPTS}$((${FUNCTIONSLINE%%:*} + 1)) installerstub.sh >> ${RUNNAME}
  277. # Add release info.
  278. if [ $isSVN -eq 1 ]; then
  279. awk '{gsub(/###ADDITIONAL_STUFF###/,"isRelease=\"'${isRelease}'\"");print}' ${RUNNAME} > ${RUNNAME}.tmp
  280. mv ${RUNNAME}.tmp ${RUNNAME}
  281. elif [ "${TAGGED}" != "" ]; then
  282. awk '{gsub(/###ADDITIONAL_STUFF###/,"isRelease=\"'${TAGGED}'\"");print}' ${RUNNAME} > ${RUNNAME}.tmp
  283. mv ${RUNNAME}.tmp ${RUNNAME}
  284. fi;
  285. FILES="DMDirc.jar";
  286. echo "Compressing files.."
  287. for FILE in "getjre.sh" "installjre.sh" "progressbar.sh" "functions.sh"; do
  288. if [ -e "${FILE}" ]; then
  289. FILES="${FILES} ${FILE}"
  290. fi
  291. done;
  292. if [ "" != "${jre}" ]; then
  293. if [ ! -e "../common/${jrename}.bin" ]; then
  294. echo "Downloading JRE to include in installer"
  295. getFile "${jre}" "../common/${jrename}.bin"
  296. fi
  297. ln -sf ../common/${jrename}.bin jre.bin
  298. FILES="${FILES} jre.bin"
  299. fi;
  300. if [ -e "setup.sh" ]; then
  301. FILES="${FILES} setup.sh"
  302. else
  303. echo "[WARNING] Creating setup-less archive. This will just extract and immediately delete the .jar file unless the -e flag is used"
  304. fi
  305. #if [ -e "../common/installer.jar" ]; then
  306. # ln -sf ../common/installer.jar ./installer.jar
  307. # FILES="${FILES} installer.jar"
  308. #else
  309. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  310. #fi
  311. if [ -e ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ]; then
  312. ln -sf ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ./icon.svg
  313. FILES="${FILES} icon.svg"
  314. fi
  315. if [ "${isRelease}" != "" ]; then
  316. DOCSDIR=${jarPath}
  317. else
  318. DOCSDIR="../common"
  319. fi
  320. if [ -e "${DOCSDIR}/README.TXT" ]; then
  321. ln -sf "${DOCSDIR}/README.TXT" .
  322. FILES="${FILES} README.TXT"
  323. fi
  324. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  325. ln -sf "${DOCSDIR}/CHANGES.TXT" .
  326. FILES="${FILES} CHANGES.TXT"
  327. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  328. ln -sf "${DOCSDIR}/CHANGELOG.TXT" .
  329. FILES="${FILES} CHANGELOG.TXT"
  330. fi
  331. if [ -e "${jarPath}/launcher/unix" ]; then
  332. ln -sf ${jarPath}/launcher/unix/DMDirc.sh .
  333. FILES="${FILES} DMDirc.sh"
  334. fi
  335. if [ -e "uninstall.sh" ]; then
  336. FILES="${FILES} uninstall.sh"
  337. fi
  338. compress $FILES
  339. MD5BIN=`which md5sum`
  340. if [ "${MD5BIN}" = "" ]; then
  341. MD5BIN=`which md5`
  342. fi;
  343. AWK=`which awk`
  344. getMD5() {
  345. if [ "${MD5BIN}" != "" ]; then
  346. echo "test" | ${MD5BIN} -
  347. if [ $? -eq 0 ]; then
  348. echo "Linux-Style MD5SUM: ${MD5BIN}"
  349. getMD5Linux $@
  350. else
  351. echo "BSD-Style MD5SUM: ${MD5BIN}"
  352. getMD5BSD $@
  353. fi;
  354. fi;
  355. }
  356. getMD5Linux() {
  357. # Everything below the MD5SUM Line
  358. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  359. MD5LINE=$((${MD5LINE%%:*} + 1))
  360. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  361. return;
  362. }
  363. getMD5BSD() {
  364. # Everything below the MD5SUM Line
  365. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  366. MD5LINE=$((${MD5LINE%%:*} + 1))
  367. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} | ${AWK} '{print $1}'`
  368. return;
  369. }
  370. if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
  371. echo "Adding MD5.."
  372. MD5SUM=""
  373. getMD5 ${RUNNAME} ${MD5SUM}
  374. echo "SUM obtained is: ${MD5SUM}"
  375. LINENUM=`grep ${GREPOPTS} "^MD5=\"\"$" ${RUNNAME}`
  376. LINENUM=${LINENUM%%:*}
  377. head -n $((${LINENUM} -1)) ${RUNNAME} > ${RUNNAME}.tmp
  378. echo 'MD5="'${MD5SUM}'"' >> ${RUNNAME}.tmp
  379. tail ${TAILOPTS}$((${LINENUM} +1)) ${RUNNAME} >> ${RUNNAME}.tmp
  380. mv ${RUNNAME}.tmp ${RUNNAME}
  381. else
  382. echo "Not Adding MD5.."
  383. fi;
  384. echo "Chmodding"
  385. chmod a+x ${RUNNAME}
  386. doRename=0
  387. if [ "${isRelease}" != "" ]; then
  388. doRename=1
  389. elif [ $isSVN -eq 0 -a "${TAGGED}" != "" ]; then
  390. doRename=1
  391. fi;
  392. if [ ${doRename} -eq 1 ]; then
  393. if [ $isSVN -eq 1 ]; then
  394. if [ "${BRANCH}" = "1" ]; then
  395. isRelease=branch-${isRelease}
  396. fi;
  397. else
  398. if [ "${TAGGED}" = "" ]; then
  399. isRelease=branch-${isRelease}
  400. else
  401. isRelease=${TAGGED}
  402. fi;
  403. fi
  404. if [ "" != "${finalTag}" ]; then
  405. finalTag="-${finalTag}"
  406. fi;
  407. finalname=DMDirc-${isRelease}-Setup${finalTag}.run
  408. else
  409. finalname=${RUNNAME##*/}
  410. fi;
  411. if [ "" != "${jre}" ]; then
  412. finalname=`echo ${finalname} | sed "s/.run$/.${jrename}.run/"`
  413. fi;
  414. mv ${RUNNAME} ../output/${finalname}
  415. mv setup.sh setup.sh.tmp
  416. mv getjre.sh getjre.sh.tmp
  417. mv installjre.sh installjre.sh.tmp
  418. mv progressbar.sh progressbar.sh.tmp
  419. mv uninstall.sh uninstall.sh.tmp
  420. mv functions.sh functions.sh.tmp
  421. rm -f ${FILES}
  422. mv setup.sh.tmp setup.sh
  423. mv getjre.sh.tmp getjre.sh
  424. mv installjre.sh.tmp installjre.sh
  425. mv progressbar.sh.tmp progressbar.sh
  426. mv uninstall.sh.tmp uninstall.sh
  427. mv functions.sh.tmp functions.sh
  428. echo "-----------"
  429. echo "Done."
  430. echo "-----------"
  431. # and Done \o
  432. exit 0;