LinuxSir.Org  
| 网站首页 | 论坛帮助 |

欢迎来到LinuxSir.Org!
您还未登录,请登录后查看论坛,或者点击论坛上方的注册链接注册新账号。


发表新主题 回复
置顶的主题 精华主题  
主题工具
旧 03-06-04, 15:21 第 31 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: RPM-INSTALLER


感谢作者:liweiming
代码:
#!/bin/sh DIALOG=Xdialog $DIALOG --backtitle "选项" \ --title "安装选项" \ --checklist "这是一个利用Xdialog制作的RPM包安装程序,如果有什么问题, 请联系Lee FICQ:1368 \n 请选择安装选项:" 0 0 0 \ "-i" "默认普通安装" on \ "-U" "升级安装" off \ " --force" "强制" On \ " --nodeps" "忽略依赖关系" off 2> /tmp/checklist.tmp.$$ retval=$? ch1="-`grep -wo i /tmp/checklist.tmp.$$`" ch2="-`grep -wo U /tmp/checklist.tmp.$$`" ch3=`grep -wo force /tmp/checklist.tmp.$$` ch4=`grep -wo nodeps /tmp/checklist.tmp.$$` if [ "$ch1" == "-" ]; then ch1="" fi if [ "$ch2" == "-" ]; then ch2="" fi if [ "$ch3" != "" ]; then ch3="--$ch3" fi if [ "$ch4" != "" ]; then ch4="--$ch4" fi rm -f /tmp/checklist.tmp.$$ case $retval in 0) choice="$ch1 $ch2 $ch3 $ch4" FILE=`$DIALOG --stdout --title "请选择一个RPM包文件" --fselect /home 0 0` case $? in 0) (rpm $choice -vh $FILE )|$DIALOG --title "正在安装,请稍等....." --left --progress "RPM包正在安装:\n\n" 0 0 $RPM_MAX_DOTS_NUMBER $RPM_LEADING_MSG_LENGTH $DIALOG --title "Finished!" --msgbox "安装完毕!" 0 0 ;; esac ;; 1) echo "Bye!";; 255) echo "Bye!";; esac
  KornLee 当前离线   回复时引用此帖
旧 03-06-21, 00:59 第 32 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: 阿拉伯数字转换为大写数字的脚本[perl版本]


感谢作者:LY00兄
[code]
#!/usr/bin/perl -w

# Chinese count method
# wrote by Lyoo
# iamlyoo@163.com
# 2003/06/22


# match @unit = qw / 个 拾 佰 仟 万 拾万 佰万 仟万/
@unit = qw / A B C D E F G H / ;

############################################################################
#
# receive user's input
#
############################################################################

$count = 0;
while ( $count < 1 ) {
print "Please input a number:";
chomp ($number = <STDIN>);
if ( $number =~ /^[-,+]?\d+\.?\d*$/ ) {
$count += 1;
} else {
print "It's not a Number!\n";
redo;
}
}

############################################################################
#
# create a number_array
#
############################################################################

# add a number to the number_string,
# so that the while-loop can get the "0" in the tail of the number_string.
$number_9 = $number."9";

# convert the number to a array.
$dot = "no";
while ($number_9) {
my $single = $number_9;
$single =~ s/([\d,.,+,-]).*/$1/;
$number_9 =~ s/[\d,.,+,-](.*)/$1/;
push (@number_array,$single);
$dot = "yes" if $single eq ".";
}

# delect the addition number.reverse the array.
pop @number_array;
@number_array = reverse @number_array;

# get number's sylobm.
$sylobm = "";
$sylobm = pop @number_array if $number_array[-1] =~ /[+,-]/;

# get the number_dot_string.
$number_dot_string = "";
if ($dot eq "yes") {
while (@number_array) {
$number_dot_string .= shift @number_array;
last if $number_dot_string =~ /\d\./;
};
$number_dot_string = reverse $number_dot_string;
};


#############################################################################
#
# creat a number_unit_array
#
#############################################################################

$min_unit = 9;
$j = 0;
$i = 0;
$n = 0;

foreach (@number_array) {
push (@number_unit_array,$unit[$i].$_);

if ($i == 0) {
$j++;
$min_unit = "on";
$switch = "on"
};

unless ($switch eq "off" || $_ eq "0") {
$min_unit = $n;
};

unless ($switch eq "off" || $min_unit eq "on") {
$number_unit_array[$min_unit] = ("Z" x ($j-1)).$number_unit_array[$min_unit];
$switch = "off";
}

$i++;
$n++;
$i = $i % 8;
}

#############################################################################
#
# modify the number_unit_string
#
#############################################################################

foreach (@number_unit_array) {
$number_unit_string .= $_;
}
$number_unit_string = reverse $number_unit_string;
$_ = $number_unit_string;
s/0[A-H]/0/g;
s/0+/0/g;
s/A//g;
s/0+$//;

#print "$_\n";

s/H(\d)G(\d)F(\d)E/D$1C$2B$3E/g;

s/H(\d)G(\d)F/D$1C$2F/g;
s/H(\d)G(\d)E/D$1C$2E/g;
s/H(\d)F(\d)E/D$1B$2E/g;
s/G(\d)F(\d)E/C$1B$2E/g;


s/H(\d)E/D$1E/g;
s/G(\d)E/C$1E/g;
s/F(\d)E/B$1E/g;

s/H(\d)F/D$1F/g;
s/G(\d)F/C$1F/g;

s/H(\d)G/D$1G/g;

$number_unit_string = "$sylobm"."$_"."$number_dot_string";

#############################################################################
#
# output the number_unit_string as a array
#
#############################################################################

# convert number_unit_string to array.
# it's ugly but without this action
# chinese can't output correct.
# I don't know why :(

while ($number_unit_string) {
my $single = $number_unit_string;
$single =~ s/([\w,.,+,-]).*/$1/;
$number_unit_string =~ s/[\w,.,+,-](.*)/$1/;
push (@number_unit_ok,$single);
}
#print "number_unit_ok is @number_unit_ok.\n";

foreach (@number_unit_ok) {
&print_chinese;
}
print "\n";

sub print_chinese {
if ($_ eq 0) {
print "零";
} elsif ($_ eq 1) {
print "壹";
} elsif ($_ eq 2) {
print "贰";
} elsif ($_ eq 3) {
print "叁";
} elsif ($_ eq 4) {
print "肆";
} elsif ($_ eq 5) {
print "伍";
} elsif ($_ eq 6) {
print "陆";
} elsif ($_ eq 7) {
print "柒";
} elsif ($_ eq 8) {
print "捌";
} elsif ($_ eq 9) {
print "玖";
} elsif ($_ eq A) {
print "个";
} elsif ($_ eq B) {
print "拾";
} elsif ($_ eq C) {
print "佰";
} elsif ($_ eq D) {
print "仟";
} elsif ($_ eq E) {
print "万";
} elsif ($_ eq F) {
print "拾万";
} elsif ($_ eq G) {
print "佰万";
} elsif ($_ eq H) {
print "仟万";
} elsif ($_ eq Z) {
print "亿";
} elsif ($_ eq "+") {
print "<正>";
} elsif ($_ eq "-") {
print "<负>";
} elsif ($_ eq ".") {
print "<点>";
}
}

#############################################################################
# the end of this script
############################################################################

此帖于 03-06-22 13:21 被 KornLee 编辑.
  KornLee 当前离线   回复时引用此帖
旧 03-06-21, 01:03 第 33 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: 阿拉伯数字转换为大写数字的脚本[shell版本]


感谢作者 penny兄
代码:
#!/bin/bash #penny_ccf@hotmail.com #it's ugly, but it works cconvert(){ declare -a cnum; declare -a cmag; cnum[1]="壹" cnum[2]="贰" cnum[3]="叁" cnum[4]="肆" cnum[5]="伍" cnum[6]="陆" cnum[7]="柒" cnum[8]="拔" cnum[9]="玖" cnum[0]="零" cmag[0]="" cmag[1]="拾" cmag[2]="佰" cmag[3]="仟" cmag[4]="万" cmag[5]="拾" cmag[6]="百" cmag[7]="千" tempalpha="$1"; ctempmag=$2; if [ $tempalpha == "00000000" ] ; then CSTR=""; return 0; fi let templength="${#tempalpha}"; CSTR=""; for ((m=0;m<templength;m++)) do tempi=${tempalpha:m:1}; let tempj="$templength-$m-1"; if ((( tempi == 0 )) && (( tempj ==4 ))); then CSTR=$CSTR"万"; elif (( tempi == 0 )); then CSTR=$CSTR${cnum[0]}; else CSTR=$CSTR${cnum[$tempi]}${cmag[$tempj]}; fi done CSTR=$(echo $CSTR | sed -e 's/零零*/零/g' -e 's/零$//g' -e 's/零零零万//g'); CMAG=""; for ((m=0;m<ctempmag;m++)) do CMAG=$CMAG"亿"; done CSTR=$CSTR$CMAG; } alpha=$1; length=${#alpha}; let k="$length/8"; let modl="$length%8"; MYSTR=""; tempstr=${alpha:0:$modl}; if ((modl>0)); then cconvert $tempstr $k; fi MYSTR=$MYSTR$CSTR; for ((i=0;i<k;i++)) do let pos="$i*8+modl"; tempstr=${alpha:$pos:8}; let tempmag="$k-$i-1"; cconvert $tempstr $tempmag; MYSTR=$MYSTR$CSTR; done echo $MYSTR | sed -e 's/亿零万/亿零/g' -e 's/零万/万/g' -e 's/零亿/亿/g' -e 's/零零*/零/g' -e 's/零$//g';
  KornLee 当前离线   回复时引用此帖
