Install Repo

Embed Size (px)

DESCRIPTION

install

Citation preview

#!/bin/ksh# install-repo.ksh# unpacks and installs Solaris IPS repository# args:# location of zip files# filesystem to set up repotypeset mkiso=falsetypeset imageopt=falsetypeset verify=falsetypeset ignoredeps=""typeset checkmd5=falsetypeset sumcomp=""typeset singlezip=falsetypeset firstpiece="_1of"typeset isziprepo=""typeset solimage=""typeset ckfile=""typeset autoadd="false"typeset CKSUM=/usr/bin/md5sumtypeset OSTOPLEVEL="COPYRIGHT NOTICES"Usage () {cat /dev/null | grep -v _[2-9]of 2> /dev/null)# no zip files in directoryif [ -z "$ziplist" ];thenecho "Cannot locate any initial zip archive segments in \c"echo "$ZIPLOC."echo "Exiting."exit 1fi# search each zip from newest to oldest for a publisher directory# indicating that it contains a repositoryfor zipfile in $ziplist; do# ignore first few files in archive in case there are# readmes, etc.typeset isziprepo=$(unzip -l $zipfile | head -7 | tail -1 | awk '{print $NF}' | grep "^publisher/")if [ -n "$isziprepo" ]; then# found the first (or only) repo archive segmenttypeset zip1=$zipfilebreakfidoneif [ -z "$zip1" ];then# cannot find any zip file containing publisher directoryecho "Cannot locate any initial zip archive segments in \c"echo "$ZIPLOC."echo "Exiting."exit 1fiif [[ "$zip1" != *_1of* ]];then# if repo segment is not labeled "1ofX", then it is a single# segment zip archive filetypeset singlezip=truetypeset -i ZIPCNT=1typeset firstpiece=""fi# set image name based on the "1of" segment# examples:# if segment is V12345-01_1of2.zip, then image is V12345-01# if segment is sol-11_2-repo_1of4.zip, then image is sol-11_2-repotypeset image=$(echo $zip1 | sed "s|.*/\(.*\)${firstpiece}.*\.zip|\1|" | head -1)# base checksum file on image nametypeset ckfile=$ZIPLOC/${image}_md5sums.txt[[ "$image" != *-repo ]] && {# get "Solaris"-format image name to use laterif ! $(ls $ZIPLOC/*-repo_md5sums.txt > /dev/null 2>&1); thenecho "Cannot find md5sums file in $ZIPLOC to \c"echo "retrieve image information. Exiting."exit 1fitypeset solimage=$(ls -t $ZIPLOC/*-repo_md5sums.txt | \head -1 | sed -n "s|.*/\(.*\)_md5sums.txt|\1|p")# link original format names to download namestypeset ckfile=$ZIPLOC/${solimage}_md5sums.txt}else# -i option used to identify image nametypeset imageopt=true# OTN uses hyphen to separate parts, others use underscoreif [ -f $ZIPLOC/${image}.zip ]; thentypeset singlezip=truetypeset -i ZIPCNT=1typeset firstpiece=""elif [ ! -f $ZIPLOC/${image}${firstpiece}* ]; thenecho "Cannot find zip images with $image name. Exiting."exit 1fi# need to determine solaris-style name from md5sum file# search all md5sum files for match to determine file to usesumcomp=$(md5sum $ZIPLOC/${image}${firstpiece}*.zip | awk '{print $1}')for sumfile in $ZIPLOC/*md5sums.txt; doif grep -q $sumcomp $sumfile; then# found ittypeset ckfile=$sumfile# use matching md5sum file to determine# "Solaris"-format namesolimage=$(echo $ckfile | sed -n "s|.*/\(.*\)_md5sums.txt|\1|p")continuefidoneif [ -z "$ckfile" ]; thenecho "No matching checksum file found. Exiting."exit 1fifiif [ -z "$solimage" ]; then# define solimage to be same as image if not already set above# it would not be defined if neither the -i nor -c option is usedtypeset solimage=$image# print out name of Solaris image to avoid confusion[[ $imageopt == false ]] && echo "Using ${image} download."else# print out name of download image to avoid confusion[[ $imageopt == false ]] &&echo "Using ${image} files for ${solimage} download."fitypeset -i zipnum=1typeset rebuild=false# check if repo already exists, give option to abortif [ -d $REPOLOC/publisher/solaris ]; then# if full Solaris repo, then display current version from entire pkgcurrentrepo=$(LC_ALL=C pkg info -g $REPOLOC entire 2>/dev/null | \sed -n "s/.*Branch: //p")if [ -z "$currentrepo" ]; then# give option to proceed if not full Solaris repoecho "$REPOLOC appears to be an existing repository but \c"echo "does not contain"echo "the \"entire\" IPS package. Please check contents of \c"echo "$REPOLOC."elseecho "IPS repository exists at destination $REPOLOC"echo "Current version: $currentrepo"fi# if -y flag was used, then just add to existing repo without promptingif [ "$autoadd" == false ]; thenecho "Do you want to add to this repository? (y/n)[n]: \c"read answercase $answer iny|Y|yes|Yes) ;;*)echo "Please choose a different destination. Exiting."exit 1;;esacelseecho "Adding packages to existing repository."fitypeset rebuild=truetypeset zipreplace="-o" # needed for overwriting current filesfiif [ -z "$ZIPCNT" ]; thentypeset -i ZIPCNT=$(ls $ZIPLOC/${image}_*of*.zip | wc -w | awk '{print $1}')fi# validate zip files# need to compare .zip files with md5 sumsif [ "$checkmd5" == "true" ]; thenif [ ! -f "$ckfile" ]; thenecho "Cannot find checksum file $ckfile. Exiting."exit 1fi# get first zip files, checksum value, if not already definedif [ -z "$sumcomp" ]; thensumcomp=$(md5sum $ZIPLOC/${image}${firstpiece}*.zip | awk '{print $1}')fiecho "\nComparing checksums of downloaded files...\c"if [ "$image" != "$solimage" ]; then# since md5sum file is shipped with "solaris"-style naming,# the file needs to be edited to use actual zip filenamessed "s/$solimage/$image/" $ckfile > /tmp/cksumbase$$elsecp $ckfile /tmp/cksumbase$$fi# generate md5 sum values of downloaded files(cd $ZIPLOC; $CKSUM $image*.zip) > /tmp/cksumdl$$diff /tmp/cksumbase$$ /tmp/cksumdl$$ > /tmp/cksumdiff$$ || {echo "\n< actual"echo "> expected"cat /tmp/cksumdiff$$echo "Checksums do not match. Please confirm that \c"echo "${image} files exist"echo "and should be used, or retry downloading mismatched files."rm -f /tmp/cksum*$$echo "Exiting."exit 1}echo "done. Checksums match.\n"rm -f /tmp/cksum*$$fi# determine number of segments for the image, used to uncompress in a looptypeset -i zipnum=1while [ ! $zipnum -gt $ZIPCNT ]; doif [ "$singlezip" == false ]; thenzipname=${image}_${zipnum}of$ZIPCNT.zipelsezipname=${image}.zipfiif [ ! -f $ZIPLOC/$zipname ]; thenecho "One or more download files are missing."echo "$ZIPLOC contains:"ls -1 $ZIPLOC | egrep "$image.*of.*.zip"echo "Exiting."exit 1fiecho "Uncompressing $zipname...\c"# ignore if files are already in repo. Only report failuresunzip -qd $REPOLOC $zipreplace $ZIPLOC/$zipname || {echo "Unzip of $zipname failed. Use -c option for checksum \c"echo "compare."echo "Script can be re-run after problem has been addressed." echo "If new repo was created, then remove before restarting."echo "Exiting."exit 1}echo "done."# Get next segmentzipnum=zipnum+1doneecho "Repository can be found in $REPOLOC."# if adding to existing repo, rebuild catalog and indexif [ "$rebuild" == "true" ]; thenpkgrepo -s $REPOLOC rebuild || exit 1fiif [ "$verify" == true ]; then# pkgrepo verify is only available on s11.1.7 and abovetypeset currvers=$(pkg list -H entire | awk '{print $2}' | \sed "s/.*-//")majnum=$(echo $currvers | awk -F. '{print $2}')minnum=$(echo $currvers | awk -F. '{print $3}')srunum=$(echo $currvers | awk -F. '{print $4}')bldnum=$(echo $currvers | awk -F. '{print $6}')if [ $majnum -eq 175 -a $minnum -le 1 ]; thenif [ "$majnum.$minnum" == "175.1" -a $srunum -ge 7 ]; then:elseecho "Skipping verify option - not supported on \c"echo "this server."fielse# starting at s12.0 bld 63, verify includes dependency checks# sparse repos will fail unless option is disabledif [ $majnum -ge 12 -a $bldnum -ge 63 ]; thenignoredeps="--disable dependency"fipkgrepo -s $REPOLOC verify $ignoredeps || exit 1fifiif [ "$mkiso" == true ]; thenecho "Building ISO image...\c"VNAME=$(echo $solimage | /usr/gnu/bin/tr 'a-z' 'A-Z' | sed "s/-REPO/_REPO/")cd $REPOLOC# unbundled products may not have top-level copyright filesif $(ls $OSTOPLEVEL > /dev/null 2>&1) ; thentypeset TOPLEVEL=$OSTOPLEVELelsetypeset TOPLEVEL=fi# Use the graft-points option to allow relocation of the repository itself# into a repo subdirectory on the ISO/usr/bin/mkisofs -o $ZIPLOC/$solimage.iso -no-limit-pathtables \-l -allow-leading-dots -A "Oracle Solaris $solimage Release Repository" \-publisher "Copyright 2014 Oracle and/or its affiliates. All rights reserved." \-p [email protected] -R -uid 0 -gid 0 -V ${VNAME} -v -graft-points \repo/publisher=publisher repo/pkg5.repository=pkg5.repository $TOPLEVEL \README-repo-iso.txt > $ZIPLOC/mkiso.log 2>& 1if [ $? -gt 0 ]; thenecho "\nError generating ISO file. Please check \c"echo "$ZIPLOC/mkiso.log for errors."fiecho "done."echo "ISO image can be found at:"echo "$ZIPLOC/${solimage}.iso"echo "Instructions for using the ISO image can be found at:"echo "$REPOLOC/README-repo-iso.txt"fi