いろいろいじってこうなった。まだテストしてないから。使用禁止。試用は可。
#!/bin/sh # updateclam.sh -- script for updateing ClamAV for ClamXav # require: Developer Tools # : System been already installed gmp (GNU MP Library) # : on Network # optional: support auto FleshClamDaemon stop/start # Limitation: Dose not support first install of ClamAV #* History # Original Version of this script is downloadables in # http://www.macosxhints.com/article.php?story=20060409060940665&query=clam # version 2006:09:05 # support yuji-okamura/official filerule (permission group and owner set) # version 2006:05:10 # backup directory support for previous freshclam.conf # switching FreshClamDaemon stop/start in before/end updating; # FreshClamDaemon : author yuji_okamura #http://homepage.mac.com/yuji_okamura/iblog/DotMac/Tips/C1181169702/E20060502200534/index.html # version 2006:05:08 # changing VARIABLE url's value ; download site to jaist Japan mirror # adding sudo command in front of chmod,chgrp,chown # version 2006:07:02 # 1st tested ! and modify messages #* Variable #** clambkdir is a backup dir which store README and previous freshclam.conf clambkdir="/usr/local/clambk" #/var/log/freshclamconf, oldfreshclamconf="${clambkdir}/freshclam.bk" # fixed backup #oldfreshclamconf=${clambkdir}/freshclam.conf`date "+%Y%m%d"` # saving when every update #** filerule: mode owner group rule filerule="yuji-okamura" # support FreshClamDaemon #filerule="official" # don't support FreshClam daemon #**mirrorurl is URL of mirror site for downloading clamav #mirrirurl="http://superb-east.dl.sourceforge.net/sourceforge/clamav/clamav-" mirrorurl="http://jaist.dl.sourceforge.net/sourceforge/clamav/clamav-" #Jaist in JPN mirror #clamXavdir is the dir being installed clamav :don't change !/usr/local/clamXav clamXavdir="/usr/local/clamXav" #fixed etcdir="${clamXavdir}/etc" #fixed bindir="${clamXavdir}/bin" #fixed clamavdir="${clamXavdir}/share/clamav" #fixed newfreshclamconf="${etcdir}/freshclam.conf" #fixed orgfreshclamconf="${etcdir}/freshclam.conf.org" #fixed binfreshclam="${bindir}/freshclam" #fixed freshclamlog="${clamavdir}/freshclam.log" #fixed #** StartupItems is the dir for StartupItems has been FleshClamDaemon StartupItems="/Library/StartupItems" #fixed (Default for FleshClamDaemon) #StartupItems="/System/Library/StartupItems" #fixed (SystemDaemon) FleshClamDaemon="${StartupItems}/FleshClamDaemon/FleshClamDaemon" #fixed (Binary) #* CODE #** Pre clamav updating if [ ! -d "$clamXavdir" ]; then printf "WARNING: Not exist $clamXavdir dir \n" printf "This script is not be tested such first install" printf "Stop" exit 0 fi if [ ! -d "$clambkdir" ]; then mkdir -p "$clambkdir" fi if [ ! -f "$oldfreshclamconf" ]; then sudo cp -r "$newfreshclamconf" "$oldfreshclamconf" fi if [ "$filerule" = "yuji-okamura" ] ; then if [ -f "$FreshClamDaemon" ]; then printf "Stopping FreshClamDaemon \n" sudo "$FreshClamDaemon" stop printf "\n OK \n" else printf "No FreshClamDaemon \n \n OK \n " fi fi #** updating clamav #*** to get number of latest version,downloadng a file in the default location latest=`curl -O "http://www.clamav.net/stable.php#pagestart" \ ; grep "released (" stable.php* | awk '{print $2}' | head -1` #*** downloading latest tar gz package of clamav and melt-compile-make it curl -O ${mirrorurl}${latest}.tar.gz && \ printf "The latest version of clamav %s has been downloaded!\n" $latest && \ tar zxvf clamav-$latest.tar.gz && \ cd clamav-$latest ./configure --prefix="$clamXavdir" && make && \ printf "\n \n Input Passord to make install clamAV \n \n " && \ sudo make install && \ printf "\n \n changing file ownership...mode...group...\n" if [ "$filerule" = "yuji-okamura" ] ; then printf "by yuji-okamuras rule\n" sudo chown -R root:admin "$etcdir" sudo chmod 0775 "$etcdir" sudo chmod 0664 "${etcdir}"/* sudo chown -R root:admin "$bindir" sudo chmod 0755 "$bindir" sudo chmod 0755 "${bindir}"/* sudo chown -R clamav:clamav "$clamavdir" sudo chmod 0755 "$clamavdir" sudo chmod 0644 "${clamavdir}"/* else printf "by official rule\n" sudo chown -R root:admin "$etc" sudo chmod 0775 "$etcdir" sudo chmod 0664 "${etcdir}"/* sudo chown -R root:admin "$bindir" sudo chmod 0755 "$bindir" sudo chmod 0755 "${bindir}"/* sudo chown clamav "$binfeshclam" sudo chmod u+s "$binfeshclam" sudo chown -R clamav:clamav "$clamavdir" sudo chmod 0755 "$clamavdir" sudo chmod 0644 "${clamavdir}"/* sudo touch "$clamavlog" sudo chmod a+wr "$clamavlog" fi #** return saved files if [ -d "${clambkdir}" ]; then if [ -f "$newfreshclamconf" ]; then sudo cp -r "$newfreshclamconf" "$orgfreshclamconf" else printf "\n\n WARNING: No new original $newfreshclamconf\n " printf "\n\n WARNING: Install uncorrectly ? \n " fi if [ -f "$oldfreshclamconf" ]; then printf "USE saved freshclam.conf\n " sudo cp -r "$oldfreshclamconf" "$newfreshclamconf" else printf "\n\n WARNING: No saved file $oldfreshclam.conf\n " printf "\n\n WARNING: USE NEW freshclam.conf\n " fi else printf "No $clambkdir .. Use original one OK \n" fi #** post clamav updating... if [ "$filerule" = "yuji-okamura" ] ; then if [ ! -f "$FreshClamDaemon" ]; then printf "No FreshClamDaemon... OK \n " printf "Re-modify freshclam mode \n " sudo chown clamav "$binfreshclam" sudo chmod u+s "$binfreshclam" printf "Re-modify freshclam mode Done \n " fi fi #*** test run... printf "test runing freshclam of version %s \n ", $latest && \ "$binfreshclam" && \ printf "Removing all source files.." && \ cd .. rm -Rf clamav-$latest rm -f clamav-$latest.tar.gz rm -f stable.php* if [ "$filerule" = "yuji-okamura" ] ; then if [ -f "$FreshClamDaemon" ]; then sudo "$FreshClamDaemon" start printf "Start FreshClamDaemon .. done \n" fi fi