旧 03-07-05, 01:25 第 34 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: 一个拷贝进度条的实现


特别感谢作者:idkey兄
代码:
#!/bin/sh # Last modified: 2003年07月05日 星期六 00时09分44秒 [test] SOURCE=$1 TARGET=$2 #CP=./fack_cp CP=cp $CP "$SOURCE" "$TARGET" & CPID=$! isalive(){ out=`ps -p $1 2> /dev/null` return $? } while [ 1 ]; do { SSIZE=`/bin/ls -l $SOURCE | gawk "{print \\\$5}"` if [ -f $TARGET ]; then TSIZE=`/bin/ls -l $TARGET | gawk "{print \\\$5}"` else TSIZE="0" fi PERCENT=`echo "scale=2; $TSIZE/$SSIZE*100" | bc -l` RATE=`echo "scale=0; 63*$PERCENT/100" | bc -l` BLUE="\\033[3;44m" NORMAIL="\\033[0;39m" BAR=$BLUE i=0 while [ $i -le 62 ]; do [ $i = $RATE ] && BAR=$BAR"\\033[7;39m" BAR=$BAR" " let i=$i+1 done BAR=$BAR$NORMAIL echo -en "\r$BAR ${PERCENT}%" if ! isalive "$CPID"; then echo -en "\n"; exit; fi sleep 1 } done

此帖于 03-07-05 01:27 被 KornLee 编辑.
  KornLee 当前离线   回复时引用此帖
旧 03-07-06, 16:44 第 35 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: shell命令中文帮助


特别感谢作者: ilmargaret兄

脚本很简单却很实用,尤适合于编程初学者和英语太菜的人.
功能: 任何时候在命令行里输入你想查找的命令名称,该脚本都会显示此命令的详细用法,而且是中文的哦.
脚本名称:showme
代码:
csplit -sf help /root/scripts/functionlib/datafile.txt /"command: $1"/ '/over/' 2>errors if [ $? -eq 0 ] then more help01 rm help?? else echo Sorry,the commnand $1 was not found in your datafile! fi
系统设置:将附件和脚本放在/root/scripts/functionlib/下,然后在/etc/profile中做如下改动:

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC 改为:
export PATH=${PATH}:/root/scripts/functionlib USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC ,这样就可以在任何目录下执行该脚本了,就象执行man命令一样.

备注: 附件datafile里你可以不断的添加新的命令,只要添加的命令与我原来的格式一致即可,时间久了就变成手册了,随时查阅,对shell编程很有用!

此帖于 03-07-07 14:44 被 KornLee 编辑.
  KornLee 当前离线   回复时引用此帖
旧 03-07-12, 13:19 第 36 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

idkey 兄的有bug.







__________________
Kurt is me.
Studing hard. Making my way to the top of the world.
  lordbyorn 当前离线   回复时引用此帖
旧 03-08-03, 10:35 第 37 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

This shell do a statistics on the online pcs.
代码:
#!/bin/sh #This shell do a statistics on the online pcs. #The ip range is from $SURFIX.$FROM to $SURFIX.$TO #The best way is using argument to define the range and log file #I didn't do that SURFIX=192.168.32 FROM=1 TO=244 LOGFILE=log let TO=TO+1 var=$FROM #log file save the results #If we has do that before, contine the statistics #if we does do that, create a new statistics if [ ! -f $LOGFILE ];then #It seems that this while is not necessary, but make this shell #more easy to understand while [ $var -lt $TO ]; do set ip$var=0; let var=var+1 done else for tmp in `awk "{ print \\\$2 }" $LOGFILE` do let ip$var=$tmp let var=var+1 done fi #ip$var save the data how many times remote host is on line #use ping command to find out var=$FROM while [ $var -lt $TO ] do if ping $SURFIX.$var -c 1 -w 1;then let ip$var=ip$var+1 fi let var=var+1 done #create a new empty log file #and save new data >$LOGFILE var=$FROM while [ $var -lt $TO ] do echo $SURFIX.$var $[ip$var] >>$LOGFILE let var=var+1 done

此帖于 03-08-03 10:38 被 lordbyorn 编辑.
  lordbyorn 当前离线   回复时引用此帖
旧 03-08-03, 16:27 第 38 帖
lordbyorn
 
lordbyorn 的头像
 
 
临时退役版主  
  注册日期: May 2003
  帖子: 889
  精华: 1
 

OpenLab:/ # cat log
192.168.32.1 76
192.168.32.2 0
192.168.32.3 0
192.168.32.4 0
192.168.32.5 0
192.168.32.6 0
192.168.32.7 0
192.168.32.8 0
192.168.32.9 16
192.168.32.10 76
192.168.32.11 76
192.168.32.12 45
192.168.32.13 22
192.168.32.14 20
192.168.32.15 0
192.168.32.16 41
192.168.32.17 0
192.168.32.18 0
192.168.32.19 0
192.168.32.20 0
192.168.32.21 25
192.168.32.22 19
192.168.32.23 0
192.168.32.24 0
192.168.32.25 63
192.168.32.26 0
192.168.32.27 17
192.168.32.28 63
192.168.32.29 0
192.168.32.30 0
192.168.32.31 0
192.168.32.32 0
192.168.32.33 0
192.168.32.34 0
192.168.32.35 1
192.168.32.36 0
192.168.32.37 0
192.168.32.38 16
192.168.32.39 0
192.168.32.40 0
192.168.32.41 49
192.168.32.42 9
192.168.32.43 0
192.168.32.44 0
192.168.32.45 21
192.168.32.46 0
192.168.32.47 0
192.168.32.48 0
192.168.32.49 0
192.168.32.50 0
192.168.32.51 0
192.168.32.52 56
192.168.32.53 0
192.168.32.54 0
192.168.32.55 63
192.168.32.56 0
192.168.32.57 63
192.168.32.58 0
192.168.32.59 22
192.168.32.60 0
192.168.32.61 33
192.168.32.62 31
192.168.32.63 62
192.168.32.64 63
192.168.32.65 26
192.168.32.66 57
192.168.32.67 0
192.168.32.68 0
192.168.32.69 46
192.168.32.70 0
192.168.32.71 0
192.168.32.72 0
192.168.32.73 56
192.168.32.74 63
192.168.32.75 0
  lordbyorn 当前离线   回复时引用此帖
旧 03-08-11, 01:46 第 39 帖
benzy
 
 
 
注册会员  
  注册日期: May 2003
  帖子: 19
  精华: 0
 

标题: 我也来一个:用iptables自动封禁多线程连接ftpd的ip,hoho


使用metalog和iptables配合,对多线程连接ftp服务器的ip进行暂时的封禁

metalog.conf里ftpd的配置如下
代码:
FTP Server : program = "pure-ftpd" logdir = "/var/log/ftpd" command = "/usr/sbin/ftpdchk" #将log分三个参数提交给处理程序,分别是:时间、进程名、内容
处理程序如下:
代码:
#!/bin/bash # ftpdchk - check and block xx ip # benzy@bbs.pku.ecu.cn, 2003/8/1 # cp file to /usr/sbin/ftpdchk #set -x # Too many connections (1) from this IP: [211.71.208.1] ip="`echo "$3" | grep -oe '\[[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\]'`" if [ -n "$ip" ];then log="/var/log/ftpd/ftpdchk.log" ip=${ip#[};ip=${ip%]} time=$1 # ftpd=$2 # iptable配置略。总之建一个ftp链专门处理ftp请求:) /sbin/iptables -I ftp -j DROP -p tcp --dport ftp -s $ip # 5分钟后解封 echo "/sbin/iptables -D ftp -j DROP -p tcp --dport ftp -s $ip" | at now +5minutes echo "$ip $time" >>$log fi

此帖于 03-08-15 00:25 被 KornLee 编辑.
  benzy 当前离线   回复时引用此帖
旧 03-08-15, 00:16 第 40 帖
deepin
 
 
 
注册会员  
  注册日期: Sep 2002
  帖子: 118
  精华: 1
 

标题: 批量改当前目录下文件后缀


代码:
#!/bin/sh for filen in * do fn=`echo $filen |cut -d "." -f 1` ext=`echo $filen |cut -d "." -f 2` if [ $ext = $1 ];then echo "$filen -> $fn.$2" mv $filen $fn.$2 fi done







__________________
欢迎访问中文debian社区
http://www.debianchina.org

此帖于 03-08-15 00:24 被 KornLee 编辑.
  deepin 当前离线   回复时引用此帖
旧 03-08-15, 00:19 第 41 帖
deepin
 
 
 
注册会员  
  注册日期: Sep 2002
  帖子: 118
  精华: 1
 

标题: 替换某个目录下所有文件中的某个字符串为另一个字符串。


