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.

makeInstallerWindows.sh 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. #!/bin/sh
  2. #
  3. # This script generates a .exe file that will install DMDirc
  4. #
  5. # DMDirc - Open Source IRC Client
  6. # Copyright (c) 2006-2009 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. # Name of the extractor
  26. RUNNAME=extractor.exe
  27. # Name of the installer (without .exe)
  28. INSTALLNAME=DMDirc-Setup
  29. # Name of the internal file
  30. INTNAME=extractor.7z
  31. # full name of the files to output to
  32. RUNNAME="${PWD}/${RUNNAME}"
  33. INTNAME="${PWD}/${INTNAME}"
  34. # Get 7zip path
  35. ZIP=`which 7z`
  36. # Are we a git working copy, or SVN?
  37. if [ -e ".svn" ]; then
  38. isSVN=1
  39. else
  40. isSVN=0
  41. fi;
  42. if [ "" = "${ZIP}" ]; then
  43. echo "7Zip not found, failing."
  44. exit 1;
  45. fi
  46. # Compress stuff!
  47. compress() {
  48. ${ZIP} a -yl ${INTNAME} $@ 2>/dev/null || {
  49. echo "Compression failed."
  50. kill -15 $$;
  51. };
  52. }
  53. # Get signcode path
  54. SIGNCODE=`which signcode`
  55. if [ "" = "${SIGNCODE}" ]; then
  56. echo "Signcode not found. EXE's will not be digitally signed."
  57. fi
  58. # Sign stuff!
  59. signexe() {
  60. return;
  61. if [ "" != "${SIGNCODE}" ]; then
  62. if [ -e "../signing/DMDirc.spc" -a -e "../signing/DMDirc.pvk" ]; then
  63. echo "Digitally Signing EXE (${@})..."
  64. ${SIGNCODE} -spc "../signing/DMDirc.spc" -v "../signing/DMDirc.pvk" -i "http://www.dmdirc.com/" -n "DMDirc Installer" $@ 2>/dev/null || {
  65. kill -15 $$;
  66. };
  67. rm ${@}.sig
  68. rm ${@}.bak
  69. fi
  70. fi
  71. }
  72. WGET=`which wget`
  73. FETCH=`which fetch`
  74. CURL=`which curl`
  75. getFile() {
  76. URL=${1}
  77. OUTPUT=${2}
  78. if [ "${WGET}" != "" ]; then
  79. ${WGET} -O ${OUTPUT} ${URL}
  80. elif [ "${FETCH}" != "" ]; then
  81. ${FETCH} -o ${OUTPUT} ${URL}
  82. elif [ "${CURL}" != "" ]; then
  83. ${CURL} -o ${OUTPUT} ${URL}
  84. fi;
  85. }
  86. # Check for some CLI params
  87. compileJar="false"
  88. updateSVN="true"
  89. compileSetup="false"
  90. useOldSetup="false"
  91. isRelease=""
  92. useUPX="false"
  93. finalTag=""
  94. signEXE="true"
  95. compilerFlags="-Xs -XX -O2 -Or -Op1"
  96. BRANCH="0"
  97. plugins=""
  98. if [ $isSVN -eq 1 ]; then
  99. location="../../../"
  100. current=""
  101. else
  102. location="../../"
  103. current="1"
  104. fi;
  105. jarfile=""
  106. jre=""
  107. jrename="jre" # Filename for JRE without the .exe
  108. TAGGED=""
  109. showHelp() {
  110. echo "This will generate a DMDirc installer for a windows based system."
  111. echo "The following command line arguments are known:"
  112. echo "---------------------"
  113. echo "-h, --help Help information"
  114. echo "-r, --release <version> Generate a file based on an svn tag (or branch with -b aswell)"
  115. echo "-b, --branch Release in -r is a branch "
  116. echo "-s, --setup Recompile the .exe file"
  117. echo "-o, If setup.exe compile fails, use old version"
  118. echo "-p, --plugins <plugins> What plugins to add to the jar file"
  119. echo "-c, --compile Recompile the .jar file"
  120. echo "-u, --unsigned Don't sign the exe"
  121. echo "-e, --extra <tag> Tag to add to final exe name to distinguish this build from a standard build"
  122. echo "-f, --flags <flags> Extra flags to pass to the compiler"
  123. echo " --jre Include the JRE in this installer"
  124. echo " --jar <file> use <file> as DMDirc.jar"
  125. echo " --current Use the current folder as the base for the build"
  126. # This is not in the help cos its crappy really, and makes little/no difference to the
  127. # exe size unless debugging information is added using --flags, in which case the person
  128. # probably is Dataforce and knows about this flag anyway
  129. # echo " --upx UPX binary if UPX is available on the path,"
  130. # echo " (Compression Level: 4 for signed exe, 9 for unsigned)"
  131. echo "-k, --keep Keep the existing source tree when compiling"
  132. echo " (don't svn update beforehand)"
  133. echo "---------------------"
  134. exit 0;
  135. }
  136. while test -n "$1"; do
  137. case "$1" in
  138. --plugins|-p)
  139. shift
  140. plugins=${1}
  141. ;;
  142. --jar)
  143. shift
  144. jarfile=${1}
  145. ;;
  146. --jre)
  147. jre="http://www.dmdirc.com/getjava/windows/all"
  148. ;;
  149. --jre64)
  150. # No specific jre64 for windows.
  151. echo "No specific 64ibt JRE for windows, exiting"
  152. exit 1;
  153. ;;
  154. --current)
  155. location="../../"
  156. current="1"
  157. ;;
  158. --compile|-c)
  159. compileJar="true"
  160. ;;
  161. --setup|-s)
  162. compileSetup="true"
  163. ;;
  164. -o)
  165. useOldSetup="true"
  166. ;;
  167. --release|-r)
  168. shift
  169. isRelease=${1}
  170. ;;
  171. --extra|-e)
  172. shift
  173. finalTag="-${1}"
  174. ;;
  175. --flags|-f)
  176. shift
  177. compilerFlags="${1} "
  178. ;;
  179. --upx)
  180. useUPX="true"
  181. ;;
  182. --unsigned|-u)
  183. signEXE="false"
  184. ;;
  185. --keep|-k)
  186. updateSVN="false"
  187. ;;
  188. --help|-h)
  189. showHelp;
  190. ;;
  191. --branch|-b)
  192. BRANCH="1"
  193. ;;
  194. --tag|-t)
  195. shift
  196. REGEX="^[0-9]+(\.[0-9]+(\.[0-9]+)?)?$"
  197. CHECKTAG=`echo ${1} | egrep "${REGEX}"`
  198. if [ "" = "${CHECKTAG}" ]; then
  199. echo "Specified tag ("${1}") is invalid."
  200. exit 1;
  201. fi;
  202. TAGGED="${1}"
  203. ;;
  204. esac
  205. shift
  206. done
  207. # Go!
  208. echo "-----------"
  209. if [ -e "${RUNNAME}" ]; then
  210. echo "Removing existing .exe file"
  211. rm -Rf "${RUNNAME}"
  212. fi
  213. if [ -e "${INTNAME}" ]; then
  214. echo "Removing existing .7z file"
  215. rm -Rf "${INTNAME}"
  216. fi
  217. echo "Creating .7z file"
  218. if [ "" = "${current}" ]; then
  219. jarPath="${location}trunk"
  220. else
  221. jarPath="${location}"
  222. fi
  223. if [ "${isRelease}" != "" ]; then
  224. if [ $isSVN -eq 1 ]; then
  225. if [ "${BRANCH}" != "0" ]; then
  226. if [ -e "${location}/${isRelease}" ]; then
  227. jarPath="${location}/${isRelease}"
  228. else
  229. echo "Branch "${isRelease}" not found."
  230. exit 1;
  231. fi
  232. else
  233. if [ -e "${location}/${isRelease}" ]; then
  234. jarPath="${location}/${isRelease}"
  235. else
  236. echo "Tag "${isRelease}" not found."
  237. exit 1;
  238. fi
  239. fi
  240. fi
  241. fi
  242. if [ "" = "${jarfile}" ]; then
  243. jarfile=${jarPath}"/dist/DMDirc.jar"
  244. if [ ! -e ${jarPath}"/dist/DMDirc.jar" -o "${compileJar}" = "true" ]; then
  245. echo "Creating jar.."
  246. OLDPWD=${PWD}
  247. cd ${jarPath}
  248. if [ "${updateSVN}" = "true" ]; then
  249. svn update
  250. fi
  251. rm -Rf build dist
  252. ant jar
  253. if [ ! -e "dist/DMDirc.jar" ]; then
  254. echo "There was an error creating the .jar file. Aborting."
  255. exit 1;
  256. fi;
  257. cd ${OLDPWD}
  258. fi;
  259. elif [ ! -e "${jarfile}" ]; then
  260. echo "Requested Jar file (${jarfile}) does not exist."
  261. exit 1;
  262. fi;
  263. if [ "" = "${plugins}" ]; then
  264. echo "Linking jar (${jarfile}).."
  265. ln -sf ${jarfile} "./DMDirc.jar"
  266. else
  267. echo "Copying jar (${jarfile}).."
  268. cp ${jarfile} "./DMDirc.jar"
  269. echo "Adding plugins to jar"
  270. ln -sf ${jarPath}"/plugins"
  271. pluginList=""
  272. for plugin in ${plugins}; do
  273. pluginList=${pluginList}" plugins/${plugin}"
  274. done
  275. jar -uvf "DMDirc.jar" ${pluginList}
  276. rm -Rf plugins;
  277. fi
  278. if [ $isSVN -eq 1 -o "${TAGGED}" = "" ]; then
  279. echo " ReleaseNumber: String = '${isRelease}';" > SetupConsts.inc
  280. else
  281. echo " ReleaseNumber: String = '${TAGGED}';" > SetupConsts.inc
  282. fi;
  283. FILES=""
  284. # Icon Res file
  285. if [ -e ${jarPath}"/src/com/dmdirc/res/icon.ico" ]; then
  286. ln -sf ${jarPath}"/src/com/dmdirc/res/icon.ico" ./icon.ico
  287. FILES="${FILES} icon.ico"
  288. fi
  289. echo "icon.ico ICON icon.ico" > icon.rc
  290. # Other resources
  291. echo "extractor RCDATA extractor.exe" > files.rc
  292. COMPILER_IS_BROKEN="0";
  293. if [ $isSVN -eq 1 -o "${TAGGED}" = "" ]; then
  294. NUM="${1}"
  295. else
  296. NUM="${TAGGED}"
  297. fi;
  298. # Version Numbers
  299. if [ "" = "${NUM}" ]; then
  300. MAJORVER="0"
  301. MINORVER="0"
  302. RELEASE="0"
  303. TEXTVER="${isRelease}"
  304. PRIVATE="1"
  305. USER=`whoami`
  306. HOST=`hostname`
  307. DATE=`date`
  308. else
  309. MAJORVER=${NUM%%.*}
  310. SUBVER=${NUM#*.}
  311. DOT=`expr index "${SUBVER}" .`
  312. if [ "${DOT}" = "0" ]; then
  313. MINORVER=${SUBVER}
  314. RELEASE="0"
  315. else
  316. MINORVER=${SUBVER%%.*}
  317. RELEASE=${SUBVER##*.}
  318. fi
  319. TEXTVER=$NUM
  320. PRIVATE="0"
  321. fi;
  322. # Information for the below section:
  323. #
  324. # http://support.microsoft.com/kb/139491
  325. # http://msdn2.microsoft.com/en-us/library/aa381049.aspx
  326. # http://courses.cs.vt.edu/~cs3304/FreePascal/doc/prog/node14.html#SECTION001440000000000000000
  327. # http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/src/Resources/TortoiseShell.rc2
  328. echo "1 VERSIONINFO" > version.rc.1
  329. echo "FILEVERSION 1, 0, 0, 0" >> version.rc.1
  330. echo "PRODUCTVERSION ${MAJORVER}, ${MINORVER}, ${RELEASE}, 0" >> version.rc.1
  331. if [ "${PRIVATE}" = "1" ]; then
  332. if [ "${COMPILER_IS_BROKEN}" = "0" ]; then
  333. echo "FILEFLAGSMASK 0x000A" >> version.rc.1
  334. echo "FILEFLAGS 0x3f" >> version.rc.1
  335. else
  336. echo "FILEFLAGS 0x000A" >> version.rc.1
  337. fi;
  338. else
  339. echo "FILEFLAGSMASK 0" >> version.rc.1
  340. fi;
  341. echo "FILEOS 0x40004" >> version.rc.1
  342. echo "FILETYPE 1" >> version.rc.1
  343. echo "BEGIN" >> version.rc.1
  344. echo " BLOCK \"StringFileInfo\"" >> version.rc.1
  345. echo " BEGIN" >> version.rc.1
  346. echo " BLOCK \"040004E4\"" >> version.rc.1
  347. echo " BEGIN" >> version.rc.1
  348. echo " VALUE \"Comments\", \"http://www.dmdirc.com/\"" >> version.rc.1
  349. echo " VALUE \"CompanyName\", \"DMDirc\"" >> version.rc.1
  350. cat version.rc.1 > version.rc
  351. cat version.rc.1 > uninstallversion.rc
  352. rm version.rc.1
  353. echo " VALUE \"FileDescription\", \"Installer for DMDirc ${TEXTVER}\"" >> version.rc
  354. echo " VALUE \"FileDescription\", \"Uninstaller for DMDirc\"" >> uninstallversion.rc
  355. echo " VALUE \"FileVersion\", \"2.0\"" > version.rc.2
  356. echo " VALUE \"InternalName\", \"DMDirc.jar\"" >> version.rc.2
  357. echo " VALUE \"LegalCopyright\", \"Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes\"" >> version.rc.2
  358. echo " VALUE \"OriginalFilename\", \"$2\"" >> version.rc.2
  359. echo " VALUE \"ProductName\", \"DMDirc\"" >> version.rc.2
  360. echo " VALUE \"ProductVersion\", \"${TEXTVER}\"" >> version.rc.2
  361. if [ "${PRIVATE}" = "1" ]; then
  362. echo " VALUE \"PrivateBuild\", \"Build by ${USER}@${HOST} on ${DATE}\"" >> version.rc.2
  363. fi;
  364. echo " END" >> version.rc.2
  365. echo " END" >> version.rc.2
  366. echo " BLOCK \"VarFileInfo\"" >> version.rc.2
  367. echo " BEGIN" >> version.rc.2
  368. echo " VALUE \"Translation\", 0x400, 1252" >> version.rc.2
  369. echo " END" >> version.rc.2
  370. echo "END" >> version.rc.2
  371. cat version.rc.2 >> version.rc
  372. cat version.rc.2 >> uninstallversion.rc
  373. rm version.rc.2
  374. echo "1 24 \"UAC.manifest\"" > UAC.rc
  375. # Build res files
  376. #windres -F pe-i386 -i version.rc -o version.res
  377. #windres -F pe-i386 -i files.rc -o files.res
  378. #windres -F pe-i386 -i icon.rc -o icon.res
  379. cat UAC.rc > uninstall.rc
  380. cat uninstallversion.rc >> all.rc
  381. cat icon.rc >> uninstall.rc
  382. windres -F pe-i386 -i uninstall.rc -o uninstall.res
  383. cat UAC.rc > all.rc
  384. cat version.rc >> all.rc
  385. cat files.rc >> all.rc
  386. cat icon.rc >> all.rc
  387. # Build later after extractor.exe exists
  388. cat UAC.rc > most.rc
  389. cat version.rc >> most.rc
  390. cat icon.rc >> most.rc
  391. windres -F pe-i386 -i most.rc -o most.res
  392. FILES="${FILES} DMDirc.jar Setup.exe";
  393. if [ "" != "${jre}" ]; then
  394. if [ ! -e "../common/${jrename}.exe" ]; then
  395. echo "Downloading JRE to include in installer"
  396. getFile "${jre}" "../common/${jrename}.exe"
  397. fi
  398. ln -sf ../common/${jrename}.exe jre.exe
  399. FILES="${FILES} jre.exe"
  400. fi;
  401. DELETEFILES=${FILES}
  402. if [ "" != "${DMDIRC_FPC}" ]; then
  403. FPC=${DMDIRC_FPC}
  404. else
  405. FPC=`which fpc`
  406. fi;
  407. lazarusDir="/usr/share/lazarus"
  408. if [ ! -e "${lazarusDir}/lcl" ]; then
  409. lazarusDir="/usr/lib/lazarus/"
  410. fi;
  411. compilerFlags="-Sd -Twin32 ${compilerFlags}";
  412. extraFlags=""
  413. if [ ! -e "Setup.exe" -o "${compileSetup}" = "true" ]; then
  414. echo "Setup.exe does not exist. Lets try and compile it."
  415. if [ "${FPC}" = "" ]; then
  416. echo "FPC Compiler not found, Setup.exe can not be built."
  417. exit 1;
  418. else
  419. echo "Building Setup.exe..."
  420. extraFlags=""
  421. if [ -e "${lazarusDir}/lcl" ]; then
  422. echo "Using Lazarus"
  423. mkdir -p ${PWD}/lazarus-build
  424. extraFlags="-dLAZARUS -FU${PWD}/lazarus-build -Fu${PWD}/lazarus-build -Fu${lazarusDir}/lcl/widgetset/ -Fu${lazarusDir}/lcl/interfaces/win32/ -Fu${lazarusDir}/lcl/ -Fi${lazarusDir}/lcl/include/"
  425. else
  426. echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
  427. echo "@ Building installer *WITHOUT* lazarus. @";
  428. echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
  429. fi;
  430. ${FPC} ${compilerFlags} ${extraFlags} Setup.dpr
  431. if [ $? -ne 0 ]; then
  432. if [ -e "Setup.exe" -a "${useOldSetup}" = "true" ]; then
  433. echo "Unable to compile Setup.exe, using existing version."
  434. else
  435. echo "Unable to compile Setup.exe, terminating."
  436. exit 1;
  437. fi
  438. fi;
  439. fi
  440. fi
  441. ls
  442. if [ ! -e "Setup.exe" ]; then
  443. echo "Still can't find Setup.exe, terminating."
  444. exit 1;
  445. fi
  446. echo "Compressing files.."
  447. # Shortcut.exe is from http://www.optimumx.com/download/#Shortcut
  448. if [ ! -e Shortcut.exe ]; then
  449. getFile "http://binary.dmdirc.com/Shortcut.zip" "Shortcut.zip"
  450. unzip -q Shortcut.zip Shortcut.exe
  451. rm Shortcut.zip
  452. fi
  453. FILES="${FILES} Shortcut.exe"
  454. DELETEFILES="${DELETEFILES} Shortcut.exe"
  455. if [ "${isRelease}" != "" ]; then
  456. DOCSDIR=${jarPath}
  457. else
  458. DOCSDIR="../common"
  459. fi
  460. if [ -e "${DOCSDIR}/README.TXT" ]; then
  461. ln -sf "${DOCSDIR}/README.TXT" .
  462. FILES="${FILES} README.TXT"
  463. DELETEFILES="${DELETEFILES} README.TXT"
  464. fi
  465. if [ -e "${DOCSDIR}/CHANGES.TXT" ]; then
  466. ln -sf "${DOCSDIR}/CHANGES.TXT" .
  467. FILES="${FILES} CHANGES.TXT"
  468. DELETEFILES="${DELETEFILES} CHANGES.TXT"
  469. elif [ -e "${DOCSDIR}/CHANGELOG.TXT" ]; then
  470. ln -sf "${DOCSDIR}/CHANGELOG.TXT" .
  471. FILES="${FILES} CHANGELOG.TXT"
  472. DELETEFILES="${DELETEFILES} CHANGELOG.TXT"
  473. fi
  474. if [ -e "${jarPath}/launcher/windows" ]; then
  475. # Try to compile all
  476. olddir=${PWD}
  477. cd "${jarPath}/launcher/windows/"
  478. sh compile.sh
  479. cd ${olddir}
  480. # Now add to file list.
  481. for thisfile in `ls -1 ${jarPath}/launcher/windows/*.exe`; do
  482. ln -sf ${thisfile} .
  483. FILES="${FILES} ${thisfile}"
  484. done
  485. fi
  486. ${FPC} ${compilerFlags} ${3}Uninstaller.dpr
  487. if [ -e "Uninstaller.exe" ]; then
  488. FILES="${FILES} Uninstaller.exe"
  489. # DELETEFILES="${DELETEFILES} Uninstaller.exe"
  490. fi
  491. # Add wget to allow downloading jre
  492. if [ ! -e "wget.exe" ]; then
  493. getFile "http://binary.dmdirc.com/wget.exe" "wget.exe"
  494. fi;
  495. if [ ! -e "wget.exe" ]; then
  496. echo "wget.exe not found, unable to continue."
  497. exit 1;
  498. fi;
  499. FILES="${FILES} wget.exe"
  500. compress $FILES
  501. echo "Creating config.."
  502. echo ";!@Install@!UTF-8!" > 7zip.conf
  503. if [ "${isRelease}" != "" ]; then
  504. echo "Title=\"DMDirc Installation "${isRelease}"\"" >> 7zip.conf
  505. echo "BeginPrompt=\"Do you want to install DMDirc "${isRelease}"?\"" >> 7zip.conf
  506. elif [ "${TAGGED}" != "" ]; then
  507. echo "Title=\"DMDirc Installation "${TAGGED}"\"" >> 7zip.conf
  508. echo "BeginPrompt=\"Do you want to install DMDirc "${TAGGED}"?\"" >> 7zip.conf
  509. else
  510. echo "Title=\"DMDirc Installation\"" >> 7zip.conf
  511. echo "BeginPrompt=\"Do you want to install DMDirc?\"" >> 7zip.conf
  512. fi;
  513. echo "ExecuteFile=\"Setup.exe\"" >> 7zip.conf
  514. echo ";!@InstallEnd@!" >> 7zip.conf
  515. if [ ! -e "7zS.sfx" ]; then
  516. echo "Obtaining sfx stub.."
  517. getFile "http://binary.dmdirc.com/7zS.sfx" "7zS.sfx"
  518. fi
  519. if [ ! -e "7zS.sfx" ]; then
  520. echo "7zS.sfx not found, unable to continue."
  521. exit 1;
  522. fi;
  523. echo "Creating .exe"
  524. cat 7zS.sfx 7zip.conf "${INTNAME}" > "${RUNNAME}"
  525. doRename=0
  526. if [ "${isRelease}" != "" ]; then
  527. doRename=1
  528. elif [ $isSVN -eq 0 -a "${TAGGED}" != "" ]; then
  529. doRename=1
  530. fi;
  531. if [ ${doRename} -eq 1 ]; then
  532. if [ $isSVN -eq 1 ]; then
  533. if [ "${BRANCH}" = "1" ]; then
  534. releaseTag=branch-${isRelease}
  535. else
  536. releaseTag=${isRelease}
  537. fi;
  538. else
  539. if [ "${TAGGED}" = "" ]; then
  540. releaseTag=branch-${isRelease}
  541. else
  542. releaseTag=${TAGGED}
  543. fi;
  544. fi
  545. ORIGNAME="DMDirc-${releaseTag}-Setup${finalTag}.exe"
  546. else
  547. ORIGNAME="${INSTALLNAME}${finalTag}.exe"
  548. fi;
  549. echo "Building launcher";
  550. MD5BIN=`which md5sum`
  551. AWK=`which awk`
  552. MD5SUM=""
  553. if [ "${MD5BIN}" != "" -a "${AWK}" != "" ]; then
  554. MD5SUM=`${MD5BIN} extractor.exe | ${AWK} '{print $1}'`
  555. fi
  556. echo "const" > consts.inc
  557. echo " MD5SUM: String = '${MD5SUM}';" >> consts.inc
  558. # Code to extract and launch resource
  559. echo "ExtractResource('extractor', 'dmdirc_extractor.exe', TempDir);" > ExtractCode.inc
  560. if [ "${MD5SUM}" != "" ]; then
  561. echo "if FindCmdLineSwitch('-nomd5') or FindCmdLineSwitch('nomd5') or checkMD5(TempDir+'dmdirc_extractor.exe') then begin" >> ExtractCode.inc
  562. echo -n " "; # Oh so important for code formatting!
  563. fi;
  564. echo "Launch(TempDir+'dmdirc_extractor.exe');" >> ExtractCode.inc
  565. if [ "${MD5SUM}" != "" ]; then
  566. echo "end" >> ExtractCode.inc
  567. echo "else begin" >> ExtractCode.inc
  568. echo " ErrorMessage := 'This copy of the DMDirc installer appears to be damaged and will now exit';" >> ExtractCode.inc
  569. echo " ErrorMessage := ErrorMessage+#13#10+'You may choose to skip this check and run it anyway by passing the /nomd5 parameter';" >> ExtractCode.inc
  570. echo " ErrorMessage := ErrorMessage+#13#10+'';" >> ExtractCode.inc
  571. echo " ErrorMessage := ErrorMessage+#13#10;" >> ExtractCode.inc
  572. echo " ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';" >> ExtractCode.inc
  573. echo " ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';" >> ExtractCode.inc
  574. echo " " >> ExtractCode.inc
  575. echo " MessageBox(0, PChar(ErrorMessage), 'Sorry, setup is unable to continue', MB_OK + MB_ICONSTOP);" >> ExtractCode.inc
  576. echo "end;" >> ExtractCode.inc
  577. fi
  578. windres -F pe-i386 -i all.rc -o all.res
  579. ${FPC} ${compilerFlags} ${3}Launcher.dpr
  580. if [ $? -ne 0 ]; then
  581. if [ -e "Launcher.exe" ]; then
  582. echo "Unable to compile Launcher.exe, using existing version."
  583. else
  584. echo "Unable to compile Launcher.exe, terminating."
  585. exit 1;
  586. fi
  587. fi
  588. rm -f *.res
  589. rm -f *.rc
  590. rm -f *.inc
  591. rm -f *.ppu
  592. FULLINSTALLER="${PWD}/${INSTALLNAME}${finalTag}.exe"
  593. mv Launcher.exe ${FULLINSTALLER}
  594. if [ "${useUPX}" = "true" ]; then
  595. UPX=`which upx`
  596. if [ "${UPX}" != "" ]; then
  597. if [ "${signEXE}" = "true" ]; then
  598. ${UPX} -4 ${FULLINSTALLER}
  599. else
  600. ${UPX} -9 ${FULLINSTALLER}
  601. fi
  602. fi
  603. fi
  604. echo "Chmodding.."
  605. chmod a+x ${FULLINSTALLER}
  606. if [ "${signEXE}" = "true" ]; then
  607. echo "Signing.."
  608. signexe ${FULLINSTALLER}
  609. else
  610. echo "Not Signing.."
  611. fi;
  612. if [ "" != "${jre}" ]; then
  613. ORIGNAME=`echo ${ORIGNAME} | sed "s/.exe$/.${jrename}.exe/"`
  614. fi;
  615. mv ${FULLINSTALLER} ../output/${ORIGNAME}
  616. # Quick hack to prevent deleting of 2 important files in ${FILES}
  617. mv Setup.exe Setup.exe.tmp
  618. mv Shortcut.exe Shortcut.exe.tmp
  619. rm -f ${DELETEFILES}
  620. rm -f ./7zip.conf
  621. rm -f ./*.o
  622. rm -f ./*.or
  623. rm -f ${RUNNAME}
  624. rm -f ${INTNAME}
  625. rm -f icon.ico
  626. # And un-hack
  627. mv Setup.exe.tmp Setup.exe
  628. mv Shortcut.exe.tmp Shortcut.exe
  629. echo "-----------"
  630. echo "Done."
  631. echo "-----------"
  632. # and Done \o
  633. exit 0;