Sunday, February 7, 2010

[Level 3] Setting Local Repository.

Days ago, I am the speaker of Sun campus seminar, 
my subject of the session is the OpenSolaris new feature.
Because I have to demo how to install package by package manager,
and I'm afraid that the school cannot provide my laptop to surve the net.
I decided to setup the local repository on my laptop.

The following script is the local repository setup script,
please refer to it.

regards,

Stanley Huang

#!/usr/bin/bash
clear
set -f ## noglob

fRepoISO=/Karajon/ISOs/osol-repo-0906-full.iso
dMP=/mnt/repo && pfexec mkdir -p $dMP
fsRepo=rpool/repo && pfexec zfs create -o compression=on $fsRepo 2>/dev/null
dRepo=`zfs get -H mountpoint $fsRepo | awk '{print($3)}'`
sHost=192.168.1.100
sHostname=stanley-nb
nPort=81
sIF=yge0:1
fBackupPublisher=/PkgPublisher.bak

cat <
Repository Full ISO Image    : $fRepoISO
Iso Image Mount Point        : $dMP
Repository ZFS File System   : $fsRepo
Repository ZFS Directory     : $dRepo
Repository Host              : $sHost
Repository Hostname          : $sHostname
Repository Server Port       : $nPort
Repository Binding Interface : $sIF
Backup Publisher File        : $fBackupPublisher
EOF

read -p "Are all setting correct (yes/NO)? " yN
[ "$yN" != "yes" ] && [ "$yN" != "YES" ] && exit 0

addHosts() {
  grep "^$sHost[     ]" /etc/hosts | grep $sHostname >/dev/null || echo "$sHost    $sHostname" >> /etc/hosts
}

rsyncRepo() {
  pfexec mount -F hsfs `pfexec lofiadm -a $fRepoISO` $dMP
  pfexec rsync -aP $dMP $dRepo
}

setPkgServerProp() {
  pfexec svccfg -s application/pkg/server setprop pkg/inst_root=$dRepo/repo
  pfexec svccfg -s application/pkg/server setprop pkg/readonly=true
  pfexec svccfg -s application/pkg/server setprop pkg/port=$nPort
}

modifyPkgServerCfg() {
  pfexec perl -pi -e "s|^origins.*|origins = http://$sHost:$nPort|" $dRepo/repo/cfg_cache
}

bindingIF() {
  ifconfig $sIF plumb set $sHost up
}

randrServer() {
  pfexec svcadm refresh application/pkg/server
  pfexec svcadm restart application/pkg/server
}

backupPublisher() {
  if [ -f /$fBackupPublisher ]
  then
    read -p "Backup file exists($fBackupPublisher), Do you want to overwrite it (Y/n)?" Yn
    if [ "$Yn" == "N" ] || [ "$Yn" == "n" ]
    then
      exit
    fi
  fi
  pfexec pkg publisher > /$fBackupPublisher
}

modifyPublisherName() {
  pfexec pkg set-publisher -O http://$sHost:$nPort opensolaris.org
}

showPkgCmds() {
  cat <
To change repository, please use following commands:
# pfexec pkg set-publisher -m http://$sHost:$nPort local-repository
# pkg publisher
# pfexec pkg set-publisher -M http://$sHost:$nPort local-repository
# pfexec pkg set-publisher -O http://$sHost:$nPort local-repository
EOF
}

############################################# main

addHosts
#rsyncRepo
setPkgServerProp
modifyPkgServerCfg
bindingIF
randrServer
backupPublisher
modifyPublisherName
showPkgCmds




Wish this helps.

regards,
Stanley Huang