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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. #!/bin/sh
  2. #
  3. # This script installs 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. 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. ###FUNCTIONS_FILE###
  64. # Location of .run stub end
  65. ENDLINE=`grep ${GREPOPTS} "^###END STUB###$" $0`
  66. ENDLINE=$((${ENDLINE%%:*} + 1))
  67. if [ "" = "${ENDLINE}" ]; then
  68. errordialog "DMDirc Setup" "End of stub not found. Aborting.";
  69. exit 0;
  70. fi
  71. # Attempt to get a name for a random dir in /tmp
  72. random() {
  73. # First off, lets try mktemp.
  74. MKTEMP=`which mktemp`
  75. if [ "" != "${MKTEMP}" ]; then
  76. # mktemp exists \o
  77. DIR=`${MKTEMP} -d /tmp/DMDirc.XXXXXX`
  78. eval "$1=${DIR}"
  79. return;
  80. fi
  81. TMPDIR=${TMPDIR:=/tmp}
  82. BASEDIR=${TMPDIR}dmdirc_`whoami`_
  83. DIR=${PWD}
  84. while [ -d "${DIR}" ]; do
  85. if [ "" != "${RANDOM}" ]; then
  86. # Bash has a psuedo random number generator that can be accessed
  87. # using ${RANDOM}
  88. RND=${RANDOM}${RANDOM}${RANDOM}
  89. else
  90. # Dash (the ubuntu default sh) however does not.
  91. # od and awk however usually exist, and we can get a random number
  92. # from /dev/urandom or /dev/random
  93. OD=`which od`
  94. AWK=`which awk`
  95. RND=""
  96. if [ "" != "$OD" -a "" != "$AWK" ]; then
  97. # Try /dev/urandom first
  98. RAND=/dev/urandom
  99. # If it doesn't exist try /dev/random
  100. if [ ! -e "${RAND}" ]; then
  101. RAND=/dev/urandom;
  102. fi
  103. # This makes sure we only try to read if one exists
  104. if [ ! -e "${RAND}" ]; then
  105. RND=$(head -1 ${RAND} | od -N 3 -t u | awk '{ print $2 }')
  106. fi;
  107. fi;
  108. # No random number was generated, getting to here means that
  109. # ${RANDOM} doesn't exist, /dev/random doesn't exist, /dev/urandom doesn't exist
  110. # or that od/awk don't exist. Annoying.
  111. # Try using this processes PID instead!
  112. if [ "${RND}" = "" ]; then
  113. RND=$$
  114. DIR=${BASEDIR}${RND}
  115. if [ -e "${DIR}" ]; then
  116. # Lets hope this never happens.
  117. errordialog "DMDirc Setup" "Unable to create random directory";
  118. exit 0;
  119. fi;
  120. fi;
  121. fi;
  122. DIR=${BASEDIR}${RND}
  123. done
  124. mkdir ${DIR}
  125. eval "$1=${DIR}"
  126. }
  127. uncompress() {
  128. # DEBUGINFO="\n\nRunname: ${0}"
  129. # DEBUGINFO="${DEBUGINFO}\nOldPwd: ${OLDPWD}"
  130. # Try runname, in old dir.
  131. FILE=${OLDPWD}/$0
  132. if [ ! -e ${FILE} ]; then
  133. # Else, try run filename in old dir
  134. FILE=${OLDPWD}/`basename $0`
  135. if [ ! -e ${FILE} ]; then
  136. # Else try run name
  137. FILE=$0
  138. if [ ! -e ${FILE} ]; then
  139. # Unable to find this file!
  140. errordialog "DMDirc Setup" "Unable to find installer.\nThis shouldn't happen, please raise a bug report at http://bugs.dmdirc.com${DEBUGINFO}";
  141. echo "Removing temp dir"
  142. cd ${OLDPWD}
  143. rm -Rf ${TEMPDIR}
  144. exit 1;
  145. fi;
  146. fi;
  147. fi;
  148. echo "Decompressing: ${FILE}"
  149. # DEBUGINFO="${DEBUGINFO}\nFile: ${FILE}"
  150. # DEBUGINFO="${DEBUGINFO}\nCommand: tail ${TAILOPTS}${ENDLINE} "${FILE}" | gzip -cd | tar -xvf - 2>&1"
  151. OUTPUT=`tail ${TAILOPTS}${ENDLINE} "${FILE}" | gzip -cd | tar -xvf - 2>&1`
  152. if [ "${OUTPUT}" = "" ]; then
  153. echo "Decompression failed."
  154. errordialog "DMDirc Setup" "Decompression failed.\nThis shouldn't happen, please raise a bug report at http://bugs.dmdirc.com${DEBUGINFO}";
  155. echo "Removing temp dir"
  156. cd ${OLDPWD}
  157. rm -Rf ${TEMPDIR}
  158. exit 1;
  159. fi;
  160. echo "Decompression successful."
  161. }
  162. showHelp() {
  163. echo "This will install DMDirc on a unix based system."
  164. echo "The following command line arguments are known:"
  165. echo "---------------------"
  166. echo "-h, --help Help information"
  167. echo "-e, --extract Extract .run file only, do not run setup.sh"
  168. # echo "-s, --script Don't use installer.jar (not implemented yet)"
  169. echo "---------------------"
  170. exit 0;
  171. }
  172. # Defaults
  173. extractOnly="false"
  174. setupParams=""
  175. skipMD5="false"
  176. # Begin
  177. echo "---------------------"
  178. echo "DMDirc Unix Setup"
  179. if [ "${isRelease}" != "" ]; then
  180. echo "Version: "${isRelease};
  181. setupParams="${setupParams} --release "${isRelease}
  182. fi;
  183. echo "---------------------"
  184. # Check for cmdline args
  185. while test -n "$1"; do
  186. case "$1" in
  187. --help|-h)
  188. showHelp
  189. ;;
  190. --extract|-e)
  191. extractOnly="true"
  192. ;;
  193. --script|-s)
  194. setupParams="${setupParams} --script"
  195. ;;
  196. --nomd5)
  197. skipMD5="true"
  198. ;;
  199. esac
  200. shift
  201. done
  202. MD5BIN=`which md5sum`
  203. if [ "${MD5BIN}" = "" ]; then
  204. MD5BIN=`which md5`
  205. fi;
  206. AWK=`which awk`
  207. getMD5() {
  208. if [ "${MD5BIN}" != "" ]; then
  209. echo "test" | ${MD5BIN} -
  210. if [ $? -eq 0 ]; then
  211. echo "Linux-Style MD5SUM: ${MD5BIN}"
  212. getMD5Linux $@
  213. else
  214. echo "BSD-Style MD5SUM: ${MD5BIN}"
  215. getMD5BSD $@
  216. fi;
  217. fi;
  218. }
  219. getMD5Linux() {
  220. # Everything below the MD5SUM Line
  221. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  222. MD5LINE=$((${MD5LINE%%:*} + 1))
  223. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} - | ${AWK} '{print $1}'`
  224. return;
  225. }
  226. getMD5BSD() {
  227. # Everything below the MD5SUM Line
  228. MD5LINE=`grep ${GREPOPTS} "^MD5=\".*\"$" ${1}`
  229. MD5LINE=$((${MD5LINE%%:*} + 1))
  230. MD5SUM=`tail ${TAILOPTS}${MD5LINE} "${1}" | ${MD5BIN} | ${AWK} '{print $1}'`
  231. return;
  232. }
  233. if [ "${MD5BIN}" != "" ]; then
  234. if [ ${skipMD5} != "true" ]; then
  235. #if [ -e "${0}.md5" ]; then
  236. # echo "Checking MD5 using ${0}.md5.."
  237. # ${MD5BIN} --check --status ${0}.md5
  238. # if [ $? = 0 ]; then
  239. # echo "MD5 Check Passed!"
  240. # else
  241. # ERROR="This copy of the DMDirc installer appears to be damaged and will now exit.";
  242. # ERROR=${ERROR}"\nYou may choose to skip this check and run it anyway by passing the --nomd5 parameter";
  243. # errordialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  244. # exit 1;
  245. # fi
  246. #elif [ "${MD5}" != "" ]; then
  247. if [ "${MD5}" != "" ]; then
  248. echo "Checking MD5 using built in hash.."
  249. if [ "${AWK}" != "" ]; then
  250. MD5SUM=""
  251. getMD5 ${0} ${MD5SUM}
  252. echo "SUM obtained is: ${MD5SUM}"
  253. echo "SUM expected is: ${MD5}"
  254. if [ "${MD5SUM}" = "${MD5}" ]; then
  255. echo "MD5 Check Passed!"
  256. elif [ "${MD5SUM}" = "" -o "${MD5}" = "" ]; then
  257. ERROR="The DMDirc installer is unable to verify the checksum of this download.";
  258. if [ "${MD5SUM}" = "" ]; then
  259. ERROR=${ERROR}"(Unable to calculate sum locally)";
  260. else
  261. ERROR=${ERROR}"(No checksum found in file)";
  262. fi;
  263. ERROR=${ERROR}"\nDo you want to continue anyway?";
  264. questiondialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  265. exit 1;
  266. else
  267. ERROR="This copy of the DMDirc installer appears to be damaged and will now exit.";
  268. ERROR=${ERROR}"\nYou may choose to skip this check and run it anyway by passing the --nomd5 parameter";
  269. errordialog "DMDirc Setup: MD5 Check Failed!" "${ERROR}";
  270. exit 1;
  271. fi;
  272. else
  273. echo "MD5 Check skipped (awk not found).."
  274. fi;
  275. else
  276. #if [ "${MD5BIN}" = "" ]; then
  277. # echo "MD5 Check skipped (md5sum not found).."
  278. #else
  279. echo "MD5 Check skipped (No MD5 hash found to compare against).."
  280. #fi
  281. fi;
  282. else
  283. echo "MD5 Check skipped (Requested).."
  284. fi
  285. fi;
  286. OLDPWD=${PWD}
  287. echo "Getting Temp Dir"
  288. random TEMPDIR
  289. echo "Got Temp Dir: ${TEMPDIR}"
  290. cd ${TEMPDIR}
  291. echo "Uncompressing to temp dir.."
  292. uncompress
  293. echo "Done."
  294. # Check if extract only was wanted.
  295. if [ "${extractOnly}" = "true" ]; then
  296. echo "Extracted. (Files can be found in: ${TEMPDIR})"
  297. exit 0;
  298. fi
  299. if [ -e "${TEMPDIR}/setup.sh" ]; then
  300. echo "Running setup.."
  301. chmod a+x ${TEMPDIR}/setup.sh
  302. ${TEMPDIR}/setup.sh ${setupParams}
  303. echo ""
  304. if [ $? -eq 0 ]; then
  305. echo "Setup completed."
  306. else
  307. echo "Setup did not complete."
  308. fi
  309. else
  310. echo "No setup.sh found. This was pointless?"
  311. fi
  312. echo "Removing temp dir"
  313. cd ${OLDPWD}
  314. rm -Rf ${TEMPDIR}
  315. echo "Installation Completed."
  316. # Job Done!
  317. exit 0;
  318. ###END STUB###