使用方式如下:
frall.sh /work teststr testok
执行结果如下:
/work目录下所有文件(包括子目录下)中存在teststr字符串的位置,全部被testok字符串所替代.
代码:
#!/bin/sh useage() { echo "useage:$0 dirname oldstr newstr" echo "attantion:dirname must haven't oldstr!" } tf1=/tmp/.f.tmp1 tf2=/tmp/.f.tmp2 workdir=`pwd` rm -f $tf1 rm -f $tf2 # do with /$2-xxx and /$2-xxx/$2-yyy if [ $# -eq 0 ];then useage exit fi for dir in `find $1/* -type d` do echo $dir | awk 'BEGIN {FS="/"} ;{print $NF}' | grep $2 if [ $? = 0 ];then echo `echo $dir | wc -c ` $dir >> $tf1 fi done sort -r -n $tf1 -o $tf2 while read LINE do dir=`echo $LINE | cut -d " " -f 2` olddir=`echo $dir | awk 'BEGIN {FS="/"};{print $NF}'` newdir=`echo $olddir | sed s/$2/$3/g` cd $dir;cd .. mv $olddir $newdir cd $workdir done < $tf2 for file in `find $1/* -type f` do grep $2 $file 1>2 2>/dev/null if [ $? = 0 ] && [ $file != $0 ]; then # echo "$file have $2 " >> /tmp/nnn ed - $file << EO g/$2/s/$2/$3/g . w q EO fi newname=`echo $file | sed s/$2/$3/g` mv $file $newname done

此帖于 03-08-15 00:30 被 KornLee 编辑.
  deepin 当前离线   回复时引用此帖
旧 03-08-19, 11:26 第 42 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: backup version 0.59


感谢作者:alphatan
脚本说明
backup version 0.59
把backup脚本分两个文件(backup.sh跟backupFunc.sh,请使用者把下述语句分开保存),现版本更具移植性。
首先,脚本脱离了uMntFtpDirs与01MntFtpDirs.sh的束缚,通过读取/etc/mtab,用函数实现了在备份系统时不用备份--bind的文件夹。
另外,本版本中不直接使用命令名进行操作,而使用变量来代指,一来便于用户在自己的机上使用--只需要更改LEADINGDIR(指向放置.tar.gz 文件的绝对路径)、PATH2BCKUPSH(指向backup.sh的绝对路径)跟$SUCOM后接的用户名的值就可以了。而且如果要提高脚本的安全性,可以把本脚本要用到的程序备份到一个独立目录,再把变量指向它,然后就算系统后来感染了,也还可以保持备份的安全性。
最后,本脚本还具备信号处理能力,可以防止用户不小心错按CTRL-C等发出TERM, INT信号,当然,用户如果真要结束脚本,只需要按提示应答即可。
同时,本人为本脚本程序源用GPL协议发布,用以更方便大家传播与使用。
代码:
------------------------------------backup.sh------------------------------------------------ #!/bin/sh # # "backup.sh" is a script written in bash to backup the whole system # Copyright (C) 2003 alphatan<alphatan@263.net> version 0.59 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # You can get it by accessing http://www.gnu.org/licenses/gpl.html # declare -i whereAmI=0 # declare the script wide variables and definitions. LEADINGDIR=/backup/filebck/LinuxBck PATH2BCKUPSH=/etc/rc.d/init.d AWKCOM=$(which awk) CATCOM=$(which cat) CHOWNCOM=$(which chown) CPCOM=$(which cp) ECHOCOM=$(which echo) FINDCOM=$(which find) LNCOM=$(which ln) MKCOM=$(which mkdir) MOUNTCOM=$(which mount) RMCOM=$(which rm) SUCOM=$(which su) TARCOM=$($ECHOCOM $(which tar) -Pzcf ) TOUCHCOM=$(which touch) UMOUNTCOM=$(which umount) declare -a mountedDirsFromMtab=( $(grep '/var/ftp/' /etc/mtab) ) declare -i mountedDirsAmount=${#mountedDirsFromMtab[@]} declare -f backupSystemDirs operatingMountDirs calculateTm signalDealingFunc source ${0%/*.sh}/backupFunc.sh trap signalDealingFunc INT TERM QUIT # declare the copyright of this software $ECHOCOM -ne "\n\n" $ECHOCOM -ne "\t \"backup.sh\" is a script written in bash to backup the whole system \n" $ECHOCOM -ne "\t Copyright (C) 2003 alphatan<alphatan@263.net> version 0.59\n" $ECHOCOM -ne "\t This program is free software; you can redistribute it and/or modify \n" $ECHOCOM -ne "\t it under the terms of the GNU General Public License as published by \n" $ECHOCOM -ne "\t the Free Software Foundation; either version 2 of the License, or \n" $ECHOCOM -ne "\t (at your option) any later version. \n" $ECHOCOM -ne "\t You can get it by accessing http://www.gnu.org/licenses/gpl.html \n" $ECHOCOM -ne "\n Input the backup dir name: " read BACKUPDIR # time calculating process starts calculateTm start let whereAmI=0 # backup system wide files backupSystemDirs let whereAmI=0 # Establish DETAILED and SIMPLE system list. SYSLISTDIR=sysList if [ ! -d $LEADINGDIR/$BACKUPDIR/$SYSLISTDIR ]; then $MKCOM $LEADINGDIR/$BACKUPDIR/$SYSLISTDIR fi operatingMountDirs umount let whereAmI=0 $FINDCOM / -fprint "$LEADINGDIR/$BACKUPDIR/$SYSLISTDIR/$BACKUPDIR""$SYSLISTDIR""Simple.txt" $FINDCOM / -fls "$LEADINGDIR/$BACKUPDIR/$SYSLISTDIR/$BACKUPDIR""$SYSLISTDIR""Detailed.txt" operatingMountDirs mount let whereAmI=0 # Backup this script. $CPCOM $PATH2BCKUPSH/backup*.sh $LEADINGDIR/$BACKUPDIR/ # Establish sysChange.log by "su alphatan" at $BACKUPDIR; # Then, remove the former linkage, and "link" again at /home/alphatan; $TOUCHCOM $LEADINGDIR/$BACKUPDIR/sysChange.log $CHOWNCOM alphatan.root $LEADINGDIR/$BACKUPDIR/sysChange.log $SUCOM alphatan --command="$RMCOM -rf ~/sysChange.log" $SUCOM alphatan --command="$LNCOM -s $LEADINGDIR/$BACKUPDIR/sysChange.log ~/sysChange.log" # "empty line to end syntax hightlight of \" # Calculate consuming time. calculateTm end let whereAmI=0 ------------------------------------backup.sh------------------------------------------------ ------------------------------------backupFunc.sh------------------------------------------------ # # "backupFunc.sh" is a script of functions written in bash as an associated "backup.sh" # Copyright (C) 2003 alphatan<alphatan@263.net> version 0.59 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # You can get it by accessing http://www.gnu.org/licenses/gpl.html # # Following is the definitions of functions. function calculateTm() { let whereAmI=1 if [ $1 = 'end' ]; then ENDTIMEMARK=`date +%s` let USEDSECONDS=$ENDTIMEMARK-$STARTTIMEMARK let USEDSECOND=$USEDSECONDS%60 let USEDMINUTE=($USEDSECONDS/60)%60 let USEDHOUR=($USEDSECONDS/3600)%60 if [ $USEDSECONDS == 0 ]; then $ECHOCOM "It doesn't need a second?? Is there something in trouble?" builtin exit 1 else $ECHOCOM "It used $USEDHOUR:$USEDMINUTE:$USEDSECOND" builtin exit 0 fi elif [ $1 = 'start' ]; then STARTTIMEMARK=`date +%s` else $ECHOCOM -e " calculateTM Usage: calculateTM [start|stop] " >&2 exit 1 fi } function operatingMountDirs() { let whereAmI=1 declare -i i=0 if [ $1 = mount ]; then local OPERATIONONTHEMOUNTDIRS='$MOUNTCOM --bind ${mountedDirsFromMtab[$i]} ${mountedDirsFromMtab[$i+1]}' elif [ $1 = umount ]; then local OPERATIONONTHEMOUNTDIRS='$UMOUNTCOM ${mountedDirsFromMtab[$i+1]}' else $ECHOCOM -e " operatingMountDirs Usage: operatingMountDirs [mount|umount] " >&2 exit 1 fi while [ $i -lt $mountedDirsAmount ] ; do eval $OPERATIONONTHEMOUNTDIRS let i+=6 done } function backupSystemDirs() { let whereAmI=1 if [ ! -d $LEADINGDIR/$BACKUPDIR ]; then $MKCOM $LEADINGDIR/$BACKUPDIR fi $TARCOM $LEADINGDIR/$BACKUPDIR/bin.tar.gz /bin $TARCOM $LEADINGDIR/$BACKUPDIR/boot.tar.gz /boot $TARCOM $LEADINGDIR/$BACKUPDIR/dev.tar.gz /dev $TARCOM $LEADINGDIR/$BACKUPDIR/etc.tar.gz /etc $TARCOM $LEADINGDIR/$BACKUPDIR/home.tar.gz /home $TARCOM $LEADINGDIR/$BACKUPDIR/initrd.tar.gz /initrd $TARCOM $LEADINGDIR/$BACKUPDIR/lib.tar.gz /lib $TARCOM $LEADINGDIR/$BACKUPDIR/misc.tar.gz /misc $TARCOM $LEADINGDIR/$BACKUPDIR/opt.tar.gz /opt $TARCOM $LEADINGDIR/$BACKUPDIR/root.tar.gz /root $TARCOM $LEADINGDIR/$BACKUPDIR/sbin.tar.gz /sbin $TARCOM $LEADINGDIR/$BACKUPDIR/tftpboot.tar.gz /tftpboot operatingMountDirs umount $TARCOM $LEADINGDIR/$BACKUPDIR/var.tar.gz /var operatingMountDirs mount $TARCOM $LEADINGDIR/$BACKUPDIR/usr_share.tar.gz /usr/share $TARCOM --exclude=/usr/share $LEADINGDIR/$BACKUPDIR/usr.tar.gz /usr } function signalDealingFunc() { local userChoice local lineNumber=$LINENO if (( $whereAmI==0 )); then local currentOperatingFileName=$0 #/etc/rc.d/init.d/backup.sh else local currentOperatingFileName=${0%.sh}Func.sh #/etc/rc.d/init.d/backupFunc.sh fi $ECHOCOM "Currently running LINE $LINENO within $currentOperatingFileName " $CATCOM $currentOperatingFileName |$AWKCOM "{if (NR==$lineNumber || NR==$lineNumber-1 || NR==$lineNumber+1) print NR\":\ \"\$0;}" builtin read -p "Are you sure you want to exit?(1:yes, 2:no) " userChoice until [ -n "$($ECHOCOM $userChoice | egrep '^(1|2|y|yes|n|no)$')" ]; do builtin read -p "Not a legal choice, (1:yes, 2:no) " userChoice done case $userChoice in 1 | y | yes ) builtin exit 1 ;; *) return ;; esac } ------------------------------------backupFunc.sh------------------------------------------------
  KornLee 当前离线   回复时引用此帖
