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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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-2010 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. rm -Rf plugins;
  204. fi
  205. echo "Creating .run file"
  206. echo "Adding stub.."
  207. grep -na "" /dev/null >/dev/null 2>&1
  208. if [ $? -eq 2 ]; then
  209. GREPOPTS="-n"
  210. else
  211. GREPOPTS="-na"
  212. fi;
  213. # Solaris also has a crappy version of tail!
  214. tail -n +1 /dev/null >/dev/null 2>&1
  215. if [ $? -eq 2 ]; then
  216. TAILOPTS="+"
  217. else
  218. TAILOPTS="-n +"
  219. fi;
  220. FUNCTIONSLINE=`grep ${GREPOPTS} "^###FUNCTIONS_FILE###$" installerstub.sh`
  221. FUNCTIONSLINE=$((${FUNCTIONSLINE%%:*} + 0))
  222. head -n ${FUNCTIONSLINE} installerstub.sh > ${RUNNAME}
  223. cat functions.sh >> ${RUNNAME}
  224. echo "" >> ${RUNNAME}
  225. tail ${TAILOPTS}$((${FUNCTIONSLINE%%:*} + 1)) installerstub.sh >> ${RUNNAME}
  226. # Add release info.
  227. awk '{gsub(/###ADDITIONAL_STUFF###/,"isRelease=\"'${TAGGED}'\"");print}' ${RUNNAME} > ${RUNNAME}.tmp
  228. mv ${RUNNAME}.tmp ${RUNNAME}
  229. FILES="DMDirc.jar";
  230. echo "Compressing files.."
  231. for FILE in "getjre.sh" "installjre.sh" "progressbar.sh" "functions.sh"; do
  232. if [ -e "${FILE}" ]; then
  233. FILES="${FILES} ${FILE}"
  234. fi
  235. done;
  236. if [ "" != "${jre}" ]; then
  237. if [ ! -e "../common/${jrename}.bin" ]; then
  238. echo "Downloading JRE to include in installer"
  239. getFile "${jre}" "../common/${jrename}.bin"
  240. fi
  241. ln -sf ../common/${jrename}.bin jre.bin
  242. FILES="${FILES} jre.bin"
  243. fi;
  244. if [ -e "setup.sh" ]; then
  245. FILES="${FILES} setup.sh"
  246. else
  247. echo "[WARNING] Creating setup-less archive. This will just extract and immediately delete the .jar file unless the -e flag is used"
  248. fi
  249. #if [ -e "../common/installer.jar" ]; then
  250. # ln -sf ../common/installer.jar ./installer.jar
  251. # FILES="${FILES} installer.jar"
  252. #else
  253. # echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  254. #fi
  255. if [ -e ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ]; then
  256. ln -sf ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ./icon.svg
  257. FILES="${FILES} icon.svg"
  258. fi
  259. if [ "${isRelease}" != "" ]; then
  260. DOCSDIR=${jarPath}
  261. else
  262. DOCSDIR="../common"
  263. fi
  264. if [ -e "${DOCSDIR}/README.TXT" ]; then
  265. ln -sf "${DOCSDIR}/README.TXT" .
  266. FILES="${FILES} README.TXT"
  267. fi
  268. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  269. ln -sf "${DOCSDIR}/CHANGES.TXT" .
  270. FILES="${FILES} CHANGES.TXT"
  271. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  272. ln -sf "${DOCSDIR}/CHANGELOG.TXT" .
  273. FILES="${FILES} CHANGELOG.TXT"
  274. fi
  275. if [ -e "${jarPath}/launcher/unix" ]; then
  276. ln -sf ${jarPath}/launcher/unix/DMDirc.sh .
  277. FILES="${FILES} DMDirc.sh"
  278. fi
  279. if [ -e "uninstall.sh" ]; then
  280. FILES="${FILES} uninstall.sh"
  281. fi
  282. compress $FILES
  283. MD5BIN=`which md5sum`
  284. if [ "${MD5BIN}" = "" ]; then
  285. MD5BIN=`which md5`
  286. fi;
  287. AWK=`which awk`
  288. getMD5() {
  289. if [ "${MD5BIN}" != "" ]; then
  290. echo "test" | ${MD5BIN} -
  291. if [ $? -eq 0 ]; then
  292. echo "Linux-Style MD5SUM: ${MD5BIN}"
  293. getMD5Linux $@
  294. else
  295. echo "BSD-Style MD5SUM: ${MD5BIN}"
  296. getMD5BSD $@
  297. fi;
  298. fi;
  299. }
  300. getMD5Linux() {
  301. # Everything below the MD5SUM Line
  302. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  303. MD5LINE=$((${MD5LINE%%:*} + 1))
  304. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  305. return;
  306. }
  307. getMD5BSD() {
  308. # Everything below the MD5SUM Line
  309. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  310. MD5LINE=$((${MD5LINE%%:*} + 1))
  311. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} | ${AWK} '{print $1}'`
  312. return;
  313. }
  314. if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
  315. echo "Adding MD5.."
  316. MD5SUM=""
  317. getMD5 ${RUNNAME} ${MD5SUM}
  318. echo "SUM obtained is: ${MD5SUM}"
  319. LINENUM=`grep ${GREPOPTS} "^MD5=\"\"$" ${RUNNAME}`
  320. LINENUM=${LINENUM%%:*}
  321. head -n $((${LINENUM} -1)) ${RUNNAME} > ${RUNNAME}.tmp
  322. echo 'MD5="'${MD5SUM}'"' >> ${RUNNAME}.tmp
  323. tail ${TAILOPTS}$((${LINENUM} +1)) ${RUNNAME} >> ${RUNNAME}.tmp
  324. mv ${RUNNAME}.tmp ${RUNNAME}
  325. else
  326. echo "Not Adding MD5.."
  327. fi;
  328. echo "Chmodding"
  329. chmod a+x ${RUNNAME}
  330. doRename=0
  331. if [ "${TAGGED}" != "" ]; then
  332. doRename=1
  333. fi;
  334. if [ ${doRename} -eq 1 ]; then
  335. if [ "${TAGGED}" = "" ]; then
  336. isRelease=branch-${isRelease}
  337. else
  338. isRelease=${TAGGED}
  339. fi;
  340. if [ "" != "${finalTag}" ]; then
  341. finalTag="-${finalTag}"
  342. fi;
  343. finalname=DMDirc-${isRelease}-Setup${finalTag}.run
  344. else
  345. finalname=${RUNNAME##*/}
  346. fi;
  347. if [ "" != "${jre}" ]; then
  348. finalname=`echo ${finalname} | sed "s/.run$/.${jrename}.run/"`
  349. fi;
  350. mv ${RUNNAME} ../output/${finalname}
  351. mv setup.sh setup.sh.tmp
  352. mv getjre.sh getjre.sh.tmp
  353. mv installjre.sh installjre.sh.tmp
  354. mv progressbar.sh progressbar.sh.tmp
  355. mv uninstall.sh uninstall.sh.tmp
  356. mv functions.sh functions.sh.tmp
  357. rm -f ${FILES}
  358. mv setup.sh.tmp setup.sh
  359. mv getjre.sh.tmp getjre.sh
  360. mv installjre.sh.tmp installjre.sh
  361. mv progressbar.sh.tmp progressbar.sh
  362. mv uninstall.sh.tmp uninstall.sh
  363. mv functions.sh.tmp functions.sh
  364. echo "-----------"
  365. echo "Done."
  366. echo "-----------"
  367. # and Done \o
  368. exit 0;