Home | History | Annotate | Download | only in repo.clone.JeOS
      1 #!/bin/bash
      2 # We will tail outputs to file, so we need get correctly errors from pipe
      3 
      4 set -o pipefail
      5 
      6 #
      7 # CDDL HEADER START
      8 #
      9 # The contents of this file are subject to the terms of the
     10 # Common Development and Distribution License (the "License").
     11 # You may not use this file except in compliance with the License.
     12 #
     13 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     14 # or http://www.opensolaris.org/os/licensing.
     15 # See the License for the specific language governing permissions
     16 # and limitations under the License.
     17 #
     18 # When distributing Covered Code, include this CDDL HEADER in each
     19 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     20 # If applicable, add the following below this CDDL HEADER, with the
     21 # fields enclosed by brackets "[]" replaced with your own identifying
     22 # information: Portions Copyright [yyyy] [name of copyright owner]
     23 #
     24 # CDDL HEADER END
     25 #
     26 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     27 # Use is subject to license terms.
     28 
     29 
     30 # This 'sample script' is part of OpenSolaris 200906 JeOS Project
     31 # Using fully local (local disk, Localhost net) based repository
     32 #  we can significantly reduce time of repetable DC,AI instalations 
     33 #  in situations when we know definitive list of installed packages 
     34 # and need just small subset of packages siutable for archiving
     35 
     36 AUTHORITY=http://pkg.opensolaris.org:80/release
     37 SITE=http://localhost:10001/
     38 TARGET=/localrepos/ips/self
     39 
     40 # This is how I start the ips repository daemon before creating a 
     41 # selected allready installed packages FMRIs IPS mirror FREEZE.
     42 #
     43 # Dependencies are handled during frist installation time.
     44 # 
     45 # There in no udate functionality, you need to run it on empty
     46 # storage to get fresh packages, but adding new package is ok
     47 #
     48 # Ideally create a separe zpool for repo , so we can attach it
     49 # to multiple VM instances, plus ZFS is fully ARCH independent.
     50 #
     51 # 1. Create a dedicated zfs based system on 1 GB disk
     52 #
     53 # /opt/install-test/bin/test_td -d all
     54 # Disk discovery
     55 # Total number of disks: 1
     56 # ---------------------------------
     57 # num |    name|  ctype|size [MB]|
     58 # ---------------------------------
     59 #  1 |* c3t0d0|   scsi|     1024|
     60 # ---------------------------------    
     61 #  
     62 # zpool create localrepos c3t2d0
     63 # zfs create localrepos/ips
     64 # zfs set atime=off localrepos/ips
     65 # zfs create localrepos/ips/self
     66 # zfs set atime=off localrepos/ips/self
     67 #
     68 # Checking out Blogbench with ZFS - atime matters
     69 # http://www.williamhathaway.com/wordpress/2009/04/04/checking-out-blogbench-with-zfs-atime-matters/ 
     70 #
     71 # For JeOS and its Sample cutomizations 1GB zpool is realy enought 
     72 #
     73 # 2. Get repo clone from pre-prepared list of allready installed packages
     74 #
     75 # 6356 PKGsend mut allow to specify FMRI (timestamp) so we can clone package
     76 # http://defect.opensolaris.org/bz/show_bug.cgi?id=6356
     77 # 
     78 # For now in OpenSolaris 200906 this is not fixed, fix is in later release, 
     79 # so I use a dirty manifest renaming after PKGsend/PKGrec per packaegs clone 
     80 #
     81 # rm -f /tmp/repo-self-get.log
     82 # repo-self-get.sh ./OSOL0906-JeOS-pkgsfmris.i386.lst ./OSOL0906-JeOS-pkgsfmris.sparc.lst \ 
     83 #            2>&1 | tee /tmp/repo-self-get.log
     84 #
     85 # Note: This script will mirror both architectures, so if we want to get full mirror list   
     86 # you can combine both architetures in one list ("uniq -c" is allready runing inside script)
     87 
     88 TEMPDIR=`mktemp -d`
     89 
     90 if [ ! -d $1 ]; then 
     91     echo "Passed file with pkg list of full FMRIs" $1 $2
     92     cat $1 $2 | grep -v "^#" |sed s%\pkg:/%%|sort -u >$TEMPDIR/packages.lst
     93 else
     94     echo "Geting installed package list from local pkg database ..."
     95     pkg list -v | awk '{print $1}'|sed s%\pkg:/%%|sort -u  >$TEMPDIR/packages.lst
     96 fi    
     97 
     98 cd $TEMPDIR
     99 
    100 # Start IPS repository so we can receive packages
    101 
    102 echo n | format >/dev/null 2>&1
    103 sleep 1
    104 zpool import -f localrepos >/dev/null 2>&1
    105 zpool list localrepos
    106 sleep 3
    107 # Critical Check Point
    108 if [ -d ${TARGET} ] ; then
    109   screen -L -d -m /usr/lib/pkg.depotd -d ${TARGET} -p 10001
    110 else
    111  echo "Can't find IPS repository FREEZE location at /localrepos/ips/self/... "
    112  echo 1
    113 fi
    114 	  
    115 # Clone each package with PKGrec/PKGsend
    116 
    117 for i in $(cat $TEMPDIR/packages.lst)
    118 do
    119     pkgname=$(echo $i | cut -f 1 -d '@')
    120     pkgnameescaped=$(echo $i | cut -f 1 -d '@'| sed s/\\//%2F/g)
    121     echo "Clonning $i as $pkgname"
    122     pkgrecv -s http://pkg.opensolaris.org/release/ "$i" || true
    123 
    124 # Add code here, to detect, if we need to rename manifests later
    125 # Or by IPS version, or be depetcting then eval will send new timestamp ?
    126     eval $(pkgsend -s $SITE open "$i")
    127     pkgsend -s $SITE include -d $pkgnameescaped "$pkgnameescaped/manifest"
    128     pkgsend -s $SITE close
    129     rm -rf $pkgnameescaped/
    130 done
    131 
    132 # Force to re-index eact time, this is protecting from PKG versions 
    133 # changes after we create a REPO FREEZE, I have this issues allready
    134 
    135 pkill -x -f "screen -L -d -m /usr/lib/pkg.depotd -d $TARGET -p 10001"
    136 
    137 DIRS="index catalog trans updatelog"
    138 for onedir in $DIRS 
    139   do [ -d $TARGET/$onedir ] && rm -rf $TARGET/$onedir
    140 done
    141 
    142 FILES="search.dir search.pag"
    143 for onefile in $FILES
    144   do [ -f $TARGET/$onefile ] && rm -f $TARGET/$onefile
    145  done
    146 
    147 # This is dirty manifest renaming code, assuming then there is only one package, 
    148 # this mean then was script was run only once and there is no any "duplicates"
    149 
    150 for i in $(cat $TEMPDIR/packages.lst)
    151 do
    152  reponame=$(echo $i | cut -f 1 -d '@' | sed s/\\//%2F/g)
    153  repomanifest=$(echo $i | cut -f 2 -d '@'| sed s/,/%2C/|sed s/:/%3A/)
    154  echo "Fixing $reponame/$repomanifest"
    155  `mv -f -T $TARGET/pkg/$reponame/*Z $TARGET/pkg/$reponame/$repomanifest`
    156 done
    157 
    158 exit 0
    159