旧 03-08-23, 03:00 第 43 帖
benzy
 
 
 
注册会员  
  注册日期: May 2003
  帖子: 19
  精华: 0
 

标题: 回复: 替换某个目录下所有文件中的某个字符串为另一个字符串。


引用:
最初由 deepin 发表
使用方式如下:
frall.sh /work teststr testok
执行结果如下:
/work目录下所有文件(包括子目录下)中存在teststr字符串的位置,全部被testok字符串所替代.
代码:
#!/bin/sh useage() { echo "useage:$0 dirname oldstr newstr" echo "attantion:dirname must haven't oldstr!" } tf1=/tmp/.f.tmp1 tf2=/tmp/.f.tmp2 workdir=`pwd` rm -f $tf1 rm -f $tf2 # do with /$2-xxx and /$2-xxx/$2-yyy if [ $# -eq 0 ];then useage exit fi for dir in `find $1/* -type d` do echo $dir | awk 'BEGIN {FS="/"} ;{print $NF}' | grep $2 if [ $? = 0 ];then echo `echo $dir | wc -c ` $dir >> $tf1 fi done sort -r -n $tf1 -o $tf2 while read LINE do dir=`echo $LINE | cut -d " " -f 2` olddir=`echo $dir | awk 'BEGIN {FS="/"};{print $NF}'` newdir=`echo $olddir | sed s/$2/$3/g` cd $dir;cd .. mv $olddir $newdir cd $workdir done < $tf2 for file in `find $1/* -type f` do grep $2 $file 1>2 2>/dev/null if [ $? = 0 ] && [ $file != $0 ]; then # echo "$file have $2 " >> /tmp/nnn ed - $file << EO g/$2/s/$2/$3/g . w q EO fi newname=`echo $file | sed s/$2/$3/g` mv $file $newname done
其实有个命令就是这个功能的
rename str1 str2 files
呵呵
  benzy 当前离线   回复时引用此帖
旧 03-08-30, 11:40 第 44 帖
colored
 
colored 的头像
 
 
注册会员  
  注册日期: Apr 2003
  我的住址: 南昌
  帖子: 158
  精华: 1
 

标题: 回复: shell命令中文帮助


引用:
最初由 javalee 发表
特别感谢作者: ilmargaret兄

备注: 附件datafile里你可以不断的添加新的命令,只要添加的命令与我原来的格式一致即可,时间久了就变成手册了,随时查阅,对shell编程很有用!
这个datafile是要自己加入中文说明吗?格式是什么样子的?
  colored 当前离线   回复时引用此帖
旧 03-09-03, 17:25 第 45 帖
KornLee
 
 
 
★☆★☆★☆★  
  注册日期: Nov 2002
  我的住址: LinuxWorld
  帖子: 6,960
  精华: 61
 

标题: Dialog经典--Slackware软件包管理程序


