You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

makeInstallerLinux.sh 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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-2008 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. # Find out what params we should pass to things.
  30. # Solaris has a nice and ancient version of grep in /usr/bin
  31. grep -na "" /dev/null >/dev/null 2>&1
  32. if [ $? -eq 2 ]; then
  33. GREPOPTS="-n"
  34. else
  35. GREPOPTS="-na"
  36. fi;
  37. # Solaris also has a crappy version of tail!
  38. tail -n +1 /dev/null >/dev/null 2>&1
  39. if [ $? -eq 2 ]; then
  40. TAILOPTS="+"
  41. else
  42. TAILOPTS="-n +"
  43. fi;
  44. # Check the which command exists, and if so make sure it behaves how we want
  45. # it to...
  46. WHICH=`which which 2>/dev/null`
  47. if [ "" = "${WHICH}" ]; then
  48. echo "which command not found. Aborting.";
  49. exit 0;
  50. else
  51. # Solaris sucks
  52. BADWHICH=`which /`
  53. if [ "${BADWHICH}" != "" ]; then
  54. echo "Replacing bad which command.";
  55. # "Which" on solaris gives non-empty results for commands that don't exist
  56. which() {
  57. OUT=`${WHICH} ${1}`
  58. if [ $? -eq 0 ]; then
  59. echo ${OUT}
  60. else
  61. echo ""
  62. fi;
  63. }
  64. fi;
  65. fi
  66. # Compress stuff!
  67. compress() {
  68. tar cvfh - $@ | gzip - 2>/dev/null >>${RUNNAME} || {
  69. echo "Compression failed."
  70. kill -15 $$;
  71. };
  72. }
  73. # Go!
  74. echo "-----------"
  75. if [ -e "${RUNNAME}" ]; then
  76. echo "Removing existing .run file"
  77. rm -Rf ./*.run
  78. fi
  79. showHelp() {
  80. echo "This will generate a DMDirc installer for a unix based system."
  81. echo "The following command line arguments are known:"
  82. echo "---------------------"
  83. echo "-h, --help Help information"
  84. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b aswell)"
  85. echo "-b, --branch Release in -r is a branch "
  86. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  87. echo "-c, --compile Recompile the .jar file"
  88. echo " --jre Include the JRE in this installer"
  89. echo " --jre64 Include the 64-Bit JRE in this installer"
  90. echo " --jar <file> use <file> as DMDirc.jar"
  91. echo " --current Use the current folder as the base for the build"
  92. echo "-t, --tag <tag> Tag to add to final exe name to distinguish this build from a standard build"
  93. echo "-k, --keep Keep the existing source tree when compiling"
  94. echo " (don't svn update beforehand)"
  95. echo "---------------------"
  96. exit 0;
  97. }
  98. # Check for some CLI params
  99. compileJar="false"
  100. updateSVN="true"
  101. isRelease=""
  102. finalTag=""
  103. BRANCH="0"
  104. plugins=""
  105. location="../../../"
  106. jarfile=""
  107. current=""
  108. jre=""
  109. jrename="jre" # Filename for JRE without the .bin
  110. while test -n "$1"; do
  111. case "$1" in
  112. --plugins|-p)
  113. shift
  114. plugins=${1}
  115. ;;
  116. --jar)
  117. shift
  118. jarfile=${1}
  119. ;;
  120. --jre)
  121. jre="http://www.dmdirc.com/getjava/linux/i686"
  122. ;;
  123. --jre64)
  124. jre="http://www.dmdirc.com/getjava/linux/x86_64"
  125. jrename="jre64"
  126. ;;
  127. --current)
  128. location="../../"
  129. current="1"
  130. ;;
  131. --compile|-c)
  132. compileJar="true"
  133. ;;
  134. --release|-r)
  135. shift
  136. isRelease=${1}
  137. ;;
  138. --tag|-t)
  139. shift
  140. finalTag=${1}
  141. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.run"
  142. ;;
  143. --keep|-k)
  144. updateSVN="false"
  145. ;;
  146. --help|-h)
  147. showHelp;
  148. ;;
  149. --branch|-b)
  150. BRANCH="1"
  151. ;;
  152. esac
  153. shift
  154. done
  155. if [ "" = "${current}" ]; then
  156. jarPath="${location}trunk"
  157. else
  158. jarPath="${location}"
  159. fi
  160. if [ "${isRelease}" != "" ]; then
  161. if [ "${BRANCH}" != "0" ]; then
  162. if [ -e "${location}/${isRelease}" ]; then
  163. jarPath="${location}/${isRelease}"
  164. else
  165. echo "Branch "${isRelease}" not found."
  166. exit 1;
  167. fi
  168. else
  169. if [ -e "${location}/${isRelease}" ]; then
  170. jarPath="${location}/${isRelease}"
  171. else
  172. echo "Tag "${isRelease}" not found."
  173. exit 1;
  174. fi
  175. fi
  176. fi
  177. if [ "" = "${jarfile}" ]; then
  178. jarfile=${jarPath}"/dist/DMDirc.jar"
  179. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  180. echo "Creating jar.."
  181. OLDPWD=${PWD}
  182. cd ${jarPath}
  183. if [ "${updateSVN}" = "true" ]; then
  184. svn update
  185. fi
  186. rm -Rf build dist
  187. ant jar
  188. if [ ! -e "dist/DMDirc.jar" ]; then
  189. echo "There was an error creating the .jar file. Aborting."
  190. exit 1;
  191. fi;
  192. cd ${OLDPWD}
  193. fi;
  194. elif [ ! -e "${jarfile}" ]; then
  195. echo "Requested Jar file (${jarfile}) does not exist."
  196. exit 1;
  197. fi;
  198. if [ "" = "${plugins}" ]; then
  199. echo "Linking jar (${jarfile}).."
  200. ln -sf ${jarfile} "./DMDirc.jar"
  201. else
  202. echo "Copying jar (${jarfile}).."
  203. cp ${jarfile} "./DMDirc.jar"
  204. echo "Adding plugins to jar"
  205. ln -sf ${jarPath}"/plugins"
  206. pluginList=""
  207. for plugin in ${plugins}; do
  208. pluginList=${pluginList}" plugins/${plugin}"
  209. done
  210. jar -uvf "DMDirc.jar" ${pluginList}
  211. rm -Rf plugins;
  212. fi
  213. echo "Creating .run file"
  214. echo "Adding stub.."
  215. cat installerstub.sh > ${RUNNAME}
  216. # Add release info.
  217. awk '{gsub(/###ADDITIONAL_STUFF###/,"isRelease=\"'${isRelease}'\"");print}' ${RUNNAME} > ${RUNNAME}.tmp
  218. mv ${RUNNAME}.tmp ${RUNNAME}
  219. FILES="DMDirc.jar";
  220. echo "Compressing files.."
  221. for FILE in "getjre.sh" "installjre.sh" "progressbar.sh"; do
  222. if [ -e "${FILE}" ]; then
  223. FILES="${FILES} ${FILE}"
  224. fi
  225. done;
  226. if [ "" != "${jre}" ]; then
  227. if [ ! -e "../common/${jrename}.bin" ]; then
  228. echo "Downloading JRE to include in installer"
  229. wget ${jre} -O ../common/${jrename}.bin
  230. fi
  231. ln -sf ../common/${jrename}.bin jre.bin
  232. FILES="${FILES} jre.bin"
  233. fi;
  234. if [ -e "setup.sh" ]; then
  235. FILES="${FILES} setup.sh"
  236. else
  237. echo "[WARNING] Creating setup-less archive. This will just extract and immediately delete the .jar file unless the -e flag is used"
  238. fi
  239. #if [ -e "../common/installer.jar" ]; then
  240. # ln -sf ../common/installer.jar ./installer.jar
  241. # FILES="${FILES} installer.jar"
  242. #else
  243. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  244. #fi
  245. if [ -e ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ]; then
  246. ln -sf ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ./icon.svg
  247. FILES="${FILES} icon.svg"
  248. fi
  249. if [ "${isRelease}" != "" ]; then
  250. DOCSDIR=${jarPath}
  251. else
  252. DOCSDIR="../common"
  253. fi
  254. if [ -e "${DOCSDIR}/README.TXT" ]; then
  255. ln -sf "${DOCSDIR}/README.TXT" .
  256. FILES="${FILES} README.TXT"
  257. fi
  258. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  259. ln -sf "${DOCSDIR}/CHANGES.TXT" .
  260. FILES="${FILES} CHANGES.TXT"
  261. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  262. ln -sf "${DOCSDIR}/CHANGELOG.TXT" .
  263. FILES="${FILES} CHANGELOG.TXT"
  264. fi
  265. if [ -e "${jarPath}/launcher/linux" ]; then
  266. ln -sf ${jarPath}/launcher/linux/DMDirc.sh .
  267. FILES="${FILES} DMDirc.sh"
  268. fi
  269. compress $FILES
  270. MD5BIN=`which md5sum`
  271. if [ "${MD5BIN}" = "" ]; then
  272. MD5BIN=`which md5`
  273. fi;
  274. AWK=`which awk`
  275. getMD5() {
  276. if [ "${MD5BIN}" != "" ]; then
  277. echo "test" | ${MD5BIN} -
  278. if [ $? -eq 0 ]; then
  279. echo "Linux-Style MD5SUM: ${MD5BIN}"
  280. getMD5Linux $@
  281. else
  282. echo "BSD-Style MD5SUM: ${MD5BIN}"
  283. getMD5BSD $@
  284. fi;
  285. fi;
  286. }
  287. getMD5Linux() {
  288. # Everything below the MD5SUM Line
  289. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  290. MD5LINE=$((${MD5LINE%%:*} + 1))
  291. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  292. return;
  293. }
  294. getMD5BSD() {
  295. # Everything below the MD5SUM Line
  296. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  297. MD5LINE=$((${MD5LINE%%:*} + 1))
  298. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} | ${AWK} '{print $1}'`
  299. return;
  300. }
  301. if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
  302. echo "Adding MD5.."
  303. MD5SUM=""
  304. getMD5 ${RUNNAME} ${MD5SUM}
  305. echo "SUM obtained is: ${MD5SUM}"
  306. LINENUM=`grep ${GREPOPTS} "^MD5=\"\"$" ${RUNNAME}`
  307. LINENUM=${LINENUM%%:*}
  308. head -n $((${LINENUM} -1)) ${RUNNAME} > ${RUNNAME}.tmp
  309. echo 'MD5="'${MD5SUM}'"' >> ${RUNNAME}.tmp
  310. tail ${TAILOPTS}$((${LINENUM} +1)) ${RUNNAME} >> ${RUNNAME}.tmp
  311. mv ${RUNNAME}.tmp ${RUNNAME}
  312. else
  313. echo "Not Adding MD5.."
  314. fi;
  315. echo "Chmodding"
  316. chmod a+x ${RUNNAME}
  317. if [ "${isRelease}" != "" ]; then
  318. if [ "${BRANCH}" = "1" ]; then
  319. isRelease=branch-${isRelease}
  320. fi;
  321. if [ "" != "${finalTag}" ]; then
  322. finalTag="-${finalTag}"
  323. fi;
  324. finalname=DMDirc-${isRelease}-Setup${finalTag}.run
  325. else
  326. finalname=${RUNNAME##*/}
  327. fi;
  328. if [ "" != "${jre}" ]; then
  329. finalname=`echo ${finalname} | sed "s/.run$/.${jrename}.run/"`
  330. fi;
  331. mv ${RUNNAME} ../output/${finalname}
  332. mv setup.sh setup.sh.tmp
  333. mv getjre.sh getjre.sh.tmp
  334. mv installjre.sh installjre.sh.tmp
  335. mv progressbar.sh progressbar.sh.tmp
  336. rm -f ${FILES}
  337. mv setup.sh.tmp setup.sh
  338. mv getjre.sh.tmp getjre.sh
  339. mv installjre.sh.tmp installjre.sh
  340. mv progressbar.sh.tmp progressbar.sh
  341. echo "-----------"
  342. echo "Done."
  343. echo "-----------"
  344. # and Done \o
  345. exit 0;