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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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-2007 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. # Location of .run stub start
  28. STARTLINE=`grep -n "^###START INCLUDE###$" $0`
  29. STARTLINE=$((${STARTLINE%%:*} + 1))
  30. # full name of the file to output to
  31. RUNNAME="${PWD}/${INSTALLERNAME}.run"
  32. # Compress stuff!
  33. compress() {
  34. tar cvfh - $@ | gzip - 2>/dev/null >>${RUNNAME} || {
  35. echo "Compression failed."
  36. kill -15 $$;
  37. };
  38. }
  39. # Go!
  40. echo "-----------"
  41. if [ -e "${RUNNAME}" ]; then
  42. echo "Removing existing .run file"
  43. rm -Rf ./*.run
  44. fi
  45. showHelp() {
  46. echo "This will generate a DMDirc installer for a unix based system."
  47. echo "The following command line arguments are known:"
  48. echo "---------------------"
  49. echo "-h, --help Help information"
  50. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b aswell)"
  51. echo "-b, --branch Release in -r is a branch "
  52. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  53. echo "-c, --compile Recompile the .jar file"
  54. echo "-t, --tag <tag> Tag to add to final exe name to distinguish this build from a standard build"
  55. echo "-k, --keep Keep the existing source tree when compiling"
  56. echo " (don't svn update beforehand)"
  57. echo "---------------------"
  58. exit 0;
  59. }
  60. # Check for some CLI params
  61. compileJar="false"
  62. updateSVN="true"
  63. isRelease=""
  64. finalTag=""
  65. BRANCH="0"
  66. plugins=""
  67. location="../../../"
  68. while test -n "$1"; do
  69. case "$1" in
  70. --plugins|-p)
  71. shift
  72. plugins=${1}
  73. ;;
  74. --compile|-c)
  75. compileJar="true"
  76. ;;
  77. --release|-r)
  78. shift
  79. isRelease=${1}
  80. ;;
  81. --tag|-t)
  82. shift
  83. RUNNAME="${PWD}/${INSTALLERNAME}-${1}.run"
  84. ;;
  85. --keep|-k)
  86. updateSVN="false"
  87. ;;
  88. --help|-h)
  89. showHelp;
  90. ;;
  91. --branch|-b)
  92. BRANCH="1"
  93. ;;
  94. esac
  95. shift
  96. done
  97. jarPath="${location}trunk"
  98. if [ "${isRelease}" != "" ]; then
  99. if [ "${BRANCH}" != "0" ]; then
  100. if [ -e "${location}branches/"${isRelease} ]; then
  101. jarPath="${location}branches/"${isRelease}
  102. else
  103. echo "Branch "${isRelease}" not found."
  104. exit 1;
  105. fi
  106. else
  107. if [ -e "${location}tags/"${isRelease} ]; then
  108. jarPath="${location}tags/"${isRelease}
  109. else
  110. echo "Tag "${isRelease}" not found."
  111. exit 1;
  112. fi
  113. fi
  114. fi
  115. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  116. echo "Creating jar.."
  117. OLDPWD=${PWD}
  118. cd ${jarPath}
  119. if [ "${updateSVN}" = "true" ]; then
  120. svn update
  121. fi
  122. rm -Rf build dist
  123. ant jar
  124. if [ ! -e "dist/DMDirc.jar" ]; then
  125. echo "There was an error creating the .jar file. Aborting."
  126. exit 0;
  127. fi;
  128. cd ${OLDPWD}
  129. fi;
  130. if [ "" = "${plugins}" ]; then
  131. echo "Linking jar.."
  132. ln -s ${jarPath}"/dist/DMDirc.jar" "./DMDirc.jar"
  133. else
  134. echo "Copying jar.."
  135. cp ${jarPath}"/dist/DMDirc.jar" "./DMDirc.jar"
  136. echo "Adding plugins to jar"
  137. ln -s ${jarPath}"/plugins"
  138. pluginList=""
  139. for plugin in ${plugins}; do
  140. pluginList=${pluginList}" plugins/${plugin}"
  141. done
  142. jar -uvf "DMDirc.jar" ${pluginList}
  143. rm -Rf plugins;
  144. fi
  145. echo "Creating .run file"
  146. echo "Adding stub.."
  147. tail -n +${STARTLINE} $0 > ${RUNNAME}
  148. # Add release info.
  149. awk '{gsub(/###ADDITIONAL_STUFF###/,"isRelease=\"'${isRelease}'\"");print}' ${RUNNAME} > ${RUNNAME}.tmp
  150. mv ${RUNNAME}.tmp ${RUNNAME}
  151. FILES="DMDirc.jar";
  152. echo "Compressing files.."
  153. if [ -e "setup.sh" ]; then
  154. FILES="${FILES} setup.sh"
  155. else
  156. echo "[WARNING] Creating setup-less archive. This will just extract and immediately delete the .jar file unless the -e flag is used"
  157. fi
  158. if [ -e "../common/installer.jar" ]; then
  159. ln -s ../common/installer.jar ./installer.jar
  160. FILES="${FILES} installer.jar"
  161. else
  162. echo "[WARNING] Creating installer-less archive - relying on setup.sh"
  163. fi
  164. if [ -e ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ]; then
  165. ln -s ${jarPath}"/src/com/dmdirc/res/source/logo.svg" ./icon.svg
  166. FILES="${FILES} icon.svg"
  167. fi
  168. if [ "${isRelease}" != "" ]; then
  169. DOCSDIR=${jarPath}
  170. else
  171. DOCSDIR="../common"
  172. fi
  173. if [ -e "${DOCSDIR}/README.TXT" ]; then
  174. ln -s "${DOCSDIR}/README.TXT" .
  175. FILES="${FILES} README.TXT"
  176. fi
  177. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  178. ln -s "${DOCSDIR}/CHANGES.TXT" .
  179. FILES="${FILES} CHANGES.TXT"
  180. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  181. ln -s "${DOCSDIR}/CHANGELOG.TXT" .
  182. FILES="${FILES} CHANGELOG.TXT"
  183. fi
  184. if [ -e "${jarPath}/launcher/linux" ]; then
  185. ln -s ${jarPath}/launcher/linux/DMDirc.sh .
  186. FILES="${FILES} DMDirc.sh"
  187. fi
  188. compress $FILES
  189. MD5BIN=`which md5sum`
  190. AWK=`which awk`
  191. getMD5() {
  192. # Everything below the MD5SUM Line
  193. MD5LINE=`grep -na "^MD5=\".*\"$" ${1}`
  194. MD5LINE=$((${MD5LINE%%:*} + 1))
  195. MD5SUM=`tail -n +${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  196. return;
  197. }
  198. if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
  199. echo "Adding MD5.."
  200. MD5SUM=""
  201. getMD5 ${RUNNAME} ${MD5SUM}
  202. echo "SUM obtained is: ${MD5SUM}"
  203. LINENUM=`grep -na "^MD5=\"\"$" ${RUNNAME}`
  204. LINENUM=${LINENUM%%:*}
  205. head -n $((${LINENUM} -1)) ${RUNNAME} > ${RUNNAME}.tmp
  206. echo 'MD5="'${MD5SUM}'"' >> ${RUNNAME}.tmp
  207. tail -n +$((${LINENUM} +1)) ${RUNNAME} >> ${RUNNAME}.tmp
  208. mv ${RUNNAME}.tmp ${RUNNAME}
  209. else
  210. echo "Not Adding MD5.."
  211. fi;
  212. echo "Chmodding"
  213. chmod a+x ${RUNNAME}
  214. if [ "${isRelease}" != "" ]; then
  215. mv ${RUNNAME} ../output/DMDirc-${isRelease}-Setup.run
  216. else
  217. mv ${RUNNAME} ../output/
  218. fi;
  219. mv setup.sh setup.sh.tmp
  220. rm -f ${FILES}
  221. mv setup.sh.tmp setup.sh
  222. echo "-----------"
  223. echo "Done."
  224. echo "-----------"
  225. # and Done \o
  226. exit 0;
  227. ### Everything below here is part of the .run stub.
  228. ###START INCLUDE###
  229. #!/bin/sh
  230. #
  231. # This script installs dmdirc
  232. #
  233. # DMDirc - Open Source IRC Client
  234. # Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  235. #
  236. # Permission is hereby granted, free of charge, to any person obtaining a copy
  237. # of this software and associated documentation files (the "Software"), to deal
  238. # in the Software without restriction, including without limitation the rights
  239. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  240. # copies of the Software, and to permit persons to whom the Software is
  241. # furnished to do so, subject to the following conditions:
  242. #
  243. # The above copyright notice and this permission notice shall be included in
  244. # all copies or substantial portions of the Software.
  245. #
  246. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  247. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  248. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  249. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  250. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  251. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  252. # SOFTWARE.
  253. MD5=""
  254. # Check the which command exists
  255. WHICH=`which`
  256. if [ "" != "${WHICH}" ]; then
  257. echo "which command not found. Aborting.";
  258. exit 0;
  259. fi
  260. ###ADDITIONAL_STUFF###
  261. errordialog() {
  262. # Send message to console.
  263. echo ""
  264. echo "-----------------------------------------------------------------------"
  265. echo "Error: ${1}"
  266. echo "-----------------------------------------------------------------------"
  267. echo "${2}"
  268. echo "-----------------------------------------------------------------------"
  269. # Now try to use the GUI Dialogs.
  270. ISKDE=`pidof -x -s kdeinit`
  271. KDIALOG=`which kdialog`
  272. ISGNOME=`pidof -x -s gnome-panel`
  273. ZENITY=`which zenity`
  274. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  275. echo "Dialog on Display: ${DISPLAY}"
  276. ${KDIALOG} --title "DMDirc: ${1}" --error "${1}\n\n${2}"
  277. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  278. echo "Dialog on Display: ${DISPLAY}"
  279. ${ZENITY} --error --title "DMDirc: ${1}" --text "${1}\n\n${2}"
  280. fi
  281. }
  282. # Location of .run stub end
  283. ENDLINE=`grep -na "^###END INCLUDE###$" $0`
  284. ENDLINE=$((${ENDLINE%%:*} + 1))
  285. if [ "" = "${ENDLINE}" ]; then
  286. errordialog "DMDirc Setup" "End of stub not found. Aborting.";
  287. exit 0;
  288. fi
  289. # Attempt to get a name for a random dir in /tmp
  290. random() {
  291. # First off, lets try mktemp.
  292. MKTEMP=`which mktemp`
  293. if [ "" != "${MKTEMP}" ]; then
  294. # mktemp exists \o
  295. DIR=`${MKTEMP} -d`
  296. eval "$1=${DIR}"
  297. return;
  298. fi
  299. TMPDIR=${TMPDIR:=/tmp}
  300. BASEDIR=${TMPDIR}dmdirc_`whoami`_
  301. DIR=${PWD}
  302. while [ -d "${DIR}" ]; do
  303. if [ "" != "${RANDOM}" ]; then
  304. # Bash has a psuedo random number generator that can be accessed
  305. # using ${RANDOM}
  306. RND=${RANDOM}${RANDOM}${RANDOM}
  307. else
  308. # Dash (the ubuntu default sh) however does not.
  309. # od and awk however usually exist, and we can get a random number
  310. # from /dev/urandom or /dev/random
  311. OD=`which od`
  312. AWK=`which awk`
  313. RND=""
  314. if [ "" != "$OD" -a "" != "$AWK" ]; then
  315. # Try /dev/urandom first
  316. RAND=/dev/urandom
  317. # If it doesn't exist try /dev/random
  318. if [ ! -e "${RAND}" ]; then
  319. RAND=/dev/urandom;
  320. fi
  321. # This makes sure we only try to read if one exists
  322. if [ ! -e "${RAND}" ]; then
  323. RND=$(head -1 ${RAND} | od -N 3 -t u | awk '{ print $2 }')
  324. fi;
  325. fi;
  326. # No random number was generated, getting to here means that
  327. # ${RANDOM} doesn't exist, /dev/random doesn't exist, /dev/urandom doesn't exist
  328. # or that od/awk don't exist. Annoying.
  329. # Try using this processes PID instead!
  330. if [ "${RND}" = "" ]; then
  331. RND=$$
  332. DIR=${BASEDIR}${RND}
  333. if [ -e "${DIR}" ]; then
  334. # Lets hope this never happens.
  335. errordialog "DMDirc Setup" "Unable to create random directory";
  336. exit 0;
  337. fi;
  338. fi;
  339. fi;
  340. DIR=${BASEDIR}${RND}
  341. done
  342. mkdir ${DIR}
  343. eval "$1=${DIR}"
  344. }
  345. uncompress() {
  346. tail -n +${ENDLINE} "${OLDPWD}/$0" | gzip -cd | tar -xvf - 2>/dev/null || {
  347. echo "Decompression failed."
  348. kill -15 $$;
  349. };
  350. }
  351. showHelp() {
  352. echo "This will install DMDirc on a unix based system."
  353. echo "The following command line arguments are known:"
  354. echo "---------------------"
  355. echo "-h, --help Help information"
  356. echo "-e, --extract Extract .run file only, do not run setup.sh"
  357. echo "-s, --script Don't use installer.jar (not implemented yet)"
  358. echo "---------------------"
  359. exit 0;
  360. }
  361. # Defaults
  362. extractOnly="false"
  363. setupParams=""
  364. skipMD5="false"
  365. # Begin
  366. echo "---------------------"
  367. echo "DMDirc Unix Setup"
  368. if [ "${isRelease}" != "" ]; then
  369. echo "Version: "${isRelease};
  370. setupParams="${setupParams} --release "${isRelease}
  371. fi;
  372. echo "---------------------"
  373. # Check for cmdline args
  374. while test -n "$1"; do
  375. case "$1" in
  376. --help|-h)
  377. showHelp
  378. ;;
  379. --extract|-e)
  380. extractOnly="true"
  381. ;;
  382. --script|-s)
  383. setupParams="${setupParams} --script"
  384. ;;
  385. --nomd5)
  386. skipMD5="true"
  387. ;;
  388. esac
  389. shift
  390. done
  391. MD5BIN=`which md5sum`
  392. AWK=`which awk`
  393. getMD5() {
  394. # Everything below the MD5SUM Line
  395. MD5LINE=`grep -na "^MD5=\".*\"$" ${1}`
  396. MD5LINE=$((${MD5LINE%%:*} + 1))
  397. MD5SUM=`tail -n +${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  398. return;
  399. }
  400. if [ "${MD5BIN}" != "" ]; then
  401. if [ ${skipMD5} != "true" ]; then
  402. if [ -e "${0}.md5" ]; then
  403. echo "Checking MD5 using ${0}.md5.."
  404. ${MD5BIN} --check --status ${0}.md5
  405. if [ $? = 0 ]; then
  406. echo "MD5 Check Passed!"
  407. else
  408. ERROR="This copy of the DMDirc installer appears to be damaged and will now exit.";
  409. ERROR=${ERROR}"\nYou may choose to skip this check and run it anyway by passing the --nomd5 parameter";
  410. errordialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  411. exit 1;
  412. fi
  413. elif [ "${MD5}" != "" ]; then
  414. echo "Checking MD5 using built in hash.."
  415. if [ "${AWK}" != "" ]; then
  416. MD5SUM=""
  417. getMD5 ${0} ${MD5SUM}
  418. echo "SUM obtained is: ${MD5SUM}"
  419. echo "SUM expected is: ${MD5}"
  420. if [ "${MD5SUM}" = "${MD5}" ]; then
  421. echo "MD5 Check Passed!"
  422. else
  423. ERROR="This copy of the DMDirc installer appears to be damaged and will now exit.";
  424. ERROR=${ERROR}"\nYou may choose to skip this check and run it anyway by passing the --nomd5 parameter";
  425. errordialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  426. exit 1;
  427. fi;
  428. else
  429. echo "MD5 Check skipped (awk not found).."
  430. fi;
  431. else
  432. if [ "${MD5BIN}" = "" ]; then
  433. echo "MD5 Check skipped (md5sum not found).."
  434. else
  435. echo "MD5 Check skipped (No MD5 hash found to compare against).."
  436. fi
  437. fi;
  438. else
  439. echo "MD5 Check skipped (Requested).."
  440. fi
  441. fi;
  442. OLDPWD=${PWD}
  443. echo "Getting Temp Dir"
  444. random TEMPDIR
  445. echo "Got Temp Dir: ${TEMPDIR}"
  446. cd ${TEMPDIR}
  447. echo "Uncompressing to temp dir.."
  448. uncompress
  449. echo "Done."
  450. # Check if extract only was wanted.
  451. if [ "${extractOnly}" = "true" ]; then
  452. echo "Extracted. (Files can be found in: ${TEMPDIR})"
  453. exit 0;
  454. fi
  455. if [ -e "${TEMPDIR}/setup.sh" ]; then
  456. echo "Running setup.."
  457. chmod a+x ${TEMPDIR}/setup.sh
  458. ${TEMPDIR}/setup.sh ${setupParams}
  459. echo ""
  460. if [ $? -eq 0 ]; then
  461. echo "Setup completed."
  462. else
  463. echo "Setup failed."
  464. fi
  465. else
  466. echo "No setup.sh found. This was pointless?"
  467. fi
  468. echo "Removing temp dir"
  469. cd ${OLDPWD}
  470. rm -Rf ${TEMPDIR}
  471. echo "Installation Completed."
  472. # Job Done!
  473. exit 0;
  474. ###END INCLUDE###