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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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-2011 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. WGET=`which wget`
  74. FETCH=`which fetch`
  75. CURL=`which curl`
  76. getFile() {
  77. URL=${1}
  78. OUTPUT=${2}
  79. if [ "${WGET}" != "" ]; then
  80. ${WGET} -O ${OUTPUT} ${URL}
  81. elif [ "${FETCH}" != "" ]; then
  82. ${FETCH} -o ${OUTPUT} ${URL}
  83. elif [ "${CURL}" != "" ]; then
  84. ${CURL} -o ${OUTPUT} ${URL}
  85. fi;
  86. }
  87. # Go!
  88. echo "-----------"
  89. if [ -e "${RUNNAME}" ]; then
  90. echo "Removing existing .run file"
  91. rm -Rf ./*.run
  92. fi
  93. showHelp() {
  94. echo "This will generate a DMDirc installer for a unix based system."
  95. echo "The following command line arguments are known:"
  96. echo "---------------------"
  97. echo "-h, --help Help information"
  98. echo "-b, --branch Release in -r is a branch "
  99. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  100. echo "-c, --compile Recompile the .jar file"
  101. echo " --jre Include the JRE in this installer"
  102. echo " --jre64 Include the 64-Bit JRE in this installer"
  103. echo " --jar <file> use <file> as DMDirc.jar"
  104. echo " --current Use the current folder as the base for the build"
  105. echo "-e, --extra <tag> Tag to add to final exe name to distinguish this build from a standard build"
  106. echo "---------------------"
  107. exit 0;
  108. }
  109. # Check for some CLI params
  110. compileJar="false"
  111. isRelease=""
  112. finalTag=""
  113. BRANCH="0"
  114. plugins=""
  115. location="../../"
  116. current="1"
  117. jarfile=""
  118. jre=""
  119. jrename="jre" # Filename for JRE without the .bin
  120. TAGGED=""
  121. while test -n "$1"; do
  122. case "$1" in
  123. --plugins|-p)
  124. shift
  125. plugins=${1}
  126. ;;
  127. --jar)
  128. shift
  129. jarfile=${1}
  130. ;;
  131. --jre)
  132. jre="http://www.dmdirc.com/getjava/linux/i686"
  133. ;;
  134. --jre64)
  135. jre="http://www.dmdirc.com/getjava/linux/x86_64"
  136. jrename="jre64"
  137. ;;
  138. --current)
  139. location="../../"
  140. current="1"
  141. ;;
  142. --compile|-c)
  143. compileJar="true"
  144. ;;
  145. --release|-r)
  146. shift
  147. isRelease=${1}
  148. ;;
  149. --extra|-e)
  150. shift
  151. finalTag=${1}
  152. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.run"
  153. ;;
  154. --help|-h)
  155. showHelp;
  156. ;;
  157. --branch|-b)
  158. BRANCH="1"
  159. ;;
  160. --tag|-t)
  161. TAGGED=`git describe --tags`
  162. TAGGED=${TAGGED%%-*}
  163. ;;
  164. esac
  165. shift
  166. done
  167. if [ "" = "${current}" ]; then
  168. jarPath="${location}trunk"
  169. else
  170. jarPath="${location}"
  171. fi
  172. if [ "" = "${jarfile}" ]; then
  173. jarfile=${jarPath}"/dist/DMDirc.jar"
  174. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  175. echo "Creating jar.."
  176. OLDPWD=${PWD}
  177. cd ${jarPath}
  178. rm -Rf build dist
  179. ant jar
  180. if [ ! -e "dist/DMDirc.jar" ]; then
  181. echo "There was an error creating the .jar file. Aborting."
  182. exit 1;
  183. fi;
  184. cd ${OLDPWD}
  185. fi;
  186. elif [ ! -e "${jarfile}" ]; then
  187. echo "Requested Jar file (${jarfile}) does not exist."
  188. exit 1;
  189. fi;
  190. if [ "" = "${plugins}" ]; then
  191. echo "Linking jar (${jarfile}).."
  192. ln -sf ${jarfile} "./DMDirc.jar"
  193. else
  194. echo "Copying jar (${jarfile}).."
  195. cp ${jarfile} "./DMDirc.jar"
  196. echo "Adding plugins to jar"
  197. ln -sf ${jarPath}"/plugins"
  198. pluginList=""
  199. for plugin in ${plugins}; do
  200. pluginList=${pluginList}" plugins/${plugin}"
  201. done
  202. jar -uvf "DMDirc.jar" ${pluginList}
  203. ../../updateBundledPlugins.sh "DMDirc.jar";
  204. rm -Rf plugins;
  205. fi
  206. echo "Creating .run file"
  207. echo "Adding stub.."
  208. grep -na "" /dev/null >/dev/null 2>&1
  209. if [ $? -eq 2 ]; then
  210. GREPOPTS="-n"
  211. else
  212. GREPOPTS="-na"
  213. fi;
  214. # Solaris also has a crappy version of tail!
  215. tail -n +1 /dev/null >/dev/null 2>&1
  216. if [ $? -eq 2 ]; then
  217. TAILOPTS="+"
  218. else
  219. TAILOPTS="-n +"
  220. fi;
  221. FUNCTIONSLINE=`grep ${GREPOPTS} "^###FUNCTIONS_FILE###$" installerstub.sh`
  222. FUNCTIONSLINE=$((${FUNCTIONSLINE%%:*} + 0))
  223. head -n ${FUNCTIONSLINE} installerstub.sh > ${RUNNAME}
  224. cat functions.sh >> ${RUNNAME}
  225. echo "" >> ${RUNNAME}
  226. tail ${TAILOPTS}$((${FUNCTIONSLINE%%:*} + 1)) installerstub.sh >> ${RUNNAME}
  227. # Add release info.
  228. awk '{gsub(/###ADDITIONAL_STUFF###/,"isRelease=\"'${TAGGED}'\"");print}' ${RUNNAME} > ${RUNNAME}.tmp
  229. mv ${RUNNAME}.tmp ${RUNNAME}
  230. FILES="DMDirc.jar";
  231. echo "Compressing files.."
  232. for FILE in "getjre.sh" "installjre.sh" "progressbar.sh" "functions.sh"; do
  233. if [ -e "${FILE}" ]; then
  234. FILES="${FILES} ${FILE}"
  235. fi
  236. done;
  237. if [ "" != "${jre}" ]; then
  238. if [ ! -e "../common/${jrename}.bin" ]; then
  239. echo "Downloading JRE to include in installer"
  240. getFile "${jre}" "../common/${jrename}.bin"
  241. fi
  242. ln -sf ../common/${jrename}.bin jre.bin
  243. FILES="${FILES} jre.bin"
  244. fi;
  245. if [ -e "setup.sh" ]; then
  246. FILES="${FILES} setup.sh"
  247. else
  248. echo "[WARNING] Creating setup-less archive. This will just extract and immediately delete the .jar file unless the -e flag is used"
  249. fi
  250. #if [ -e "../common/installer.jar" ]; then
  251. # ln -sf ../common/installer.jar ./installer.jar
  252. # FILES="${FILES} installer.jar"
  253. #else
  254. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  255. #fi
  256. if [ -e ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ]; then
  257. ln -sf ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ./icon.svg
  258. FILES="${FILES} icon.svg"
  259. fi
  260. if [ "${isRelease}" != "" ]; then
  261. DOCSDIR=${jarPath}
  262. else
  263. DOCSDIR="../common"
  264. fi
  265. if [ -e "${DOCSDIR}/README.TXT" ]; then
  266. ln -sf "${DOCSDIR}/README.TXT" .
  267. FILES="${FILES} README.TXT"
  268. fi
  269. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  270. ln -sf "${DOCSDIR}/CHANGES.TXT" .
  271. FILES="${FILES} CHANGES.TXT"
  272. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  273. ln -sf "${DOCSDIR}/CHANGELOG.TXT" .
  274. FILES="${FILES} CHANGELOG.TXT"
  275. fi
  276. if [ -e "${jarPath}/launcher/unix" ]; then
  277. # Hax in functions.sh
  278. FUNCTIONSFILE="functions.sh"
  279. SRCFILE=${jarPath}/launcher/unix/DMDirc.sh
  280. DESTFILE=./DMDirc.sh
  281. if [ -e "${FUNCTIONSFILE}" ]; then
  282. FUNCTIONSLINE=`grep ${GREPOPTS} "^###FUNCTIONS_FILE###$" ${SRCFILE}`
  283. if [ "${FUNCTIONSLINE}" == "" ]; then
  284. echo " Functions already built into launcher."
  285. cp ${SRCFILE} ${DESTFILE}
  286. else
  287. echo " Including functions.sh into launcher."
  288. FUNCTIONSLINE=$((${FUNCTIONSLINE%%:*} + 0))
  289. head -n ${FUNCTIONSLINE} ${SRCFILE} > ${DESTFILE}
  290. cat functions.sh >> ${DESTFILE}
  291. echo "" >> ${DESTFILE}
  292. tail ${TAILOPTS}$((${FUNCTIONSLINE%%:*} + 1)) ${SRCFILE} >> ${DESTFILE}
  293. fi;
  294. else
  295. echo " Unable to create unix launcher update, no functions.sh found."
  296. fi;
  297. FILES="${FILES} DMDirc.sh"
  298. fi
  299. if [ -e "uninstall.sh" ]; then
  300. FILES="${FILES} uninstall.sh"
  301. fi
  302. compress $FILES
  303. MD5BIN=`which md5sum`
  304. if [ "${MD5BIN}" = "" ]; then
  305. MD5BIN=`which md5`
  306. fi;
  307. AWK=`which awk`
  308. getMD5() {
  309. if [ "${MD5BIN}" != "" ]; then
  310. echo "test" | ${MD5BIN} -
  311. if [ $? -eq 0 ]; then
  312. echo "Linux-Style MD5SUM: ${MD5BIN}"
  313. getMD5Linux $@
  314. else
  315. echo "BSD-Style MD5SUM: ${MD5BIN}"
  316. getMD5BSD $@
  317. fi;
  318. fi;
  319. }
  320. getMD5Linux() {
  321. # Everything below the MD5SUM Line
  322. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  323. MD5LINE=$((${MD5LINE%%:*} + 1))
  324. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  325. return;
  326. }
  327. getMD5BSD() {
  328. # Everything below the MD5SUM Line
  329. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  330. MD5LINE=$((${MD5LINE%%:*} + 1))
  331. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} | ${AWK} '{print $1}'`
  332. return;
  333. }
  334. if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
  335. echo "Adding MD5.."
  336. MD5SUM=""
  337. getMD5 ${RUNNAME} ${MD5SUM}
  338. echo "SUM obtained is: ${MD5SUM}"
  339. LINENUM=`grep ${GREPOPTS} "^MD5=\"\"$" ${RUNNAME}`
  340. LINENUM=${LINENUM%%:*}
  341. head -n $((${LINENUM} -1)) ${RUNNAME} > ${RUNNAME}.tmp
  342. echo 'MD5="'${MD5SUM}'"' >> ${RUNNAME}.tmp
  343. tail ${TAILOPTS}$((${LINENUM} +1)) ${RUNNAME} >> ${RUNNAME}.tmp
  344. mv ${RUNNAME}.tmp ${RUNNAME}
  345. else
  346. echo "Not Adding MD5.."
  347. fi;
  348. echo "Chmodding"
  349. chmod a+x ${RUNNAME}
  350. doRename=0
  351. if [ "${TAGGED}" != "" ]; then
  352. doRename=1
  353. fi;
  354. if [ ${doRename} -eq 1 ]; then
  355. if [ "${TAGGED}" = "" ]; then
  356. isRelease=branch-${isRelease}
  357. else
  358. isRelease=${TAGGED}
  359. fi;
  360. if [ "" != "${finalTag}" ]; then
  361. finalTag="-${finalTag}"
  362. fi;
  363. finalname=DMDirc-${isRelease}-Setup${finalTag}.run
  364. else
  365. finalname=${RUNNAME##*/}
  366. fi;
  367. if [ "" != "${jre}" ]; then
  368. finalname=`echo ${finalname} | sed "s/.run$/.${jrename}.run/"`
  369. fi;
  370. mv ${RUNNAME} ../output/${finalname}
  371. mv setup.sh setup.sh.tmp
  372. mv getjre.sh getjre.sh.tmp
  373. mv installjre.sh installjre.sh.tmp
  374. mv progressbar.sh progressbar.sh.tmp
  375. mv uninstall.sh uninstall.sh.tmp
  376. mv functions.sh functions.sh.tmp
  377. rm -f ${FILES}
  378. mv setup.sh.tmp setup.sh
  379. mv getjre.sh.tmp getjre.sh
  380. mv installjre.sh.tmp installjre.sh
  381. mv progressbar.sh.tmp progressbar.sh
  382. mv uninstall.sh.tmp uninstall.sh
  383. mv functions.sh.tmp functions.sh
  384. echo "-----------"
  385. echo "Done."
  386. echo "-----------"
  387. # and Done \o
  388. exit 0;