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

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