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.

installerstub.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #!/bin/sh
  2. #
  3. # This script installs 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. MD5=""
  26. # Check the which command exists, and if so make sure it behaves how we want
  27. # it to...
  28. WHICH=`which which 2>/dev/null`
  29. if [ "" = "${WHICH}" ]; then
  30. echo "which command not found. Aborting.";
  31. exit 0;
  32. else
  33. # Solaris sucks
  34. BADWHICH=`which /`
  35. if [ "${BADWHICH}" != "" ]; then
  36. # "Which" on solaris gives non-empty results for commands that don't exist
  37. which() {
  38. OUT=`${WHICH} ${1}`
  39. if [ $? -eq 0 ]; then
  40. echo ${OUT}
  41. else
  42. echo ""
  43. fi;
  44. }
  45. fi;
  46. fi
  47. # Find out what params we should pass to things.
  48. # Solaris has a nice and ancient version of grep in /usr/bin
  49. grep -na "" /dev/null >/dev/null 2>&1
  50. if [ $? -eq 2 ]; then
  51. GREPOPTS="-n"
  52. else
  53. GREPOPTS="-na"
  54. fi;
  55. # Solaris also has a crappy version of tail!
  56. tail -n +1 /dev/null >/dev/null 2>&1
  57. if [ $? -eq 2 ]; then
  58. TAILOPTS="+"
  59. else
  60. TAILOPTS="-n +"
  61. fi;
  62. ###ADDITIONAL_STUFF###
  63. PIDOF=`which pidof`
  64. if [ "${PIDOF}" = "" ]; then
  65. # For some reason some distros hide pidof...
  66. if [ -e /sbin/pidof ]; then
  67. PIDOF=/sbin/pidof
  68. elif [ -e /usr/sbin/pidof ]; then
  69. PIDOF=/usr/sbin/pidof
  70. fi;
  71. fi;
  72. ## Helper Functions
  73. if [ "${PIDOF}" != "" ]; then
  74. ISKDE=`${PIDOF} -x -s kdeinit`
  75. ISGNOME=`${PIDOF} -x -s gnome-panel`
  76. else
  77. ISKDE=`ps -Af | grep kdeinit | grep -v grep`
  78. ISGNOME=`ps -Af | grep gnome-panel | grep -v grep`
  79. fi;
  80. KDIALOG=`which kdialog`
  81. ZENITY=`which zenity`
  82. errordialog() {
  83. # Send message to console.
  84. echo ""
  85. echo "-----------------------------------------------------------------------"
  86. echo "Error: ${1}"
  87. echo "-----------------------------------------------------------------------"
  88. echo "${2}"
  89. echo "-----------------------------------------------------------------------"
  90. # Now try to use the GUI Dialogs.
  91. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  92. echo "Dialog on Display: ${DISPLAY}"
  93. ${KDIALOG} --title "${1}" --error "${1}\n\n${2}"
  94. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  95. echo "Dialog on Display: ${DISPLAY}"
  96. ${ZENITY} --error --title "${1}" --text "${1}\n\n${2}"
  97. fi
  98. }
  99. questiondialog() {
  100. # Send question to console.
  101. echo ""
  102. echo "-----------------------------------------------------------------------"
  103. echo "Question: ${1}"
  104. echo "-----------------------------------------------------------------------"
  105. echo "${2}"
  106. echo "-----------------------------------------------------------------------"
  107. # Now try to use the GUI Dialogs.
  108. if [ "" != "${ISKDE}" -a "" != "${KDIALOG}" -a "" != "${DISPLAY}" ]; then
  109. echo "Dialog on Display: ${DISPLAY}"
  110. ${KDIALOG} --title "${1}" --yesno "${2}"
  111. elif [ "" != "${ISGNOME}" -a "" != "${ZENITY}" -a "" != "${DISPLAY}" ]; then
  112. echo "Dialog on Display: ${DISPLAY}"
  113. ${ZENITY} --question --title "${1}" --text "${2}"
  114. else
  115. echo "Unable to ask question, assuming no."
  116. return 1;
  117. fi
  118. }
  119. # Location of .run stub end
  120. ENDLINE=`grep ${GREPOPTS} "^###END STUB###$" $0`
  121. ENDLINE=$((${ENDLINE%%:*} + 1))
  122. if [ "" = "${ENDLINE}" ]; then
  123. errordialog "DMDirc Setup" "End of stub not found. Aborting.";
  124. exit 0;
  125. fi
  126. # Attempt to get a name for a random dir in /tmp
  127. random() {
  128. # First off, lets try mktemp.
  129. MKTEMP=`which mktemp`
  130. if [ "" != "${MKTEMP}" ]; then
  131. # mktemp exists \o
  132. DIR=`${MKTEMP} -d /tmp/DMDirc.XXXXXX`
  133. eval "$1=${DIR}"
  134. return;
  135. fi
  136. TMPDIR=${TMPDIR:=/tmp}
  137. BASEDIR=${TMPDIR}dmdirc_`whoami`_
  138. DIR=${PWD}
  139. while [ -d "${DIR}" ]; do
  140. if [ "" != "${RANDOM}" ]; then
  141. # Bash has a psuedo random number generator that can be accessed
  142. # using ${RANDOM}
  143. RND=${RANDOM}${RANDOM}${RANDOM}
  144. else
  145. # Dash (the ubuntu default sh) however does not.
  146. # od and awk however usually exist, and we can get a random number
  147. # from /dev/urandom or /dev/random
  148. OD=`which od`
  149. AWK=`which awk`
  150. RND=""
  151. if [ "" != "$OD" -a "" != "$AWK" ]; then
  152. # Try /dev/urandom first
  153. RAND=/dev/urandom
  154. # If it doesn't exist try /dev/random
  155. if [ ! -e "${RAND}" ]; then
  156. RAND=/dev/urandom;
  157. fi
  158. # This makes sure we only try to read if one exists
  159. if [ ! -e "${RAND}" ]; then
  160. RND=$(head -1 ${RAND} | od -N 3 -t u | awk '{ print $2 }')
  161. fi;
  162. fi;
  163. # No random number was generated, getting to here means that
  164. # ${RANDOM} doesn't exist, /dev/random doesn't exist, /dev/urandom doesn't exist
  165. # or that od/awk don't exist. Annoying.
  166. # Try using this processes PID instead!
  167. if [ "${RND}" = "" ]; then
  168. RND=$$
  169. DIR=${BASEDIR}${RND}
  170. if [ -e "${DIR}" ]; then
  171. # Lets hope this never happens.
  172. errordialog "DMDirc Setup" "Unable to create random directory";
  173. exit 0;
  174. fi;
  175. fi;
  176. fi;
  177. DIR=${BASEDIR}${RND}
  178. done
  179. mkdir ${DIR}
  180. eval "$1=${DIR}"
  181. }
  182. uncompress() {
  183. # DEBUGINFO="\n\nRunname: ${0}"
  184. # DEBUGINFO="${DEBUGINFO}\nOldPwd: ${OLDPWD}"
  185. # Try runname, in old dir.
  186. FILE=${OLDPWD}/$0
  187. if [ ! -e ${FILE} ]; then
  188. # Else, try run filename in old dir
  189. FILE=${OLDPWD}/`basename $0`
  190. if [ ! -e ${FILE} ]; then
  191. # Else try run name
  192. FILE=$0
  193. if [ ! -e ${FILE} ]; then
  194. # Unable to find this file!
  195. errordialog "DMDirc Setup" "Unable to find installer.\nThis shouldn't happen, please raise a bug report at http://bugs.dmdirc.com${DEBUGINFO}";
  196. echo "Removing temp dir"
  197. cd ${OLDPWD}
  198. rm -Rf ${TEMPDIR}
  199. exit 1;
  200. fi;
  201. fi;
  202. fi;
  203. echo "Decompressing: ${FILE}"
  204. # DEBUGINFO="${DEBUGINFO}\nFile: ${FILE}"
  205. # DEBUGINFO="${DEBUGINFO}\nCommand: tail ${TAILOPTS}${ENDLINE} "${FILE}" | gzip -cd | tar -xvf - 2>&1"
  206. OUTPUT=`tail ${TAILOPTS}${ENDLINE} "${FILE}" | gzip -cd | tar -xvf - 2>&1`
  207. if [ "${OUTPUT}" = "" ]; then
  208. echo "Decompression failed."
  209. errordialog "DMDirc Setup" "Decompression failed.\nThis shouldn't happen, please raise a bug report at http://bugs.dmdirc.com${DEBUGINFO}";
  210. echo "Removing temp dir"
  211. cd ${OLDPWD}
  212. rm -Rf ${TEMPDIR}
  213. exit 1;
  214. fi;
  215. echo "Decompression successful."
  216. }
  217. showHelp() {
  218. echo "This will install DMDirc on a unix based system."
  219. echo "The following command line arguments are known:"
  220. echo "---------------------"
  221. echo "-h, --help Help information"
  222. echo "-e, --extract Extract .run file only, do not run setup.sh"
  223. # echo "-s, --script Don't use installer.jar (not implemented yet)"
  224. echo "---------------------"
  225. exit 0;
  226. }
  227. # Defaults
  228. extractOnly="false"
  229. setupParams=""
  230. skipMD5="false"
  231. # Begin
  232. echo "---------------------"
  233. echo "DMDirc Unix Setup"
  234. if [ "${isRelease}" != "" ]; then
  235. echo "Version: "${isRelease};
  236. setupParams="${setupParams} --release "${isRelease}
  237. fi;
  238. echo "---------------------"
  239. # Check for cmdline args
  240. while test -n "$1"; do
  241. case "$1" in
  242. --help|-h)
  243. showHelp
  244. ;;
  245. --extract|-e)
  246. extractOnly="true"
  247. ;;
  248. --script|-s)
  249. setupParams="${setupParams} --script"
  250. ;;
  251. --nomd5)
  252. skipMD5="true"
  253. ;;
  254. esac
  255. shift
  256. done
  257. MD5BIN=`which md5sum`
  258. if [ "${MD5BIN}" = "" ]; then
  259. MD5BIN=`which md5`
  260. fi;
  261. AWK=`which awk`
  262. getMD5() {
  263. if [ "${MD5BIN}" != "" ]; then
  264. echo "test" | ${MD5BIN} -
  265. if [ $? -eq 0 ]; then
  266. echo "Linux-Style MD5SUM: ${MD5BIN}"
  267. getMD5Linux $@
  268. else
  269. echo "BSD-Style MD5SUM: ${MD5BIN}"
  270. getMD5BSD $@
  271. fi;
  272. fi;
  273. }
  274. getMD5Linux() {
  275. # Everything below the MD5SUM Line
  276. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  277. MD5LINE=$((${MD5LINE%%:*} + 1))
  278. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  279. return;
  280. }
  281. getMD5BSD() {
  282. # Everything below the MD5SUM Line
  283. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  284. MD5LINE=$((${MD5LINE%%:*} + 1))
  285. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} | ${AWK} '{print $1}'`
  286. return;
  287. }
  288. if [ "${MD5BIN}" != "" ]; then
  289. if [ ${skipMD5} != "true" ]; then
  290. #if [ -e "${0}.md5" ]; then
  291. # echo "Checking MD5 using ${0}.md5.."
  292. # ${MD5BIN} --check --status ${0}.md5
  293. # if [ $? = 0 ]; then
  294. # echo "MD5 Check Passed!"
  295. # else
  296. # ERROR="This copy of the DMDirc installer appears to be damaged and will now exit.";
  297. # ERROR=${ERROR}"\nYou may choose to skip this check and run it anyway by passing the --nomd5 parameter";
  298. # errordialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  299. # exit 1;
  300. # fi
  301. #elif [ "${MD5}" != "" ]; then
  302. if [ "${MD5}" != "" ]; then
  303. echo "Checking MD5 using built in hash.."
  304. if [ "${AWK}" != "" ]; then
  305. MD5SUM=""
  306. getMD5 ${0} ${MD5SUM}
  307. echo "SUM obtained is: ${MD5SUM}"
  308. echo "SUM expected is: ${MD5}"
  309. if [ "${MD5SUM}" = "${MD5}" ]; then
  310. echo "MD5 Check Passed!"
  311. elif [ "${MD5SUM}" = "" -o "${MD5}" = "" ]; then
  312. ERROR="The DMDirc installer is unable to verify the checksum of this download.";
  313. if [ "${MD5SUM}" = "" ]; then
  314. ERROR=${ERROR}"(Unable to calculate sum locally)";
  315. else
  316. ERROR=${ERROR}"(No checksum found in file)";
  317. fi;
  318. ERROR=${ERROR}"\nDo you want to continue anyway?";
  319. questiondialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  320. exit 1;
  321. else
  322. ERROR="This copy of the DMDirc installer appears to be damaged and will now exit.";
  323. ERROR=${ERROR}"\nYou may choose to skip this check and run it anyway by passing the --nomd5 parameter";
  324. errordialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  325. exit 1;
  326. fi;
  327. else
  328. echo "MD5 Check skipped (awk not found).."
  329. fi;
  330. else
  331. #if [ "${MD5BIN}" = "" ]; then
  332. # echo "MD5 Check skipped (md5sum not found).."
  333. #else
  334. echo "MD5 Check skipped (No MD5 hash found to compare against).."
  335. #fi
  336. fi;
  337. else
  338. echo "MD5 Check skipped (Requested).."
  339. fi
  340. fi;
  341. OLDPWD=${PWD}
  342. echo "Getting Temp Dir"
  343. random TEMPDIR
  344. echo "Got Temp Dir: ${TEMPDIR}"
  345. cd ${TEMPDIR}
  346. echo "Uncompressing to temp dir.."
  347. uncompress
  348. echo "Done."
  349. # Check if extract only was wanted.
  350. if [ "${extractOnly}" = "true" ]; then
  351. echo "Extracted. (Files can be found in: ${TEMPDIR})"
  352. exit 0;
  353. fi
  354. if [ -e "${TEMPDIR}/setup.sh" ]; then
  355. echo "Running setup.."
  356. chmod a+x ${TEMPDIR}/setup.sh
  357. ${TEMPDIR}/setup.sh ${setupParams}
  358. echo ""
  359. if [ $? -eq 0 ]; then
  360. echo "Setup completed."
  361. else
  362. echo "Setup failed."
  363. fi
  364. else
  365. echo "No setup.sh found. This was pointless?"
  366. fi
  367. echo "Removing temp dir"
  368. cd ${OLDPWD}
  369. rm -Rf ${TEMPDIR}
  370. echo "Installation Completed."
  371. # Job Done!
  372. exit 0;
  373. ###END STUB###