推荐者:Sandy
代码:
#!/bin/sh # # Copyright 1993, 1994, 1995, 1996, 1997, # 1998, 1999 Patrick Volkerding, Moorhead, MN USA # Copyright 2001 Slackware Linux, Inc., Concord, CA USA # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Wed, 27 Apr 1994 00:06:50 -0700 (PDT) # Optimization by David Hinds. SOURCE_DIR=/var/log/mount ASK="tagfiles" if [ -L /bin/chmod -a -L /bin/chown ]; then # probably on the bootdisk using busybox TARGET_DIR=/mnt TMP=/mnt/var/log/setup/tmp if mount | grep "on /mnt" 1> /dev/null 2>&1 ; then # good true else # bad echo echo echo "You can't run pkgtool from the rootdisk until you've mounted your Linux" echo "partitions beneath /mnt. Here are some examples of this:" echo echo "If your root partition is /dev/hda1, and is using ext2fs, you would type:" echo "mount /dev/hda1 /mnt -t ext2" echo echo "Then, supposing your /usr partition is /dev/hda2, you must do this:" echo "mount /dev/hda2 /mnt/usr -t ext2" echo echo "Please mount your Linux partitions and then run pkgtool again." echo exit fi else TARGET_DIR=/ TMP=/var/log/setup/tmp fi if [ ! -d $TMP ]; then mkdir -p $TMP chmod 700 $TMP fi ADM_DIR=$TARGET_DIR/var/log LOG=$TMP/PKGTOOL.REMOVED # remove whitespace crunch() { while read FOO ; do echo $FOO done } package_name() { STRING=`basename $1 .tgz` # Check for old style package name with one segment: if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then echo $STRING else # has more than one dash delimited segment # Count number of segments: INDEX=1 while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do INDEX=`expr $INDEX + 1` done INDEX=`expr $INDEX - 1` # don't include the null value # If we don't have four segments, return the old-style (or out of spec) package name: if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then echo $STRING else # we have four or more segments, so we'll consider this a new-style name: NAME=`expr $INDEX - 3` NAME="`echo $STRING | cut -f 1-$NAME -d -`" echo $NAME # cruft for later #VER=`expr $INDEX - 2` #VER="`echo $STRING | cut -f $VER -d -`" #ARCH=`expr $INDEX - 1` #ARCH="`echo $STRING | cut -f $ARCH -d -`" #BUILD="`echo $STRING | cut -f $INDEX -d -`" fi fi } remove_packages() { for pkg_name in $* do if [ -r $ADM_DIR/packages/$pkg_name ]; then dialog --title "PACKAGE REMOVAL IN PROGRESS" --cr-wrap --infobox \ "\nRemoving package $pkg_name.\n\ \n\ Since each file must be checked \ against the contents of every other installed package to avoid wiping out \ areas of overlap, this process can take quite some time. If you'd like to \ watch the progress, flip over to another virtual console and type:\n\ \n\ tail -f $TMP/PKGTOOL.REMOVED\n" 13 60 export ROOT=$TARGET_DIR removepkg $pkg_name >> $LOG 2> /dev/null else echo "No such package: $pkg_name. Can't remove." >> $LOG fi done } # Here, we read the list of arguments passed to the pkgtool script. if [ $# -gt 0 ]; then # there are arguments to the command while [ $# -gt 0 ]; do case "$1" in "-sets") DISK_SETS=`echo $2 | tr "[A-Z]" "[a-z]"` ; shift 2 ;; "-source_mounted") SOURCE_MOUNTED="always" ; shift 1 ;; "-ignore_tagfiles") ASK="never" ; shift 1 ;; "-tagfile") USETAG=$2 ; shift 2 ;; "-source_dir") SOURCE_DIR=$2 ; shift 2 ;; "-target_dir") TARGET_DIR=$2 ADM_DIR=$TARGET_DIR/var/log shift 2 ;; "-source_device") SOURCE_DEVICE=$2 ; shift 2 ;; esac done else # there were no arguments, so we'll get the needed information from the # user and then go on. CMD_START="true" rm -f $TMP/SeT* while [ 0 ]; do dialog --title "Slackware Package Tool (pkgtool version 9.0.0)" \ --menu "\nWelcome to the Slackware package tool.\n\ \nWhich option would you like?\n" 17 75 7 \ "Current" "Install packages from the current directory" \ "Other" "Install packages from some other directory" \ "Floppy" "Install packages from floppy disks" \ "Remove" "Remove packages that are currently installed" \ "View" "View the list of files contained in a package" \ "Setup" "Choose Slackware installation scripts to run again" \ "Exit" "Exit Pkgtool" 2> $TMP/reply if [ ! $? = 0 ]; then rm -f $TMP/reply dialog --clear exit fi REPLY="`cat $TMP/reply`" rm -f $TMP/reply if [ "$REPLY" = "Exit" ]; then dialog --clear exit fi if [ "$REPLY" = "Setup" ]; then echo 'dialog --title "SELECT SYSTEM SETUP SCRIPTS" --item-help --checklist \ "Please use the spacebar to select the setup scripts to run. Hit enter when you \ are done selecting to run the scripts." 17 70 9 ' > $TMP/setupscr for script in $ADM_DIR/setup/setup.* ; do BLURB=`grep '#BLURB' $script | cut -b8-` if [ "$BLURB" = "" ]; then BLURB="\"\"" fi echo " \"`basename $script | cut -f2- -d .`\" $BLURB \"no\" $BLURB \\" >> $TMP/setupscr done echo "2> $TMP/return" >> $TMP/setupscr . $TMP/setupscr if [ ! "`cat $TMP/return`" = "" ]; then # Run each script: for script in `cat $TMP/return` ; do scrpath=$ADM_DIR/setup/setup.`echo $script | tr -d \"` rootdevice="`mount | head -1 | cut -f 1 -d ' '`" ( COLOR=on ; cd $TARGET_DIR ; . $scrpath / $rootdevice ) done fi rm -f $TMP/return $TMP/setupscr continue fi # end Setup if [ "$REPLY" = "View" ]; then DEFITEM="" export DEFITEM dialog --title "SCANNING" --infobox "Please wait while \ Pkgtool scans your system to determine which packages you have \ installed and prepares a list for you." 0 0 echo 'dialog $DEFITEM --item-help --menu "Please select the package you wish to view." 17 68 10 ' > $TMP/viewscr for name in `ls $ADM_DIR/packages` ; do pkg_name=`package_name $name` BLURB="`sed -n \"/$pkg_name:/{s/\\"//g;p;q;}\" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" # Let's have some backward compatibility with the interim beta (for now): if [ "$BLURB" = "" ]; then BLURB="`sed -n \"/$name:/{s/\\"//g;p;q;}\" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" fi echo " \"$name\" \"$BLURB\" \"View information about package $name\" \\" >> $TMP/viewscr done echo "2> $TMP/return" >> $TMP/viewscr while [ 0 ]; do . $TMP/viewscr if [ ! "`cat $TMP/return`" = "" ]; then DEFITEM="--default-item `cat $TMP/return`" dialog --title "CONTENTS OF PACKAGE: `cat $TMP/return`" --no-shadow --textbox "$ADM_DIR/packages/`cat $TMP/return`" \ 0 0 2> /dev/null else break fi done rm -f $TMP/return $TMP/viewscr $TMP/tmpmsg # This will clean up after most defective packages: chmod 755 / chmod 1777 /tmp continue fi if [ "$REPLY" = "Remove" ]; then dialog --title "SCANNING" --infobox "Please wait while Pkgtool scans \ your system to determine which packages you have installed and prepares \ a list for you." 0 0 # end section cat << EOF > $TMP/rmscript dialog --title "SELECT PACKAGES TO REMOVE" --item-help --checklist \ "Please select the \ packages you wish to Remove. Use the \ spacebar to select packages to delete, and the UP/DOWN arrow keys to \ scroll up and down through the entire list." 20 75 11 \\ EOF for name in `ls $ADM_DIR/packages` ; do pkg_name=`package_name $name` BLURB="`sed -n \"/$pkg_name:/{s/\\"//g;p;q;}\" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" # Let's have some backward compatibility with the interim beta (for now): if [ "$BLURB" = "" ]; then BLURB="`sed -n \"/$name:/{s/\\"//g;p;q;}\" $ADM_DIR/packages/$name | cut -f 2- -d : | crunch`" fi echo " \"$name\" \"$BLURB\" off \"Select/Unselect removing package $name\" \\" >> $TMP/rmscript done echo "2> $TMP/return" >> $TMP/rmscript if [ -L $LOG -o -r $LOG ]; then rm -f $LOG fi cat /dev/null > $LOG chmod 600 $LOG chmod 700 $TMP/rmscript export ADM_DIR; $TMP/rmscript remove_packages `cat $TMP/return | tr -d "\042"` if [ "`cat $TMP/PKGTOOL.REMOVED`" = "" ]; then rm -f $TMP/PKGTOOL.REMOVED dialog --title "NO PACKAGES REMOVED" --msgbox "Hit OK to return \ to the main menu." 5 40 else dialog --title "PACKAGE REMOVAL COMPLETE" --msgbox "The packages have \ been removed. A complete log of the files that were removed has been created \ in $TMP: PKGTOOL.REMOVED." 0 0 fi rm -f $TMP/rmscript $TMP/return $TMP/tmpmsg $TMP/SeT* chmod 755 / chmod 1777 /tmp # No, return to the main menu: # exit elif [ "$REPLY" = "Floppy" ]; then dialog --title "SELECT FLOPPY DRIVE" --menu "Which floppy drive would \ you like to install from?" \ 11 70 4 \ "/dev/fd0u1440" "1.44 MB first floppy drive" \ "/dev/fd1u1440" "1.44 MB second floppy drive" \ "/dev/fd0h1200" "1.2 MB first floppy drive" \ "/dev/fd1h1200" "1.2 MB second floppy drive" 2> $TMP/wdrive if [ $? = 1 ]; then dialog --clear exit fi SOURCE_DEVICE="`cat $TMP/wdrive`" rm -f $TMP/wdrive cat << EOF > $TMP/tmpmsg Enter the names of any disk sets you would like to install. Separate the sets with a space, like this: a b oi x To install packages from one disk, hit [enter] without typing anything. EOF dialog --title "SOFTWARE SELECTION" --inputbox "`cat $TMP/tmpmsg`" 13 70 2> $TMP/sets DISK_SETS="`cat $TMP/sets`" rm -f $TMP/sets if [ "$DISK_SETS" = "" ]; then DISK_SETS="disk" else DISK_SETS=`echo $DISK_SETS | sed 's/ /#/g'` DISK_SETS="#$DISK_SETS" fi break; elif [ "$REPLY" = "Other" ]; then dialog --title "SELECT SOURCE DIRECTORY" --inputbox "Please enter the name of the directory that you wish to \ install packages from:" 10 50 2> $TMP/pkgdir if [ $? = 1 ]; then rm -f $TMP/pkgdir $TMP/SeT* dialog --clear exit fi SOURCE_DIR="`cat $TMP/pkgdir`" SOURCE_MOUNTED="always" DISK_SETS="disk" chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp rm -f $TMP/pkgdir if [ ! -d $SOURCE_DIR ]; then dialog --title "DIRECTORY NOT FOUND" --msgbox "The directory you want to \ install from ($SOURCE_DIR) \ does not seem to exist. Please check the directory and then try again." \ 10 50 dialog --clear exit fi break; else # installing from current directory SOURCE_MOUNTED="always" SOURCE_DIR="$PWD" DISK_SETS="disk" chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp break; fi done fi if [ "$DISK_SETS" = "disk" ]; then ASK="always" fi mount_the_source() { # is the source supposed to be mounted already? if [ "$SOURCE_MOUNTED" = "always" ]; then # The source should already be mounted, so we test it if [ ! -d $SOURCE_DIR ]; then # the directory is missing cat << EOF > $TMP/tmpmsg Your source device cannot be accessed properly. Please be sure that it is mounted on $SOURCE_DIR, and that the Slackware disks are found in subdirectories of $SOURCE_DIR like specified. EOF dialog --title "MOUNT ERROR" --msgbox "`cat $TMP/tmpmsg`" 11 67 rm -f $TMP/tmpmsg exit 1; fi return 0; fi dialog --title "INSERT DISK" --menu "Please insert disk $1 and \ press ENTER to continue." \ 11 50 3 \ "Continue" "Continue with the installation" \ "Skip" "Skip the current disk series" \ "Quit" "Abort the installation process" 2> $TMP/reply if [ ! $? = 0 ]; then REPLY="Quit" else REPLY="`cat $TMP/reply`" fi rm -f $TMP/reply if [ "$REPLY" = "Skip" ]; then return 1; fi if [ "$REPLY" = "Quit" ]; then dialog --title "ABORTING" --msgbox "Aborting software installation." 5 50 chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp exit 1; fi; # Old line: # mount -r -t msdos $SOURCE_DEVICE $SOURCE_DIR # New ones: (thanks to Andy Schwierskott!) go_on=y not_successfull_mounted=1 while [ "$go_on" = y -a "$not_successfull_mounted" = 1 ]; do mount -r -t msdos $SOURCE_DEVICE $SOURCE_DIR not_successfull_mounted=$? if [ "$not_successfull_mounted" = 1 ]; then mount_answer=x while [ "$mount_answer" != "y" -a "$mount_answer" != "q" ] ; do dialog --title "MOUNT PROBLEM" --menu "Media was not successfully \ mounted! Do you want to \ retry, or quit?" 10 60 2 \ "Yes" "Try to mount the disk again" \ "No" "No, abort." 2> $TMP/mntans mount_answer="`cat $TMP/mntans`" rm -f $TMP/mntans if [ "$mount_answer" = "Yes" ]; then mount_answer="y" else mount_answer="q" fi done go_on=$mount_answer fi done test $not_successfull_mounted = 0 } umount_the_source() { if [ ! "$SOURCE_MOUNTED" = "always" ]; then umount $SOURCE_DEVICE 1> /dev/null 2>&1 fi; } install_disk() { mount_the_source $1 if [ $? = 1 ]; then umount_the_source; return 1; fi CURRENT_DISK_NAME="$1" PACKAGE_DIR=$SOURCE_DIR if [ "$SOURCE_MOUNTED" = "always" -a ! "$DISK_SETS" = "disk" ]; then PACKAGE_DIR=$PACKAGE_DIR/$1 fi # If this directory is missing or contains no *.tgz files, bail. if [ ! -d $PACKAGE_DIR ]; then return 1 fi if ls $PACKAGE_DIR/*.tgz 1> /dev/null 2> /dev/null ; then true else return 1 fi # # look for tagfile for this series and copy into $TMP/tagfile # touch $TMP/tagfile if [ ! "$DISK_SETS" = "disk" ]; then if [ -r $TMP/SeTtagext ]; then if [ -r $PACKAGE_DIR/tagfile`cat $TMP/SeTtagext` ]; then cat $PACKAGE_DIR/tagfile`cat $TMP/SeTtagext` >> $TMP/tagfile else if [ -r $PACKAGE_DIR/tagfile ]; then cat $PACKAGE_DIR/tagfile >> $TMP/tagfile fi fi # # Do we need to follow a custom path to the tagfiles? # elif [ -r $TMP/SeTtagpath ]; then custom_path=`cat $TMP/SeTtagpath` short_path=`basename $PACKAGE_DIR` # If tagfile exists at the specified custom path, copy it over. if [ -r $custom_path/$short_path/tagfile ]; then cat $custom_path/$short_path/tagfile >> $TMP/tagfile else # well, I guess we'll use the default one then. if [ -r $PACKAGE_DIR/tagfile ]; then cat $PACKAGE_DIR/tagfile >> $TMP/tagfile fi fi # # We seem to be testing for this too often... maybe this code should # be optimized a little... # elif [ -r $PACKAGE_DIR/tagfile ]; then cat $PACKAGE_DIR/tagfile >> $TMP/tagfile fi # # Execute menus if in QUICK mode: # if [ -r $TMP/SeTQUICK -a -r $PACKAGE_DIR/maketag ]; then if [ ! "$MAKETAG" = "" -a -r $PACKAGE_DIR/$MAKETAG ]; then # use alternate maketag sh $PACKAGE_DIR/$MAKETAG else sh $PACKAGE_DIR/maketag fi if [ -r $TMP/SeTnewtag ]; then mv $TMP/SeTnewtag $TMP/tagfile fi fi # # Protect tagfile from hacker attack: # if [ -r $TMP/tagfile ]; then chmod 600 $TMP/tagfile fi fi # ! "$DISK_SETS" = "disk" # It's possible that the tagfile was specified on the command line. If that's # the case, then we'll just override whatever we figured out up above. if [ ! "$USETAG" = "" ]; then cat $USETAG > $TMP/tagfile fi # If there's a catalog file present, use it to check for missing files. # If not, forget about that and install whatever's there. if [ "$1" = "single_disk" -o -r $PACKAGE_DIR/disk$1 -o -r $PACKAGE_DIR/package-list.txt ]; then if [ -r $PACKAGE_DIR/package-list.txt ]; then CATALOG_FILE=$PACKAGE_DIR/package-list.txt else CATALOG_FILE=`basename $PACKAGE_DIR/disk*`; fi if [ -r $PACKAGE_DIR/$CATALOG_FILE -a ! -d $PACKAGE_DIR/$CATALOG_FILE ]; then if grep CONTENTS: $PACKAGE_DIR/$CATALOG_FILE 1> /dev/null 2>&1 ; then # First we check for missing packages... for PKGTEST in `grep "^CONTENTS:" $PACKAGE_DIR/$CATALOG_FILE | cut -f2- -d : 2> /dev/null` ; do # This is not a perfect test. (say emacs is missing but emacs-nox is not) if ls $PACKAGE_DIR/$PKGTEST*.tgz 1> /dev/null 2> /dev/null ; then # found something like it true else cat << EOF > $TMP/tmpmsg WARNING!!! While looking through your index file ($CATALOG_FILE), I noticed that you might be missing a package: $PKGTEST-\*-\*-\*.tgz that is supposed to be on this disk (disk $1). You may go on with the installation if you wish, but if this is a crucial file I'm making no promises that your machine will boot. EOF dialog --title "FILE MISSING FROM YOUR DISK" --msgbox \ "`cat $TMP/tmpmsg`" 17 67 fi done # checking for missing packages # Now we test for extra packages: ALLOWED="`grep CONTENTS: $PACKAGE_DIR/$CATALOG_FILE | cut -b10- 2> /dev/null`" for PACKAGE_FILENAME in $PACKAGE_DIR/*.tgz; do BASE="`basename $PACKAGE_FILENAME .tgz`" BASE="`package_name $BASE`" if echo $ALLOWED | grep $BASE 1> /dev/null 2>&1 ; then true else cat << EOF > $TMP/tmpmsg WARNING!!! While looking through your index file ($CATALOG_FILE), I noticed that you have this extra package: ($BASE.tgz) that I don't recognize. Please be sure this package is really supposed to be here, and is not left over from an old version of Slackware. Sometimes this can happen at the archive sites. EOF dialog --title "EXTRA FILE FOUND ON YOUR DISK" \ --msgbox "`cat $TMP/tmpmsg`" 17 67 rm -f $TMP/tmpmsg fi done fi fi fi # check for missing/extra packages # Install the packages: for PACKAGE_FILENAME in $PACKAGE_DIR/*.tgz; do if [ "$PACKAGE_FILENAME" = "$PACKAGE_DIR/*.tgz" ]; then continue; fi if [ "$ASK" = "never" ]; then # install the package installpkg -root $TARGET_DIR -infobox -tagfile $TMP/tagfile $PACKAGE_FILENAME ERROR=$? elif [ "$ASK" = "tagfiles" ]; then installpkg -root $TARGET_DIR -menu -tagfile $TMP/tagfile $PACKAGE_FILENAME ERROR=$? else # ASK should be = always here, and that's how we'll treat it installpkg -root $TARGET_DIR -menu -ask -tagfile $TMP/tagfile $PACKAGE_FILENAME ERROR=$? fi # Check for abort: if [ "$ERROR" = "99" ]; then umount_the_source; chmod 755 $TARGET_DIR chmod 1777 $TARGET_DIR/tmp exit 1; fi done OUTTAHERE="false" if [ -r $PACKAGE_DIR/install.end ]; then OUTTAHERE="true" fi umount_the_source; if [ "$OUTTAHERE" = "true" ]; then return 1; fi } install_disk_set() { # accepts one argument: the series name in lowercase. SERIES_NAME=$1 CURRENT_DISK_NUMBER="1"; while [ 0 ]; do # Don't start numbering the directories until 2: if [ $CURRENT_DISK_NUMBER = 1 ]; then DISKTOINSTALL=$SERIES_NAME else DISKTOINSTALL=$SERIES_NAME$CURRENT_DISK_NUMBER fi install_disk $DISKTOINSTALL if [ ! $? = 0 ]; then # install.end was found, or the user chose # to quit installing packages. return 0; fi CURRENT_DISK_NUMBER=`expr $CURRENT_DISK_NUMBER + 1` done; } # /* main() */ if [ "$DISK_SETS" = "disk" ]; then install_disk single_disk; ASK="always" else touch $TMP/tagfile chmod 600 $TMP/tagfile if echo $DISK_SETS | grep "#a#" 1> /dev/null 2>&1; then A_IS_NEEDED="true" else A_IS_NEEDED="false" fi while [ 0 ]; do while [ 0 ]; # strip leading '#'s do if [ "`echo $DISK_SETS | cut -b1`" = "#" ]; then DISK_SETS="`echo $DISK_SETS | cut -b2-`" else break; fi done if [ "$A_IS_NEEDED" = "true" ]; then cat << EOF > $TMP/tmpmsg --- Installing package series ==>a<== EOF dialog --infobox "`cat $TMP/tmpmsg`" 5 45 sleep 1 rm -f $TMP/tmpmsg install_disk_set a; A_IS_NEEDED="false" fi count="1" if [ "`echo $DISK_SETS | cut -b$count`" = "" ]; then break; # we be done here :^) else count="2" while [ 0 ]; do if [ "`echo $DISK_SETS | cut -b$count`" = "" -o "`echo $DISK_SETS | cut -b$count`" = "#" ]; then count="`expr $count - 1`" break; else count="`expr $count + 1`" fi done fi diskset="`echo $DISK_SETS | cut -b1-$count`" count="`expr $count + 1`" DISK_SETS="`echo $DISK_SETS | cut -b$count-`" if [ "$diskset" = "a" ]; then continue; # we expect this to be done elsewhere fi cat << EOF > $TMP/tmpmsg Installing package series ==>$diskset<== EOF dialog --infobox "`cat $TMP/tmpmsg`" 5 45 sleep 1 rm -f $TMP/tmpmsg install_disk_set $diskset; done fi if [ "$DISK_SETS" = "disk" -o "$CMD_START" = "true" ]; then if [ -r $TMP/tagfile ]; then rm $TMP/tagfile fi dialog --clear fi chmod 755 $TARGET_DIR $TARGET_DIR/var $TARGET_DIR/usr chmod 1777 $TARGET_DIR/tmp installpkg 源码: #!/bin/sh # Copyright 1994, 1998, 2000 Patrick Volkerding, Concord, CA, USA # Copyright 2001 Slackware Linux, Inc., Concord, CA, USA # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Sun Nov 26 12:38:25 CST 1995 # Added patch from Glenn Moloney <glenn@physics.unimelb.edu.au> to allow # packages to be installed to directories other than /. # # Wed Mar 18 15:15:51 CST 1998 # Changed $TMP directory to /var/log/setup/tmp, and chmod'ed it 700 to close # some security holes. # If installpkg encounters a problem, it will return a non-zero error code. # If it finds more than one problem (i.e. with a list of packages) you'll only # hear about the most recent one. # 1 = tar returned error code # 2 = failed 'gzip -l package' # 3 = does not end in .tgz # 4 = not a file # 99 = user abort from menu mode EXITSTATUS=0 TAR=tar-1.13 $TAR --help 1> /dev/null 2> /dev/null if [ ! $? = 0 ]; then TAR=tar fi if [ ! "`LC_MESSAGES=C $TAR --version`" = "tar (GNU tar) 1.13 Copyright (C) 1988, 92,93,94,95,96,97,98, 1999 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by John Gilmore and Jay Fenlason." ]; then echo "WARNING: pkgtools are unstable with tar > 1.13." echo " You should provide a \"tar-1.13\" in your \$PATH." sleep 5 fi usage() { cat << EOF Usage: installpkg [options] package_name Installpkg is used to install a .tgz package like this: installpkg xf_bin.tgz options: -warn (warn if files will be overwritten, but do not install) -root /mnt (install someplace else, like /mnt) -infobox (use dialog to draw an info box) -menu (confirm package installation with a menu, unless the priority is [required] or ADD) -ask (used with menu mode: always ask if a package should be installed regardless of what the package's priority is) -priority ADD|REC|OPT|SKP (provide a priority for the entire package list to use instead of the priority in the tagfile) -tagfile /somedir/tagfile (specify a different file to use for package priorities. The default is "tagfile" in the package's directory) EOF } # Eliminate whitespace function: crunch() { while read FOO ; do echo $FOO done } package_name() { STRING=`basename $1 .tgz` # Check for old style package name with one segment: if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then echo $STRING else # has more than one dash delimited segment # Count number of segments: INDEX=1 while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do INDEX=`expr $INDEX + 1` done INDEX=`expr $INDEX - 1` # don't include the null value # If we don't have four segments, return the old-style (or out of spec) package name: if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then echo $STRING else # we have four or more segments, so we'll consider this a new-style name: NAME=`expr $INDEX - 3` NAME="`echo $STRING | cut -f 1-$NAME -d -`" echo $NAME # cruft for later #VER=`expr $INDEX - 2` #VER="`echo $STRING | cut -f $VER -d -`" #ARCH=`expr $INDEX - 1` #ARCH="`echo $STRING | cut -f $ARCH -d -`" #BUILD="`echo $STRING | cut -f $INDEX -d -`" fi fi } # Parse options: MODE=install # standard text-mode while [ 0 ]; do if [ "$1" = "-warn" ]; then MODE=warn shift 1 elif [ "$1" = "-infobox" ]; then MODE=infobox shift 1 elif [ "$1" = "-menu" ]; then MODE=menu shift 1 elif [ "$1" = "-ask" ]; then ALWAYSASK="yes" shift 1 elif [ "$1" = "-tagfile" ]; then if [ -r "$2" ]; then USERTAGFILE="$2" elif [ -r "`pwd`/$2" ]; then USERTAGFILE="`pwd`/$2" else usage exit fi shift 2 elif [ "$1" = "-priority" ]; then if [ "$2" = "" ]; then usage exit fi USERPRIORITY="$2" shift 2 elif [ "$1" = "-root" ]; then if [ "$2" = "" ]; then usage exit fi ROOT="$2" shift 2 else break fi done # Set the prefix for the package database directories (packages, scripts). ADM_DIR="$ROOT/var/log" # If the directories don't exist, "initialize" the package database: for PKGDBDIR in packages removed_packages removed_scripts scripts setup ; do if [ ! -d $ADM_DIR/$PKGDBDIR ]; then rm -rf $ADM_DIR/$PKGDBDIR # make sure it's not a symlink or something stupid mkdir -p $ADM_DIR/$PKGDBDIR chmod 755 $ADM_DIR/$PKGDBDIR fi done # Make sure there's a proper temp directory: TMP=$ADM_DIR/setup/tmp # If the $TMP directory doesn't exist, create it: if [ ! -d $TMP ]; then rm -rf $TMP # make sure it's not a symlink or something stupid mkdir -p $TMP chmod 700 $TMP # no need to leave it open fi # usage(), exit if called with no arguments: if [ $# = 0 ]; then usage; exit fi # If -warn mode was requested, produce the output and then exit: if [ "$MODE" = "warn" ]; then while [ -f "$1" ]; do echo "#### Scanning the contents of $1..." mkdir -p $TMP/scan$$ ( cd $TMP/scan$$ ; $TAR xzf - install ) < $1 2> /dev/null if [ -r $TMP/scan$$/install/doinst.sh ]; then if cat $TMP/scan$$/install/doinst.sh | grep ' rm -rf ' 1>/dev/null 2>/dev/null ; then cat $TMP/scan$$/install/doinst.sh | grep ' rm -rf ' > $TMP/scan$$/install/delete echo "The following locations will be completely WIPED OUT to allow symbolic" echo "links to be made. (We're talking 'rm -rf') These locations may be files," echo "or entire directories. Be sure you've backed up anything at these" echo "locations that you want to save before you install this package:" cat $TMP/scan$$/install/delete | cut -f 3,7 -d ' ' | tr ' ' '/' fi if [ -d $TMP/scan$$ ]; then ( cd $TMP/scan$$ ; rm -rf install ) 2> /dev/null ( cd $TMP ; rmdir scan$$ ) 2> /dev/null fi fi echo "The following files will be overwritten when installing this package." echo "Be sure they aren't important before you install this package:" ( $TAR tzvvf - ) < $1 | grep -v 'drwx' echo shift 1 done exit fi # Main loop: for package in $* ; do # If someone left off the .tgz, try to figure that out: if [ ! -r "$package" -a -r "$package.tgz" ]; then package=$package.tgz fi # "shortname" isn't really THAT short... it's just the full name without ".tgz" shortname="`basename $package .tgz`" packagedir="`dirname $package`" # This is the base package name, used for grepping tagfiles and descriptions: packagebase="`package_name $shortname`" # Reject package if it does not end in '.tgz': if [ ! -r "`dirname $package`/$shortname.tgz" ]; then EXITSTATUS=3 if [ "$MODE" = "install" ]; then echo "Cannot install $package: package does not end in .tgz" fi continue; fi # Determine package's priority: unset PRIORITY if [ "$USERPRIORITY" = "" ]; then if [ "$USERTAGFILE" = "" ]; then TAGFILE="`dirname $package`/tagfile" else TAGFILE="$USERTAGFILE" fi if [ ! -r "$TAGFILE" ]; then TAGFILE=/dev/null fi if grep "^$packagebase:" "$TAGFILE" | grep ADD > /dev/null 2> /dev/null ; then PRIORITY="ADD" elif grep "^$packagebase:" "$TAGFILE" | grep REC > /dev/null 2> /dev/null ; then PRIORITY="REC" elif grep "^$packagebase:" "$TAGFILE" | grep OPT > /dev/null 2> /dev/null ; then PRIORITY="OPT" elif grep "^$packagebase:" "$TAGFILE" | grep SKP > /dev/null 2> /dev/null ; then PRIORITY="SKP" fi else PRIORITY="$USERPRIORITY" fi if [ "$PRIORITY" = "ADD" ]; then #PMSG="Priority: [required]" PMSG="[required]" elif [ "$PRIORITY" = "REC" ]; then #PMSG="Priority: [recommended]" PMSG="[recommended]" elif [ "$PRIORITY" = "OPT" ]; then #PMSG="Priority: [optional]" PMSG="[optional]" elif [ "$PRIORITY" = "SKP" ]; then #PMSG="Priority: [skip]" PMSG="[skip]" else #PMSG="Priority: [unknown]" PMSG="" fi # Locate package description file: DESCRIPTION="/dev/null" # First check the usual locations outside the package, since this is faster: for file in $packagedir/disk* $packagedir/package_descriptions $packagedir/$shortname.txt $packagedir/$packagebase.txt ; do if grep "^$packagebase:" "$file" 1> /dev/null 2> /dev/null ; then DESCRIPTION="$file" elif grep "^$shortname:" "$file" 1> /dev/null 2> /dev/null ; then DESCRIPTION="$file" fi done # If we still don't have anything, look inside the package. This requires a costly untar. if [ "$DESCRIPTION" = "/dev/null" ]; then mkdir -p $TMP/scan$$ ( cd $TMP/scan$$ ; $TAR xzf - install ) < $package 2> /dev/null if grep "^$packagebase:" "$TMP/scan$$/install/slack-desc" 1> /dev/null 2> /dev/null ; then DESCRIPTION="$TMP/scan$$/install/slack-desc" elif grep "^$shortname:" "$TMP/scan$$/install/slack-desc" 1> /dev/null 2> /dev/null ; then DESCRIPTION="$TMP/scan$$/install/slack-desc" fi fi # Simple package integrity check: if [ ! -f $package ]; then EXITSTATUS=4 if [ "$MODE" = "install" ]; then echo "Cannot install $package: package is not a regular file" fi continue; fi gzip -l $package 1> /dev/null 2> /dev/null if [ ! "$?" = "0" ]; then EXITSTATUS=2 # failed gzip -l if [ "$MODE" = "install" ]; then echo "Cannot install $package: package is corrupt (failed 'gzip -l $package')" fi continue; fi # Collect the package information into a temp file: COMPRESSED=`gzip -l $package | grep -v uncompressed_name | crunch | cut -f 1 -d ' '` UNCOMPRESSED=`gzip -l $package | grep -v uncompressed_name | crunch | cut -f 2 -d ' '` COMPRESSED="`expr $COMPRESSED / 1024` K" UNCOMPRESSED="`expr $UNCOMPRESSED / 1024` K" # MD5SUM=`md5sum $package | cut -f 1 -d ' '` cat $DESCRIPTION | grep "^$packagebase:" | cut -f 2- -d : | cut -b2- 1> $TMP/tmpmsg$$ 2> /dev/null if [ "$shortname" != "$packagebase" ]; then cat $DESCRIPTION | grep "^$shortname:" | cut -f 2- -d : | cut -b2- 1>> $TMP/tmpmsg$$ 2> /dev/null fi # Adjust the length here. This allows a slack-desc to be any size up to 13 lines instead of fixed at 11. LENGTH=`cat $TMP/tmpmsg$$ | wc -l` while [ $LENGTH -lt 12 ]; do echo >> $TMP/tmpmsg$$ LENGTH=`expr $LENGTH + 1` done echo "Size: Compressed: $COMPRESSED, uncompressed: $UNCOMPRESSED." >> $TMP/tmpmsg$$ # For recent versions of dialog it is necessary to add \n to the end of each line # or it will remove repeating spaces and mess up our careful formatting: cat << EOF > $TMP/controlns$$ \n \n \n \n \n \n \n \n \n \n \n \n \n EOF paste -d "" $TMP/tmpmsg$$ $TMP/controlns$$ > $TMP/pasted$$ rm -f $TMP/controlns$$ mv $TMP/pasted$$ $TMP/tmpmsg$$ # Emit information to the console: if [ "$MODE" = "install" ]; then if [ "$PMSG" = "" ]; then echo "Installing package $shortname... " else echo "Installing package $shortname ($PMSG)... " fi echo "PACKAGE DESCRIPTION:" cat $DESCRIPTION | grep "^$packagebase:" | uniq if [ "$shortname" != "$packagebase" ]; then cat $DESCRIPTION | grep "^$shortname:" | uniq fi elif [ "$MODE" = "infobox" -a ! "$PRIORITY" = "SKP" ]; then # install non-SKP infobox package dialog --title "Installing package ==>$shortname<== $PMSG" --infobox "`cat $TMP/tmpmsg$$`" 0 0 elif [ "$MODE" = "menu" -a "$PRIORITY" = "ADD" -a ! "$ALWAYSASK" = "yes" ]; then # ADD overrides menu mode unless -ask was used dialog --title "Installing package ==>$shortname<== $PMSG" --infobox "`cat $TMP/tmpmsg$$`" 0 0 elif [ "$MODE" = "menu" -a "$PRIORITY" = "SKP" -a ! "$ALWAYSASK" = "yes" ]; then # SKP overrides menu mode unless -ask used rm -f $TMP/tmpmsg$$ continue # next package elif [ "$MODE" = "infobox" -a "$PRIORITY" = "SKP" -a ! "$ALWAYSASK" = "yes" ]; then # SKP overrides infobox mode, too rm -f $TMP/tmpmsg$$ continue else # we must need a full menu: dialog --title "Package Name: ==>$shortname<== $PMSG" --menu "`cat $TMP/tmpmsg$$`" 0 0 3 \ "Yes" "Install package $shortname" \ "No" "Do not install package $shortname" \ "Quit" "Abort software installation completely" 2> $TMP/reply$$ if [ ! $? = 0 ]; then echo "No" > $TMP/reply$$ fi REPLY="`cat $TMP/reply$$`" rm -f $TMP/reply$$ $TMP/tmpmsg$$ if [ "$REPLY" = "Quit" ]; then exit 99 # EXIT STATUS 99 = ABORT! elif [ "$REPLY" = "No" ]; then continue # skip the package fi fi # Test tarball integrity, and make sure we're not installing files on top of existing symbolic links: $TAR tzf $package 1> $TMP/tmplist$$ 2> /dev/null TARERROR=$? if [ ! "$TARERROR" = "0" ]; then EXITSTATUS=1 # tar file corrupt if [ "$MODE" = "install" ]; then echo "Unable to install $package: tar archive is corrupt (tar returned error code $TARERROR)" fi rm -f $TMP/tmplist$$ continue fi cat $TMP/tmplist$$ | grep -v "/$" | while read file ; do if [ -L "$ROOT/$file" ]; then rm -f "$ROOT/$file" fi done rm -f $TMP/tmplist$$ # Write the package file database entry and install the package: echo "PACKAGE NAME: $shortname" > $ADM_DIR/packages/$shortname echo "COMPRESSED PACKAGE SIZE: $COMPRESSED" >> $ADM_DIR/packages/$shortname echo "UNCOMPRESSED PACKAGE SIZE: $UNCOMPRESSED" >> $ADM_DIR/packages/$shortname echo "PACKAGE LOCATION: $package" >> $ADM_DIR/packages/$shortname # echo "PACKAGE MD5SUM: $MD5SUM" >> $ADM_DIR/packages/$shortname echo "PACKAGE DESCRIPTION:" >> $ADM_DIR/packages/$shortname cat $DESCRIPTION | grep "^$packagebase:" >> $ADM_DIR/packages/$shortname 2> /dev/null if [ "$shortname" != "$packagebase" ]; then cat $DESCRIPTION | grep "^$shortname:" >> $ADM_DIR/packages/$shortname 2> /dev/null fi echo "FILE LIST:" >> $ADM_DIR/packages/$shortname ( cd $ROOT/ ; $TAR -xzlUpvf - ) < $package >> $TMP/$shortname 2> /dev/null if [ "`cat $TMP/$shortname | grep '^./' | wc -l | tr -d ' '`" = "1" ]; then # Good. We have a package that meets the Slackware spec. cat $TMP/$shortname >> $ADM_DIR/packages/$shortname else # Some dumb bunny built a package with something other than makepkg. Bad! # Oh well. Bound to happen. Par for the course. Fix it and move on... echo './' >> $ADM_DIR/packages/$shortname cat $TMP/$shortname | grep -v '^./$' | cut -b3- >> $ADM_DIR/packages/$shortname fi rm -f $TMP/$shortname if [ -x /sbin/ldconfig ]; then /sbin/ldconfig fi if [ -f $ROOT/install/doinst.sh ]; then if [ "$MODE" = "install" ]; then echo "Executing install script for $shortname..." fi ( cd $ROOT/ ; sh install/doinst.sh -install; ) fi # Clean up the mess... if [ -d $ROOT/install ]; then if [ -r $ROOT/install/doinst.sh ]; then cp $ROOT/install/doinst.sh $ADM_DIR/scripts/$shortname chmod 755 $ADM_DIR/scripts/$shortname fi # /install/doinst.sh and /install/slack-* are reserved locations for the package system. ( cd $ROOT/install ; rm -f doinst.sh slack-* 1> /dev/null 2>&1 ) rmdir $ROOT/install 1> /dev/null 2>&1 fi # If we used a scan directory, get rid of it: if [ -d "$TMP/scan$$" ]; then rm -rf "$TMP/scan$$" fi rm -f $TMP/tmpmsg$$ $TMP/reply$$ if [ "$MODE" = "install" ]; then echo fi done exit $EXITSTATUS
  KornLee 当前离线   回复时引用此帖
发表新主题 回复


主题工具

发帖规则
您 [不可以] 发表新主题
您 [不可以] 回复主题
您 [不可以] 上传附件
您 [不可以] 编辑您的帖子

已 [启用] BB 代码
已 [启用] 表情符号
已 [启用] IMG 代码
已 [禁用] HTML 代码
[论坛跳转…]


所有时间均为[北京时间]。现在的时间是 12:22


Powered by vBulletin 版本 3.6.8
版权所有 ©2000 - 2012, Jelsoft Enterprises Ltd.
官方中文技术支持: vBulletin 中文
版权所有 ©2002 - 2011, LinuxSir.Org