Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

pbuilder-dist
Friday, March 7th, 2008 at 6:45:53pm UTC 

  1. !/bin/sh
  2. #
  3. # Copyright (C) Jamin W. Collins <[email protected]>
  4. # Copyright (C) Jordan Mantha <[email protected]>
  5. # Copyright (C) 2007-2008 Siegfried-A. Gevatter <[email protected]>
  6. #
  7. # License: GPLv2 or later
  8. #
  9. # This script is a wrapper to be able to easily use pbuilder for
  10. # different distributions (eg, Gutsy, Hardy, Debian unstable, etc).
  11. #
  12. # You can create symlinks to a pbuilder-dist executable to get different
  13. # configurations. For example, a symlink called pbuilder-hardy will assume
  14. # that the target distribution is always Ubuntu Hardy.
  15.  
  16. ######################################################################
  17.  
  18. # Base directory where pbuilder will put all the files it creates.
  19. # This is overriden by the global variable $PBUILDFOLDER
  20. BASE_DIR="$HOME/pbuilder"
  21.  
  22. # Change this to 0 if you don't want additional components to be used.
  23. # That is, 'universe' and 'multiverse' for Ubuntu chroots and 'contrib'
  24. # and 'non-free' for Debian. (This option can be overwriten at runtime).
  25. EXTRACOMP=1
  26.  
  27. # Change this to 1 if you want the log for the last operation to be saved
  28. # in the base directory by default (it will be named '.lastlog').
  29. SAVELOG=0
  30.  
  31. # Allow this script to use /var/cache/apt/archives/ when possible.
  32. if [ -z $SYSCACHE ]
  33. then
  34.         SYSCACHE=1
  35. fi
  36.  
  37. ######################################################################
  38.  
  39. # Detect system architecture
  40. REALARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
  41.  
  42. # Detect Ubuntu distribution (wheter it is gutsy, hardy, etc.)
  43. SYSDIST=$(lsb_release -cs 2>/dev/null)
  44.  
  45. # Overwrite hardcoded base directory by that one in the global variable
  46. if [ $PBUILDFOLDER ] && [ $PBUILDFOLDER != "" ]
  47. then
  48.         BASE_DIR=$PBUILDFOLDER
  49. fi
  50.  
  51. ######################################################################
  52.  
  53. # Abort if the name of the executable has hypens but it doesn't
  54. # start with "pbuilder-".
  55. if [ -n $(basename $0 | grep '-') ] && [ $(basename $0 | cut -d'-' -f1) != 'pbuilder' ]
  56. then
  57.         echo "Error: " $(basename $0) " is not a valid name for a pbuilder-dist executable."
  58.         exit 1
  59. fi
  60.  
  61. # Detect if the script has it's original name or if a symlink is being used,
  62. # and if it's a symlink extract the information that it contains.
  63. if [ -n $(basename $0 | grep '-') ] && [ `basename $0` != 'pbuilder-dist' ]
  64. then
  65.         ORIGINAL_NAME=0
  66.         DISTRIBUTION=$(basename $0 | cut -d'-' -f2)
  67.         ARCHITECTURE=$(basename $0 | cut -d'-' -f3)
  68. else
  69.         ORIGINAL_NAME=1
  70.         DISTRIBUTION=$1
  71.         shift 1
  72. fi
  73.  
  74. # Check if the choosen architecture is supported on the user's system.
  75. if [ "$1" = 'i386' ]  || [ "$1" = 'amd64' ]
  76. then
  77.         if [ $REALARCH = 'amd64' ]; then
  78.                 ARCHITECTURE=$1
  79.         else
  80.                 echo "Warning: Architecture switching is not supported on your system; ignoring argument '$1'."
  81.         fi
  82.  
  83.         shift 1
  84. fi
  85.  
  86. # If architecture hasn't been set yet, use the system's one.
  87. if [ -z "$ARCHITECTURE" ]
  88. then
  89.         ARCHITECTURE=$REALARCH
  90. fi
  91.  
  92. # Check if there's a component modifier
  93. if [ "$1" = 'mainonly' ]; then
  94.     EXTRACOMP=0
  95.     shift 1
  96. elif [ "$1" = 'allcomp' ]; then
  97.     EXTRACOMP=1
  98.     shift 1
  99. fi
  100.  
  101. # Check if the default logging preferences should be overwriten
  102. if [ "$1" = 'withlog' ]; then
  103.     SAVELOG=1
  104.     shift 1
  105. elif [ "$1" = 'nolog' ]; then
  106.     SAVELOG=0
  107.     shift 1
  108. fi
  109.  
  110. # Check if some proxy should be used.
  111. if [ -n "$http_proxy" ]
  112. then
  113.         PROXY=$http_proxy
  114. fi
  115.  
  116. if [ -z "$PROXY" ] && [ -n "$HTTP_PROXY" ]
  117. then
  118.         PROXY=$HTTP_PROXY
  119. fi
  120.  
  121. ######################################################################
  122.  
  123. usage()
  124. {
  125.         echo "Usage: $0 "$( [ $ORIGINAL_NAME = 0 ] || echo "<distribution> " )$( [ $ARCHITECTURE != "amd64" ] || echo "[i386|amd64] " )"[mainonly|allcomp] [withlog|nolog] <operation>"
  126. }
  127.  
  128. distdata()
  129. {
  130.         # Populate variables with Debian / Ubuntu specific data
  131.         if [ "$1" = "debian" ]
  132.         then
  133.                 # Set Debian specific data
  134.                
  135.                 ISDEBIAN=True
  136.                
  137.                 if [ -z $ARCHIVE ]
  138.                 then
  139.                         ARCHIVE="http://ftp.debian.org"
  140.                 fi
  141.                
  142.                 COMPONENTS="main"$( [ $EXTRACOMP = 0 ] || echo " contrib non-free" )
  143.         else
  144.                 # Set Ubuntu specific data
  145.                
  146.                 ISDEBIAN=False
  147.                
  148.                 if [ -z $ARCHIVE ]
  149.                 then
  150.                         ARCHIVE="http://archive.ubuntu.com/ubuntu"
  151.                 fi
  152.                
  153.                 COMPONENTS="main restricted"$( [ $EXTRACOMP = 0 ] || echo " universe multiverse" )
  154.         fi
  155. }
  156.  
  157. ######################################################################
  158.  
  159. # Check if there is at least one argument remaining.
  160. if [ $# -lt 1 ]
  161. then
  162.         echo "You provided an insufficent number of arguments."
  163.         usage
  164.         exit 1
  165. fi
  166.  
  167. ######################################################################
  168.  
  169. # Check if the distribution exists, and fill the variables that change
  170. # depending on wheter the target distribution is Ubuntu or Debian.
  171. case $DISTRIBUTION in
  172.     dapper|edgy|feisty|gutsy|hardy)
  173.         distdata ubuntu
  174.         ;;
  175.    
  176.     oldstable|sarge|stable|etch|testing|lenny|unstable|sid|experimental)
  177.         distdata debian
  178.         ;;
  179.    
  180.     *)
  181.         if [ ! -d $BASE_DIR/${DISTRIBUTION}-* ]
  182.         then
  183.             echo -n "Warning: Unknown distribution «$DISTRIBUTION». Do you want to continue [y/N]? "
  184.             read continue
  185.            
  186.             if [ "$continue" != 'y' ] && [ "$continue" != 'Y' ]
  187.             then
  188.                 echo "Aborting..."
  189.                 exit 1
  190.             fi
  191.         fi
  192.        
  193.         distdata ubuntu
  194.         ;;
  195. esac
  196.  
  197. # Save the selected operation in a variable.
  198. OPERATION=$1
  199. shift 1
  200.  
  201. # Check if the selected operation is an alias for another one.
  202. case "$OPERATION" in
  203.         upgrade)
  204.                 OPERATION=update
  205.                 ;;
  206. esac
  207.  
  208. # Check if the selected operation is correct, or if it is an alias for
  209. # another one.
  210. case "$OPERATION" in
  211.     create|update|build|clean|login|execute)
  212.         # Allright.
  213.         ;;
  214.    
  215.     upgrade)
  216.         OPERATION=update
  217.         ;;
  218.    
  219.     *)
  220.         if [ ${OPERATION##*.}'dsc' ]
  221.         then
  222.             OPERATION=build
  223.         else
  224.                 echo "Unrecognized argument '$OPERATION'. Please use one of those:"
  225.                 echo "    create"
  226.                 echo "    update"
  227.                 echo "    build"
  228.                 echo "    clean"
  229.                 echo "    login"
  230.                 echo "    execute"
  231.                 exit 1
  232.         fi
  233.         ;;
  234. esac
  235.  
  236. # Determine the base name for the chroot tarball and the folder where the
  237. # resulting files will be stored.
  238. FOLDERBASE="${DISTRIBUTION}-$ARCHITECTURE"
  239.  
  240. # Create the folder where the resulting files will be placed (if the
  241. # option is build), if it doesn't exist yet.
  242. if [ ! -d $BASE_DIR/${FOLDERBASE}_result ]
  243. then
  244.     mkdir -p $BASE_DIR/${FOLDERBASE}_result
  245. fi
  246.  
  247. # Determine wheter system cache should be used or not.
  248. if [ $SYSCACHE = 1 ] && [ "$SYSDIST" = "$DISTRIBUTION" ] && [ "$REALARCH" = "$ARCHITECTURE"]
  249. then
  250.                 DEBCACHE='/var/cache/apt/archives/'
  251. fi
  252.  
  253. # If it's an Ubuntu system, create an editable configuration file,
  254. # and if it's a stable release add the -security and -updates repositories.
  255. if [ $ISDEBIAN = "False" ]
  256. then
  257.         if [ ! -d $BASE_DIR/etc/$DISTRIBUTION/apt.conf/ ]
  258.         then
  259.                 mkdir -p $BASE_DIR/etc/$DISTRIBUTION/apt.conf
  260.         fi
  261.         if [ ! -e $BASE_DIR/etc/$DISTRIBUTION/apt.conf/sources.list ]
  262.         then
  263.                 echo "deb $ARCHIVE $DISTRIBUTION $COMPONENTS" > $BASE_DIR/etc/$DISTRIBUTION/apt.conf/sources.list
  264.                 case $DISTRIBUTION in
  265.                         dapper|edgy|feisty|gutsy )
  266.                                 cat >>  $BASE_DIR/etc/$DISTRIBUTION/apt.conf/sources.list <<EOF
  267. deb $ARCHIVE $DISTRIBUTION-security $COMPONENTS
  268. deb $ARCHIVE $DISTRIBUTION-updates $COMPONENTS
  269. EOF
  270.                                 ;;
  271.                         * )
  272.                                 ;;
  273.                 esac
  274.         fi
  275. fi
  276.  
  277. #if [ -z "$PBUILDAUTH" ]
  278. #then
  279. #       if [ -n "$DESKTOP_SESSION"  ]
  280. #       then
  281. #              case $DESKTOP_SESSION in
  282. #                     gnome )
  283. #                            SUDOREPLACE="gksudo -D \"Pbuilder\""
  284. #                            ;;
  285. #                     kde|kde4 )
  286. #                            SUDOREPLACE="kdesudo -d --comment \"Pbuilder\""
  287. #                            ;;
  288. #                     * )
  289. #                            SUDOREPLACE="sudo"
  290. #                            ;;
  291. #              esac
  292. #       else
  293. #              SUDOREPLACE=sudo
  294. #       fi
  295. #else
  296. #       SUDOREPLACE=$PBUILDAUTH
  297. #fi
  298.  
  299. sudo pbuilder $OPERATION \
  300. --basetgz "$BASE_DIR/${FOLDERBASE}-base.tgz" \
  301. --distribution "$DISTRIBUTION" \
  302. --debootstrapopts --arch \
  303. --debootstrapopts "$ARCHITECTURE" \
  304. $( [ "$SAVELOG" = 0 ] || echo "--logfile ${BASE_DIR}/.lastlog" ) \
  305. $( [ -z "$PROXY" ] || echo "--http-proxy ${PROXY}" ) \
  306. $( [ -z "$DEBCACHE" ] || echo "--aptcache ${DEBCACHE}" ) \
  307. --buildresult "${BASE_DIR}/${FOLDERBASE}_result" \
  308. --mirror "${ARCHIVE}" \
  309. $( [ $ISDEBIAN != "False" ] || echo "--aptconfdir \"${BASE_DIR}/etc/${DISTRIBUTION}/apt.conf/\"" ) \

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right