Guest User

Untitled

a guest
Jun 15th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###################################################################################
  4. # UCK - Ubuntu Customization Kit #
  5. # Copyright (C) 2006-2010 UCK Team #
  6. # #
  7. # UCK is free software: you can redistribute it and/or modify #
  8. # it under the terms of the GNU General Public License as published by #
  9. # the Free Software Foundation, either version 3 of the License, or #
  10. # (at your option) any later version. #
  11. # #
  12. # UCK is distributed in the hope that it will be useful, #
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  15. # GNU General Public License for more details. #
  16. # #
  17. # You should have received a copy of the GNU General Public License #
  18. # along with UCK. If not, see <http://www.gnu.org/licenses/>. #
  19. ###################################################################################
  20.  
  21. function failure()
  22. {
  23. echo "$@"
  24. exit 1
  25. }
  26.  
  27. function failure_user()
  28. {
  29. failure "Script was cancelled by the user"
  30. }
  31.  
  32. function gui_failure()
  33. {
  34. dialog_msgbox "Error" "$@"
  35. failure "$@"
  36. }
  37.  
  38. ############################
  39. # parsing input parameters #
  40. ############################
  41. USE_MOUNT=
  42. WAIT_BEFORE_EXIT=0
  43. SAVED_ARGS="$@"
  44. while [ -n "$1" ]; do
  45. case "$1" in
  46. --wait-before-exit)
  47. WAIT_BEFORE_EXIT=1;;
  48. -m|--mount)
  49. USE_MOUNT=-m;;
  50. -*) echo "Unexpected argument: $1" >&2
  51. echo "Usage: $0 [--wait-before-exit] [-m] [remaster_home]" >&2
  52. exit 1;;
  53. *) break;;
  54. esac
  55. shift
  56. done
  57.  
  58. REMASTER_HOME=${1:-~/tmp}
  59. LIVECD_ISO_LOCATION=$REMASTER_HOME/remaster-new-files/livecd.iso
  60.  
  61.  
  62. if [ -e libraries/gui.sh ]; then
  63. SCRIPTS_DIR=`dirname "$0"`
  64. LIBRARIES_DIR=$SCRIPTS_DIR/libraries
  65. else
  66. SCRIPTS_DIR=/usr/bin
  67. LIBRARIES_DIR=/usr/lib/uck/
  68. fi
  69.  
  70. ############
  71. # MESSAGES #
  72. ############
  73.  
  74. if [ -e VERSION ]; then
  75. VERSION=`cat VERSION`
  76. else
  77. VERSION=`cat /usr/lib/uck/VERSION`
  78. fi
  79.  
  80. rel="`lsb_release -is` `lsb_release -rs`"
  81. kernel=`uname -rm`
  82.  
  83. WELCOME_TEXT=`cat <<EOF
  84. Welcome to Ubuntu Customization Kit $VERSION!
  85. (Running on $rel, $kernel)
  86.  
  87. This tool lets you create Ubuntu live CDs in your language,
  88. with all the necessary language packs preinstalled.
  89. It also changes the boot screen to appear in your chosen language.
  90.  
  91. Requirements:
  92. 1. about 5 GB of free disk space in $HOME/tmp
  93. (on local machine and mounted with "dev,suid,exec" options)
  94. 2. Internet access
  95.  
  96. Homepage: http://uck.sourceforge.net
  97. Authors: http://uck.sourceforge.net/team
  98. License: GPL v3
  99. EOF
  100. `
  101.  
  102. RUN_CUSTOMIZATIONS_TEXT=`cat <<EOF
  103. You will be provided with menu to choose from customization actions when build reaches proper place.
  104.  
  105. This menu app will be run your Xserver, but with the title "UCK customization menu".
  106. It will appear when unpacking CD and installing predefined packages is done, so it might take a long time.
  107. All operations you do there will affect only customized CD.
  108. You can:
  109. - Run package manager to add or remove software or repositories (see Note 2 for information about upgrading kernel packages).
  110. - Run console app for manual customizations in shell.
  111. - Run predefined customization actions.
  112.  
  113. When you finish customization, quit the application and building process will proceed.
  114.  
  115. Note 1: package application will be run after language packs are installed according to previous selections, so you do not have to do this again.
  116.  
  117. Note 2: upgrading kernel package updates kernel used to run live CD (latest one available will be used). You can remove earlier version using package application, just like any other package.
  118.  
  119. Note 3: sources.list changes are not propagated to installed system.
  120.  
  121. Note 4: Simple upgrading system increases CD size, as some other updates might increase size.
  122. You will probably have to remove something from image to make it fit on CD.
  123. EOF
  124. `
  125.  
  126. PRE_START_TEXT=`cat <<EOF
  127. All the necessary information has been gathered.
  128. Building will now start.
  129.  
  130. Note: You will have to provide your password on the command-line
  131.  
  132. Your live CD will be created as:
  133.  
  134. $LIVECD_ISO_LOCATION
  135.  
  136. Please fasten your seatbelts and enjoy the ride!
  137. EOF
  138. `
  139.  
  140. BUILD_SUCCESS_TEXT=`cat <<EOF
  141. Building was successful!
  142.  
  143. You can find your live CD in:
  144.  
  145. $LIVECD_ISO_LOCATION
  146.  
  147. If you have installed the \"qemu\" package, you can test the image by doing:
  148.  
  149. qemu -cdrom $LIVECD_ISO_LOCATION -boot d -m 256
  150. EOF
  151. `
  152.  
  153. BUILD_FAILURE_TEXT=`cat <<EOF
  154. Building failed.
  155.  
  156. Please look at $REMASTER_HOME/build.log to see what went wrong.
  157.  
  158. If you cannot find the problem, please send a support request at:
  159.  
  160. https://launchpad.net/products/uck/+addticket
  161. EOF
  162. `
  163.  
  164. #########################
  165. # EXECUTION STARTS HERE #
  166. #########################
  167.  
  168. . $LIBRARIES_DIR/gui.sh
  169.  
  170. if [ `id -un` = "root" ] ; then
  171. gui_failure "UCK GUI should not be run as root, please run again as a normal user. You will be asked for your password when administrator privileges are required."
  172. fi
  173.  
  174. dialog_msgbox "Welcome" "$WELCOME_TEXT"
  175.  
  176. AVAILABLE_LANGUAGE_PACKS=`apt-cache pkgnames language-support | egrep '^language-support-.{2,7}$' | cut -b 18- | sort`
  177. if [ "$AVAILABLE_LANGUAGE_PACKS" == "" ]; then
  178. AVAILABLE_LANGUAGE_PACKS=`apt-cache pkgnames language-pack | egrep '^language-pack-.{2,7}$' | grep -v base | grep -v gnome | grep -v kde | cut -b 15- | sort`
  179. fi
  180.  
  181. CD_LANGS=`dialog_multi_choice $'Please choose language packs to install\n(you can choose more than one)' $AVAILABLE_LANGUAGE_PACKS`
  182. RESULT=$?
  183.  
  184. if [ $RESULT -ne 0 ] ; then
  185. failure_user
  186. fi
  187.  
  188. LANGLIST_FILE="$LIBRARIES_DIR/langlist"
  189. AVAILABLE_BOOT_LANGS=$(cat $LANGLIST_FILE)
  190. BOOT_CD_LANGS=`dialog_multi_choice $'Please choose which languages will be available at boot of live CD\n(some might not be supported by the specific Ubuntu release you\'re customizing)' $AVAILABLE_BOOT_LANGS`
  191. RESULT=$?
  192.  
  193. if [ $RESULT -ne 0 ] ; then
  194. failure_user
  195. fi
  196.  
  197. if [ "$BOOT_CD_LANGS" == "" ]; then
  198. BOOT_CD_LANGS=$AVAILABLE_BOOT_LANGS
  199. fi
  200.  
  201. while true; do
  202. BOOT_CD_LANG=`dialog_menu $'Please choose which language will be selected by default at boot of live CD' $BOOT_CD_LANGS`
  203. RESULT=$?
  204.  
  205. if [ $RESULT -ne 0 ] ; then
  206. failure_user
  207. fi
  208.  
  209. if [ "$BOOT_CD_LANG" != "" ]; then
  210. break
  211. fi
  212. done
  213.  
  214. if [ -z "$CD_LANGS" ] ; then
  215. DESKTOP_TYPES=""
  216. else
  217. DESKTOP_TYPES=`dialog_multi_choice $'Please choose desktop environments which will be present on customized CD\n(you can choose more than one)' unity gnome kde others`
  218. if [ "$DESKTOP_TYPES" = "unity" ]; then
  219. DESKTOP_TYPES="gnome"
  220. fi
  221. if [ "$DESKTOP_TYPES" = "others" ]; then
  222. DESKTOP_TYPES=""
  223. fi
  224. fi
  225.  
  226. RESULT=$?
  227. if [ $RESULT -ne 0 ] ; then
  228. failure_user
  229. fi
  230.  
  231. while true; do
  232. ISO_IMAGE=`dialog_choose_file "Please choose an ISO image to be used as the basis for your live CD."`
  233.  
  234. if [ -z "$ISO_IMAGE" ] ; then
  235. failure_user
  236. fi
  237.  
  238. if [ ! -r "$ISO_IMAGE" ] ; then
  239. dialog_msgbox "Non-existent file" "File $ISO_IMAGE does not exist"
  240. continue
  241. fi
  242.  
  243. if [ ! -r "$ISO_IMAGE" ] ; then
  244. dialog_msgbox "Unreadable file" "File $ISO_IMAGE cannot be read, do you have permissions for this file?"
  245. continue
  246. fi
  247.  
  248. if [ "`isoinfo -p -i \"$ISO_IMAGE\" | grep -i CASPER | wc -l`" = "0" ] ; then
  249. dialog_msgbox "Not an Ubuntu Desktop ISO image" "File $ISO_IMAGE is not an Ubuntu Desktop Edition ISO image, alternate CDs can be remastered using backend scripts."
  250. continue
  251. fi
  252. break
  253. done
  254.  
  255. while true; do
  256. ISO_DESCRIPTION=`dialog_line_input "Please enter the name for your CD (you can leave it blank, 32 chars max)" "Customized Ubuntu live CD" `
  257. RESULT=$?
  258.  
  259. if [ $RESULT -ne 0 ] ; then
  260. failure_user
  261. fi
  262.  
  263. DESCRIPTION_LEN=`echo "$ISO_DESCRIPTION" | wc -c`
  264.  
  265. if [ "$DESCRIPTION_LEN" -gt 32 ]; then
  266. dialog_msgbox "ISO description too long" "The description must not be longer than 32 characters (yours is $DESCRIPTION_LEN characters)"
  267. continue
  268. fi
  269. break
  270. done
  271.  
  272. RUN_MANUAL_CUSTOMIZATIONS=`dialog_menu "Do you want to customize the CD manually during building (using package utilities, console, etc.)?" yes no`
  273. if [ $? -ne 0 ] ; then
  274. failure_user
  275. fi
  276.  
  277. REMOVE_WIN32_FILES=`dialog_menu $'Do you want to delete all windows-related files from the CD?\nThese are files that will appear when you use the CD under Windows (wubi, autorun.inf, etc.)' yes no`
  278. if [ $? -ne 0 ] ; then
  279. failure_user
  280. fi
  281.  
  282. HYBRID=`dialog_menu $'Do you want to generate a hybrid image(ISO/USB)' yes no`
  283. if [ $? -ne 0 ] ; then
  284. failure_user
  285. fi
  286.  
  287. dialog_msgbox "Ready to build" "$PRE_START_TEXT"
  288.  
  289. echo "Preparing build environment..."
  290. if [ ! -e "$REMASTER_HOME" ]; then
  291. mkdir "$REMASTER_HOME" || gui_failure "Unable to create $REMASTER_HOME directory"
  292. fi
  293. BUILD_DIR=$REMASTER_HOME/customization-scripts
  294. rm -rf "$BUILD_DIR" || gui_failure "Unable to remove previous build directory ($BUILD_DIR)"
  295. mkdir $BUILD_DIR || gui_failure "Unable to create $BUILD_DIR directory"
  296.  
  297. cp -a "$LIBRARIES_DIR"/customization-profiles/localized_cd/* "$BUILD_DIR"/
  298. cp -a "$LIBRARIES_DIR"/gui.sh "$BUILD_DIR"/
  299.  
  300. echo "$CD_LANGS" >"$BUILD_DIR"/language_packs
  301. echo "$BOOT_CD_LANGS" >"$BUILD_DIR"/livecd_locales
  302. echo "$BOOT_CD_LANG" >"$BUILD_DIR"/livecd_locale
  303. echo "$DESKTOP_TYPES" >"$BUILD_DIR"/desktop_types
  304. echo "$ISO_DESCRIPTION" >"$BUILD_DIR"/iso_description
  305. echo "$RUN_MANUAL_CUSTOMIZATIONS" >"$BUILD_DIR"/run_manual_customizations
  306. echo "$REMOVE_WIN32_FILES" >"$BUILD_DIR"/remove_win32_files
  307. echo "$HYBRID" >"$BUILD_DIR"/hybrid
  308. echo "yes" >"$BUILD_DIR"/clean_desktop_manifest
  309.  
  310. # Pass proxy variables around sudo to chroot environment
  311. >"$BUILD_DIR"/environment
  312. for var in `env | grep -i _proxy`
  313. do
  314. name=`echo "$var" | sed 's/=.*//'`
  315. value=`echo "$var" | sed 's/[^=]*=//'`
  316. echo "export $name=\"$value\"" >>"$BUILD_DIR"/environment
  317. done
  318.  
  319. if [ "$RUN_MANUAL_CUSTOMIZATIONS" = "yes" ] ; then
  320. echo "Creating X authentication cookie..."
  321. xauth extract - $DISPLAY > "$BUILD_DIR"/Xcookie || failure "Cannot create Xauthentication cookie in $BUILD_DIR/Xcookie, error=$?"
  322. fi
  323.  
  324. echo "Running build process..."
  325. (
  326. echo "Build ($0 $SAVED_ARGS) started at `date +'%Y-%m-%d %H:%M:%S'`"
  327. export UCK_USERNAME="$USER"
  328. sudo bash "$SCRIPTS_DIR"/uck-remaster $USE_MOUNT "$ISO_IMAGE" "$BUILD_DIR" "$REMASTER_HOME"
  329. RESULT=$?
  330.  
  331. if [ $RESULT -ne 0 ]; then
  332. dialog_msgbox "Build failure" "$BUILD_FAILURE_TEXT"
  333. else
  334. dialog_msgbox "Build success" "$BUILD_SUCCESS_TEXT"
  335.  
  336. MAX_CD_700MB_SIZE=737280000 #From http://en.wikipedia.org/wiki/CD-ROM
  337.  
  338. ISO_SIZE=`stat --format='%s' "$LIVECD_ISO_LOCATION"`
  339.  
  340. if [ $ISO_SIZE -ge $MAX_CD_700MB_SIZE ] ; then
  341. dialog_msgbox "ISO too big" "Warning: ISO image might be too big to fit on 700MB CD-ROM"
  342. fi
  343. fi
  344. echo "Build ended at `date +'%Y-%m-%d %H:%M:%S'`"
  345. ) 2>&1 | tee -a $REMASTER_HOME/build.log
  346.  
  347. if [ $WAIT_BEFORE_EXIT = 1 ] ; then
  348. echo -n "Press ENTER to close the terminal"
  349. read FAKE_EXIT_CHECK
  350. fi
Advertisement
Add Comment
Please, Sign In to add comment