add Qin Bo's operating shell scripts in

rename directory 'python' to 'interface', for I think it is a better name for its included python scripts function.
This commit is contained in:
lizhi-rocky
2010-09-03 15:59:49 +08:00
parent ed7054ed98
commit 220e6bfe40
23 changed files with 1898 additions and 0 deletions

20
operation/99finish_install.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
# run post_add scripts
#
pkg_dir=/var/lib/pkg
ls -rt ${pkg_dir}/*.post_add | while read pa_file
do
source ${pa_file}
rm ${pa_file}
done
rm $pkg_dir/*-serv.conf
#
#
# Destroy itself
#
rm -f $0

113
operation/configure_fstab.sh Executable file
View File

@@ -0,0 +1,113 @@
#!/bin/bash
#
# DESCRIPTION: configure fstab
# this script will modify $TARGT/etc/fstab,
# append the mountpoint to $TARGET/etc/fstab.
#
# SCRIPT NAME: configure_fstab.sh
#
# Usage: echo "/dev/hda2 /home ext3"|./configure_fstab.sh
#
# Input: stdin
# 1. partition
# 2. mountpoint
# 3. filesystem type
# below input is optional, if not set, we configure default,
# more about these argument read man fstab.
# 4. fs_mntops
# 5. fs_freq
# 6. fs_passno
#
# Output:
# 1 fstab doesn't exist
# 2 lack input (reserve)
# 3 device node doesn't exist
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-12
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-12 create
#
#
#
source ./functions
#
# if you redirect to /etc/fstab, don't print redundant to stdout in this function
#
configure_fstab ()
{
local devname="$1"
local mountpoint="$2"
local fs_type="$3"
local fs_mntops="$4"
local fs_freq="$5"
local fs_passno="$6"
if [ ! -e "$devname" ];then
err "$devname node doesn't exist !"
return 3
fi
# if partition is not swap, md, /, we use uuid instead device node
# / and swap partition use device node is decide by mkinitrd, this
# fstab will use by mkinitrd first ,if use UUID in fstab, mkinitrd will dead loop.
if [ "$mountpoint" != "/" -a "$(echo $devname | grep md)" = "" -a "$fs_type" != "swap" ];then
DEV_UUID=$(vol_id "$devname" | grep "ID_FS_UUID=" | cut -d "=" -f2)
devname="UUID=$DEV_UUID"
else
devname="$devname"
fi
# configure fstab options here
# fs_mntops, fs_freq, fs_passno has given, we use function argument,
# or we set default configuration, this default configuration according
# to old Rocky installer.
case $fs_type in
ext2|ext3|reiserfs)
[ -z "$fs_mntops" ] && fs_mntops="acl"
[ -z "$fs_freq" ] && fs_freq=1
[ -z "$fs_passno" ] && fs_passno=1 ;;
swap)
[ -z "$fs_mntops" ] && fs_mntops="defaults"
[ -z "$fs_freq" ] && fs_freq=0
[ -z "$fs_passno" ] && fs_passno=0 ;;
*)
[ -z "$fs_mntops" ] && fs_mntops="defaults"
[ -z "$fs_freq" ] && fs_freq=1
[ -z "$fs_passno" ] && fs_passno=1 ;;
esac
printf "%-60s %-10s %-10s %-25s %-1s %-1s\n" $devname $mountpoint $fs_type $fs_mntops $fs_freq $fs_passno
}
main ()
{
if [ -e "$TARGET/etc/fstab" ];then
sed -i '/^#devpts/ s/#//
/^#sysfs/ s/#//
/^#shm/ s/#shm /tmpfs/ ' "$TARGET/etc/fstab"
while read line;do
if [ -n "$line" ];then
configure_fstab $line >> "$TARGET/etc/fstab"
erv
fi
done
else
err "$TARGET/etc/fstab doesn't exist"
exit 1
fi
}
main $@

255
operation/configure_network.sh Executable file
View File

@@ -0,0 +1,255 @@
#!/bin/bash
#
# DESCRIPTION: configure network services
#
# SCRIPT NAME: configure_network.sh
#
# Input: argument
# [--help] show usage
# [-t|--type] \"manual\" or \"dynamic\"
# manual argument:
# [-h|--hostname] hostname
# [-d|--domainname] domainname
# [-i|--ip] ip address
# [-n|--netmask] netmask
# [-g|--gateway] gateway
# [-p|--pdns] priamaryDNS
# [-s|--sdns] secondaryDNS
# <-e|--device> network device. if no configure, default is eth0.
# dynamic argument:
# [-h|--hostname] hostname
# <-e|--device> network device. if no configure, default is eth0.
#
# Output:
# 1 argument error
# 2 ip/netmask/gateway address incorrect
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-23
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-23 create
#
#
#
source ./functions
usage ()
{
if [ "$1" == "-n" ];then
cmd="info"
ret=0
else
cmd="err"
ret=1
fi
$cmd "
This script will configure your network
Usage: $0 options:
options:
[--help] show this message
[-t|--type] \"manual\" or \"dynamic\"
manual argument:
[-h|--hostname] hostname
[-d|--domainname] domainname
[-i|--ip] ip address
[-n|--netmask] netmask
[-g|--gateway] gateway
[-p|--pdns] priamaryDNS
[-s|--sdns] secondaryDNS
<-e|--device> network device. if no configure, default is eth0.
dynamic argument:
[-h|--hostname] hostname
<-e|--device> network device. if no configure, default is eth0.
"
return $ret
}
check_ip ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error, it must be 1"
return 1;
fi
local ip=$1
local ret=2
# "=~" use for match regular expression, only use in bash 3.0 or higher
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# IFS is a separator for read builtin command, we save old IFS
OIFS=$IFS
IFS='.'
# set $ip to ip array
ip=($ip)
# restore IFS
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
ret=$?
fi
return $ret
}
parse_arg ()
{
tmp=$(getopt -o t:h:d:i:n:g:p:s:e:? --long type:,hostname:,ip:,netmask:,gateway:,pdns:,sdns:,device:,help -- "$@" 2>$dev_LOG)
if [ $? -ne 0 ];then
usage
return 1
fi
# set all argument to arg variable
eval set -- "$tmp"
while true ; do
case $1 in
-t|--type) type="$2" ;
info "network configure type: $type" ;
shift 2;;
-h|--hostname) hostname="$2";
info "hostname: $hostname" ;
shift 2 ;;
-d|--domainname) domainname="$2";
info "domainname: $domainname" ;
shift 2 ;;
-i|--ip) ip="$2";
info "ip: $ip" ;
shift 2 ;;
-n|--netmask) netmask="$2";
info "netmask: $netmask" ;
shift 2 ;;
-g|--gateway) gateway="$2";
info "gateway: $gateway" ;
shift 2 ;;
-p|--pdns) primaryDNS="$2";
info "primaryDNS: $primaryDNS" ;
shift 2 ;;
-s|--sdns) secondaryDNS="$2";
info "secondaryDNS: $secondaryDNS" ;
shift 2 ;;
# may be have mulit-network devices
-e|--device) device="$2";
info "device: $device" ;
shift 2 ;;
# shift the last "--", this dash is define by getopt (more information see man getopt)
--) shift ;break;;
--help) usage -n ;return 0;;
*) usage ;return 1;;
esac
done
if [ "$type" != "manual" -a "$type" != "dynamic" ];then
usage
return 1
fi
if [ -z "$hostname" ];then
err "you must specify hostname"
return 1
fi
# default device is eth0
if [ -z "$device" ];then
device="eth0"
fi
if [ "$type" == "manual" ];then
if [ -z "$ip" ];then
err "manual configure network, IP address can't be empty"
return 1
else
info "checking ip: $ip"
if ! check_ip "$ip"; then
return 2
fi
fi
if [ -z "$netmask" ];then
err "manual configure network, netmask address can't be empty"
return 1
else
info "checking netmask: $netmask"
if ! check_ip "$netmask"; then
return 2
fi
fi
if [ -z "$gateway" ];then
err "manual configure network, gateway address can't be empty"
return 1
else
info "checking gateway: $gateway"
if ! check_ip "$gateway"; then
return 2
fi
fi
fi
}
configure_network ()
{
if [ "$type" == "manual" ];then
# configure /etc/hosts
printf "%s %s.%s %s\n" $ip $hostname $domainname $hostname >>"$TARGET/etc/hosts"
# configure /etc/resolv.conf
printf "search %s\n" $domainname >>"$TARGET/etc/resolv.conf"
if [ -n "$primaryDNS" ];then
printf "nameserver %s\n" $primaryDNS >>"$TARGET/etc/resolv.conf"
fi
if [ -n "$secondaryDNS" ];then
printf "nameserver %s\n" $secondaryDNS >> "$TARGET/etc/resolv.conf"
fi
printf "domainname %s\n" $domainname >> "$TARGET/etc/resolv.conf"
# configure /etc/sysconfig/network-devices/ifcfg-eth0
broadcast=$(./ipcalc.pl -n $ip/$netmask| grep Broadcast|awk '{ print $2 }')
sed -i '/IPADDR/ c\IPADDR='$ip'
/NETMASK/ c\NETMASK='$netmask'
/DEVICE/ c\DEVICE='$device'
/GATEWAY/ c\GATEWAY='$gateway'
/BROADCAST/ c\BROADCAST='$broadcast'' "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0"
sed -i '/HOSTNAME/ c\HOSTNAME='$hostname'' "$TARGET/etc/sysconfig/network"
else [ "$type" == "dynamic" ]
printf "%s\n" $hostname >> "$TARGET/etc/hosts"
sed -i '/BOOTPROTO/ c\BOOTPROTO=dhcp
/DEVICE/ c\DEVICE='$device'
/SERVICE/ c\SERVICE=dhcpcd
/IPADDR/ c\IPADDR=
/NETMASK/ c\NETMASK=
/GATEWAY/ c\GATEWAY=
/BROADCAST/ c\BROADCAST=' "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0"
sed -i '/HOSTNAME/ c\HOSTNAME='$hostname'' "$TARGET/etc/sysconfig/network"
fi
if [ "$device" != "eth0" ];then
mv "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0" "$TARGET/etc/sysconfig/network-devices/ifcfg-$device"
fi
}
main ()
{
parse_arg $@
erv
configure_network
}
main $*

39
operation/copy_kernels.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
#
# DESCRIPTION: copying kernel and modules to system
#
# SCRIPT NAME: copy_kernel.sh
#
# Input: stdin
# 1.
# 2.
#
# Output:
# 1
# 2
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-23
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-23 create
#
#
#
source ./functions
main ()
{
cp -r /Rocky/kernels/* $TARGET/boot/ 2>$dev_LOG
cp -r /Rocky/modules/* $TARGET/lib/modules/ 2>$dev_LOG
cp /Rocky/initrd/initrd.gz $TARGET/boot/initrd.gz.old 2>$dev_LOG
./makeinitrd
}
main $@

View File

@@ -0,0 +1,83 @@
#!/bin/bash
#
# DESCRIPTION: chroot $TARGET excute script under /var/finish_install/.
# copy 99finish_install to /var/finish_install/, then one
# by one copy the script in /var/finish_install/ to $TARGET
# with sequence, and then chroot $TARGET to execte it.
#
# SCRIPT NAME: exec_finish_install.sh
#
# Input: stdin
# 1. script name which need run after installation
#
# Output:
# 1
# 2
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-27
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-27 create
#
#
#
source ./functions
prep ()
{
if [ ! -d $finish_install_dir ];then
mkdir -p $finish_install_dir
fi
for mp in /dev /proc /sys
do
mount --bind -n $mp "$TARGET$mp"
done
}
exec_script ()
{
src="$1"
src_name=$(basename $src)
cp $src "$TARGET/opt"
chroot $TARGET "/opt/$src_name" >$dev_LOG 2>&1 && rm -f "$TARGET/opt/$src_name"
}
main ()
{
prep
while read line ;do
if [ -n "$line" ];then
cp $line $finish_install_dir/
else
break
fi
done
# run all the script in /var/finish_install,
# execute sequence through number of script name
for script in "$finish_install_dir"/*; do
base=$(basename $script | sed 's/[0-9]*//')
if [ -x "$script" ];then
info "Running $base"
exec_script $script
erv
else
warn "Unable to execute $script"
fi
done
}
finish_install_dir="/var/finish_install"
main $@

106
operation/format_partition.sh Executable file
View File

@@ -0,0 +1,106 @@
#!/bin/bash
#
# DESCRIPTION: formating partition with a filesystem
# NOTICE: if have duplicate partition, it will format the final filesystem type.
#
# SCRIPT NAME: format_partition.sh
#
# Usage: echo "/dev/sda1 ext2" | ./format_partition.sh
#
# Input: stdin
# 1. partition
# 2. filesystem type
# 1,2 separate with space
#
# Output:
# 0 success
# 1 argument error
# 2 lack input (reserve)
# 3 deivce node doesn't exist
# 4 filesystem no implement
# 127 format partition utils not found
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-05
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-05 create
#
#
#
source ./functions
# ex: format_partition /dev/sda1 ext3
format_partition ()
{
if [ $# -ne 2 ];then
err "$FUNCNAME function argument error, it must be 2 !"
return 1
fi
devname="$1"
fs_type="$2"
if [ ! -e "$devname" ];then
err "$devname node doesn't exist !"
return 3
fi
# partition may be used to swap, or has already mounted
if grep -q "^$devname " /proc/swaps ;then
swapoff "$devname"
elif grep -q "^$devname " /proc/mounts;then
reumount $devname >"$dev_LOG" 2>&1
fi
info "formating device "$devname" as "$fs_type" filesystem"
case ${fs_type} in
ext2)
mkfs.ext2 -F "$devname" 1>"$dev_LOG" 2>&1
;;
ext3)
mkfs.ext3 -F "$devname" 1>"$dev_LOG" 2>&1
;;
reiserfs)
yes | mkfs.reiserfs -f "$devname" 1>"$dev_LOG" 2>&1
;;
xfs)
yes | mkfs.xfs -f "$devname" 1>"$dev_LOG" 2>&1
;;
jfs)
yes | mkfs.jfs -q "$devname" 1>"$dev_LOG" 2>&1
;;
swap)
mkswap -f "$devname" 1>"$dev_LOG" 2>&1
swapon "$devname"
;;
fat)
mkfs.vfat "$devname" 1>"$dev_LOG" 2>&1
;;
*)
err ""$fs_type" filesystem no implement yet !"
return 4
;;
esac
}
main ()
{
while read line;do
if [ -n "$line" ];then
# Notice: don't use "$line"
format_partition $line
erv
fi
done
}
main $@
# vim:set ts=4 sw=4;

147
operation/functions Normal file
View File

@@ -0,0 +1,147 @@
LOG_FILE="/var/log/install.log"
dev_LOG="/dev/tty6"
TARGET="/mnt"
TMP_DIR="/tmp"
# just for debug, also can use in run time
LOG="stdout"
#PKG_SOURCE_DIR="/Rocky/packages"
DATE=$(date "+%Y/%m/%d %T")
log ()
{
case "$LOG" in
true) printf "$DATE $*\n" >>"$LOG_FILE" ;;
stdout) printf "$DATE $*\n" ;;
*) : ;;
esac
}
err ()
{
log "error: $0: $*" >&2
}
warn ()
{
log "warning: $0: $*" >&2
}
info ()
{
log "info: $0: $*"
}
# erv stands for "Evaluate Return Value"
erv ()
{
ret="${?}"
if [ "$ret" -ne 0 ];then
exit $ret
fi
}
cleanup ()
{
rm -f $*
}
#
# check mountpoint whether is duplicate
#
check_duplicate_mountpoint ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
dup=$(awk '{print $2}' "$MOUNTPOINT_CONF" | sort | uniq -d)
if [ -n "$dup" ];then
err "mountpoint: \""$(echo $dup|tr " " "," )"\" is duplicate !"
return 4
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
#
# check partition whether is duplicate
#
check_duplicate_partition ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
dup=$(awk '{print $1}' "$MOUNTPOINT_CONF" | sort | uniq -d)
if [ -n "$dup" ];then
err "partition: \""$(echo $dup|tr " " "," )"\" is duplicate !"
return 5
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
#
# check root whether will mounted
#
check_root ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
if ! grep -q "[[:space:]]/[[:space:]]" $MOUNTPOINT_CONF;then
err "\"/\" partition can not be empty!"
return 6
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
#
# check /boot partition whether exist, if root partition is mounted by raid device
#
check_boot ()
{
if [ -s "$MOUNTPOINT_CONF" ];then
if grep " / " $MOUNTPOINT_CONF|grep -q "md" && ! grep -q " /boot " $MOUNTPOINT_CONF; then
err "boot parition mustn't mount alone, when root partition mount at raid devices !"
return 7
fi
return 0
else
err "$MOUNTPOINT_CONF file is empty or doesn't exist !"
return 8
fi
}
# recursively umount
# arg can is a device node or mountpoint
# ex: 1.reumount /dev/hda5
# 2.reumount /mnt/
reumount ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error, it must be 1 !"
return 1
fi
local arg="$1"
local mountpoint
# if arg is a device node
if [ ! -d "$arg" ];then
mountpoint=$(dirname `grep "^$arg " /proc/mounts|awk '{print $2}'`)
else
mountpoint="$arg"
fi
for mp in $(grep "$mountpoint" /proc/mounts|sort -k2 -r |awk '{print $2}');do
umount $mp 1>"$dev_LOG" 2>&1
done
}

106
operation/generate_issue.sh Executable file
View File

@@ -0,0 +1,106 @@
#!/bin/bash
#
# DESCRIPTION: generate system issue file
#
# SCRIPT NAME: generate_issue.sh
#
# Input: argument
# 1.version
# 2.arch
# 3.release
# 4.date
#
# Output:
# 1 argument error
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-13
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-13 create
#
#
#
source ./functions
usage ()
{
if [ "$1" == "-n" ];then
cmd="info"
ret=0
else
cmd="err"
ret=1
fi
$cmd "
This script will generate issue
Usage: $0 options
options:
[--help] show this message
[-v | --version] version of OS
[-a | --arch] architecture of OS
[-r | --release] release of OS
[-d | --date] date of generate OS
"
return $ret
}
generate_issue () {
local version="$1"
local arch="$2"
local release="$3"
local date="$4"
echo -e "\033[H\033[J"
echo "Welcome to Rocky OS ${version} ${arch} ${release} ($date) (\n) (\l)"
echo
echo
}
main()
{
tmp=$(getopt -o v:a:r:d: --long version:,arch:,release:,date:,help -- "$@" 2>$dev_LOG)
if [ "$?" -ne 0 ];then
usage
erv
fi
# set all argument to arg variable
eval set -- "$tmp"
while true ;do
case "$1" in
-v|--version) local version="$2"; shift 2 ;;
-a|--arch) local arch="$2"; shift 2 ;;
-r|--release) local release="$2"; shift 2 ;;
-d|--date) local date="$2"; shift 2 ;;
--help) usage -n; exit 0 ;;
# shift the last "--", this dash is define by getopt (more information see man getopt)
--) shift; break;;
*) usage; erv ;;
esac
done
if [ -z "$version" -a -z "$arch" -a -z "$release" -a -z "$date" ];then
usage
erv
fi
generate_issue "$version" "$arch" "$release" "$date" >"$TARGET/etc/issue"
}
main $@

175
operation/install_pkg.sh Executable file
View File

@@ -0,0 +1,175 @@
#!/bin/bash
#
# DESCRIPTION: install package
#
# SCRIPT NAME: install_pkg.sh
#
# Usage: echo "acl" |./install_pkg.sh -s /Rocky/packages
#
# Input: stdin
# 1. pkgname
# argument:
# [--help] show usage
# [-s|--source] Package source directory
#
# Output:
# 1 argument error
# 2 pkgname doesn't exist in source directory
#
# TODO:
# 1. need handle more case for install package (use pkgadd utils)
# 1). if package has already installed.
# 2). if devices near no spaces left.
#
# 2. add install package from below media:
# 1). install from network.
# (1). get packages.txt from mirror.
# (2). download package from mirror to hardisk /var/lib/pkg/cache,
# make sure cache is have enough spaces to store download package.
# Notice: download package, need convert package name of #->%23
# 2). install from nfs.
# (1). mount nfs directory as package source directory.
#
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-09
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-09 create
#
#
#
source ./functions
usage ()
{
if [ "$1" == "-n" ];then
cmd="info"
ret=0
else
cmd="err"
ret=1
fi
$cmd "
This script will install a package
Usage: $0 options
options:
[--help] Show this message
[-s | --source] Package source directory
(ex: echo make|install_pkg.sh -s /Rocky/packages)
"
return $ret
}
# get the package file in source directory
get_pkg_file ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error , it must be 1 !"
return 1
fi
local pkg_name="$1"
if [ -e "$PKG_SOURCE_DIR"/"$pkgname"'#'*tar.gz ]; then
ls "$PKG_SOURCE_DIR"/"$pkgname"'#'*tar.gz|head -n 1
else
err "package \"$pkgname\" doesn't exist in "$PKG_SOURCE_DIR" "
return 2
fi
}
add_pkg ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error , it must be 1 !"
return 1
fi
local pkg_src=$1
pkgadd -f -r $TARGET $pkg_src 1>$dev_LOG 2>&1
}
install_pkg ()
{
if [ $# -ne 1 ];then
err "$FUNCNAME function argument error , it must be 1 !"
return 1
fi
local pkgname="$1"
# create db for pkgutils
db_dir="/var/lib/pkg"
db="$TARGET$db_dir/db"
if [ ! -e "$db" ];then
info "create $TARGET$db_dir ..."
mkdir -p "$TARGET$db_dir"
touch "$db"
fi
local pkg_src=$(get_pkg_file $pkgname)
erv
info "install $pkgname to $TARGET"
add_pkg $pkg_src
erv
}
main ()
{
tmp=$(getopt -o s: --long source:,help -- "$@" 2>$dev_LOG)
if [ $? -ne 0 ];then
usage
erv
fi
# set all argument to arg variable
eval set -- "$tmp"
while true ;do
case "$1" in
-s|--source)
PKG_SOURCE_DIR="$2"
shift 2
;;
--help) usage -n; exit 0 ;;
# shift the last "--", this dash is define by getopt (more information see man getopt)
--) shift; break;;
*) usage; erv ;;
esac
done
if [ -z "$PKG_SOURCE_DIR" ];then
usage
erv
elif [ ! -e "$PKG_SOURCE_DIR" ];then
err "$PKG_SOURCE_DIR doen't exist !"
exit 1
fi
while read line ;do
echo "$line"
done | sort -u |
while read pkgname;do
if [ -n "$pkgname" ];then
install_pkg "$pkgname"
erv
fi
done
}
PKG_SOURCE_DIR=""
main "$@"

625
operation/ipcalc.pl Executable file
View File

@@ -0,0 +1,625 @@
#!/usr/bin/perl -w
# 2/2000 krischan at jodies.cx
#
# 0.14 Release
# 0.14.1 Allow netmasks given as dotted quads
# 0.15 Colorize Classbits, Mark new bits in network
# 0.16 25.9.2000 Accept <addr>/<cidr> as first argument
# Print <pre> tag in the script
# 0.17 Bugfix
# 0.18 Replace \n with <br> in HTML to make konqueror work. Argh.
# 0.19 HTML modified again to make Internet Exploder work. Argh ** 2
# Added -v Option
# 0.2 New Tabular Format. Idea by Kevin Ivory
# 0.21
# 0.22 Don't show -1 if netmask is 32 (Sven Anderson)
# 0.23 Removed broken prototyping. Thanks to Scott Davis sdavis(a)austin-texas.net
# 0.31 4/1/2001 Print cisco wildcard (inverse netmask).
# Idea by Denis Alan Hainsworth denis(a)ans.net
# 0.32 5/21/2001 - Accepts now inverse netmask as argument (Alan's idea again)
# Fixed missing trailing zeros in sub/supernets
# Warns now when given netmasks are illegal
# Added option to suppress the binary output
# Added help text
# 0.33 5/21/2001 Cosmetic
# 0.34 6/19/2001 Use default netmask of class when no netmask is given
# 0.35 12/2/2001 Fixed big-endian bug in subnets(). This was reported
# by Igor Zozulya and Steve Kent. Thank you for your help
# and access to your sparc machine!
use strict;
my $version = '0.35 12/2/2001';
my $private = "(Private Internet RFC 1918)";
my @privmin = qw (10.0.0.0 172.16.0.0 192.168.0.0);
my @privmax = qw (10.255.255.255 172.31.255.255 192.168.255.255);
my @class = qw (0 8 16 24 4 5 5);
my $allhosts;
my $mark_newbits = 0;
my $print_html = 0;
my $print_bits = 1;
my $print_only_class = 0;
my $qcolor = "\033[34m"; # dotted quads, blue
my $ncolor = "\033[m"; # normal, black
my $bcolor = "\033[33m"; # binary, yellow
my $mcolor = "\033[31m"; # netmask, red
my $ccolor = "\033[35m"; # classbits, magenta
my $dcolor = "\033[32m"; # subnet bits, green
my $break ="\n";
my $h; # Host address
foreach (@privmin) {
$_ = &bintoint(&dqtobin("$_"));
}
foreach (@privmax) {
$_ = &bintoint(&dqtobin("$_"));
}
if (! defined ($ARGV[0])) {
&usage;
exit();
}
if (defined ($ARGV[0]) && $ARGV[0] eq "-help") {
help();
}
if (defined ($ARGV[0]) && $ARGV[0] eq "-b") {
$ARGV[0] = "-n";
$print_bits = 0;
}
if (defined ($ARGV[0]) && $ARGV[0] eq "-v") {
print "$version\n";
exit 0;
}
if (defined ($ARGV[0]) && $ARGV[0] eq "-n") {
shift @ARGV;
$qcolor = '';
$ncolor = '';
$bcolor = '';
$mcolor = '';
$ccolor = '';
$dcolor = '';
}
if (defined ($ARGV[0]) && $ARGV[0] eq "-c") {
shift @ARGV;
$print_only_class = 1;
}
if (defined ($ARGV[0]) && $ARGV[0] eq "-h") {
shift @ARGV;
$print_html = 1;
$qcolor = '<font color="#0000ff">' ;
$ncolor = '<font color="#000000">';
$bcolor = '<font color="#909090">';
$mcolor = '<font color="#ff0000">';
$ccolor = '<font color="#009900">';
$dcolor = '<font color="#663366">';
$break = "<br>";
$private = "(<a href=\"http://www.ietf.org/rfc/rfc1918.txt\">Private Internet</a>)";
print "<pre>\n";
print "<!-- Version $version -->\n";
}
my $host = "192.168.0.1";
my $mask = '';
my $mask2 = '';
my @arg;
if ((defined $ARGV[0]) &&($ARGV[0] =~ /^(.+?)\/(.+)$/)) {
$arg[0] = $1;
$arg[1] = $2;
if (defined($ARGV[1])) {
$arg[2] = $ARGV[1];
}
} else {
@arg = @ARGV;
}
if (defined $arg[0]) {
$host = $arg[0];
}
if (! ($host = &is_valid_dq($host)) ) {
print "$mcolor Illegal value for ADDRESS ($arg[0])$ncolor\n";
}
if (defined $arg[1]) {
$mask = $arg[1];
if (! ($mask = is_valid_netmask($mask)) ) {
print "$mcolor Illegal value for NETMASK ($arg[1])$ncolor\n";
}
}
else
{
# if mask is not defined - take the default mask of the network class
$mask = $class[getclass(dqtobin($host))];
}
if ($print_only_class) {
print $class[getclass(dqtobin($host))];
exit 0;
}
if (defined ($arg[2])) {
$mask2 = $arg[2];
if (! ($mask2 = is_valid_netmask($mask2)) ) {
print "$mcolor Illegal value for second NETMASK ($arg[2])$ncolor\n";
}
} else {
$mask2 = $mask;
}
print "\n";
printline ("Address", $host , (&dqtobin($host),$mask,$bcolor,0) );
my $m = cidrtobin($mask);
#pack( "B*",("1" x $mask) . ("0" x (32 - $mask)) );
print_netmask($m,$mask);
print "=>\n";
$h = dqtobin($host);
my $n = $h & $m;
&printnet($n,$mask);
if ( $mask2 == $mask ) {
&end;
}
if ($mask2 > $mask) {
print "Subnets\n\n";
$mark_newbits = 1;
&subnets;
} else {
print "Supernet\n\n";
&supernet;
}
&end;
sub end {
if ($print_html) {
print "\n</pre>\n";
}
exit;
}
sub supernet {
$m = cidrtobin($mask2);
##pack( "B*",("1" x $mask2) . ("0" x (32 - $mask2)) );
$n = $h & $m;
print_netmask($m,$mask2);
print "\n";
printnet($n,$mask2);
}
sub subnetsREMOVED {
my $subnets = 0;
my @oldnet;
my $oldnet;
my $k;
my @nr;
my $nextnet;
my $l;
$m = cidrtobin($mask2);
##pack( "B*",("1" x $mask2) . ("0" x (32 - $mask2)) );
print_netmask($m,$mask2);
print "\n"; #*** ??
@oldnet = split //,unpack("B*",$n);
for ($k = 0 ; $k < $mask ; $k++) {
$oldnet .= $oldnet[$k];
}
for ($k = 0 ; $k < ( 2 ** ($mask2 - $mask)) ; $k++) {
@nr = split //,unpack("b*",pack("L",$k));
$nextnet = $oldnet;
for ($l = 0; $l < ($mask2 - $mask) ; $l++) {
$nextnet .= $nr[$mask2 - $mask - $l - 1] ;
}
$n = pack "B32",$nextnet;
&printnet($n,$mask2);
++$subnets;
if ($subnets >= 1000) {
print "... stopped at 1000 subnets ...$break";
last;
}
}
if ( ($subnets < 1000) && ($mask2 > $mask) ){
print "\nSubnets: $qcolor$subnets $ncolor$break";
print "Hosts: $qcolor" . ($allhosts * $subnets) . "$ncolor$break";
}
}
sub subnets
{
my $subnet=0;
$m = cidrtobin($mask2);
print_netmask($m,$mask2);
print "\n";
for ($subnet=0; $subnet < 2**($mask2 - $mask); $subnet++)
{
my $net = inttobin((bintoint($n) | ($subnet << (32-$mask2))));
printnet($net,$mask2);
if ($subnet >= 1000) {
print "... stopped at 1000 subnets ...$break";
return;
}
}
if ($mask2 > $mask) {
print "\nSubnets: $qcolor$subnet $ncolor$break";
print "Hosts: $qcolor" . ($allhosts * $subnet) . "$ncolor$break";
}
}
sub print_netmask {
my ($m,$mask2) = @_;
printline ("Netmask", &bintodq($m) . " = $mask2", ($m,$mask2,$mcolor,0) );
printline ("Wildcard", &bintodq(~$m) , (~$m,$mask2,$bcolor,0) );
}
sub getclass {
my $n = $_[0];
my $class = 1;
while (unpack("B$class",$n) !~ /0/) {
$class++;
if ($class > 5) {
last;
}
}
return $class;
}
sub printnet {
my ($n,$mask) = @_;
my $nm;
my $type;
my $hmin;
my $hmax;
my $hostn;
my $p;
my $i;
## $m = pack( "B*",("1" x $mask) . ("0" x (32 - $mask)) );
$nm = ~cidrtobin($mask);
##pack( "B*",("0" x $mask) . ("1" x (32 - $mask)) );
$b = $n | $nm;
#$type = 1;
#while (unpack("B$type",$n) !~ /0/) {
# $type++;
#}
#if ($type > 5) {
# $type = '';
#} else {
# $type = "Class " . chr($type+64);
#}
$type = getclass($n);
if ($type > 5 ) {
$type = "Undefined Class";
} else {
$type = "Class " . chr($type+64);
}
$hmin = pack("B*",("0"x31) . "1") | $n;
$hmax = pack("B*",("0"x $mask) . ("1" x (31 - $mask)) . "0" ) | $n;
$hostn = (2 ** (32 - $mask)) -2 ;
$hostn = 1 if $hostn == -1;
$p = 0;
for ($i=0; $i<3; $i++) {
if ( (&bintoint($hmax) <= $privmax[$i]) &&
(&bintoint($hmin) >= $privmin[$i]) ) {
$p = $i +1;
last;
}
}
if ($p) {
$p = $private;
} else {
$p = '';
}
printline ("Network", &bintodq($n) . "/$mask", ($n,$mask,$bcolor,1), " ($ccolor" . $type. "$ncolor)" );
printline ("Broadcast", &bintodq($b) , ($b,$mask,$bcolor,0) );
printline ("HostMin", &bintodq($hmin) , ($hmin,$mask,$bcolor,0) );
printline ("HostMax", &bintodq($hmax) , ($hmax,$mask,$bcolor,0) );
printf "Hosts/Net: $qcolor%-22s$ncolor",$hostn;
if ($p) {
print "$p";
}
print "$break$break\n";
$allhosts = $hostn;
}
sub printline {
my ($label,$dq,$mask,$mask2,$color,$mark_classbit,$class) = @_;
$class = "" unless $class;
printf "%-11s$qcolor","$label:";
printf "%-22s$ncolor", "$dq";
if ($print_bits)
{
print formatbin($mask,$mask2,$color,$mark_classbit);
if ($class) {
print $class;
}
}
print $break;
}
sub formatbin {
my ($bin,$actual_mask,$color,$mark_classbits) = @_;
my @dq;
my $dq;
my @dq2;
my $is_classbit = 1;
my $bit;
my $i;
my $j;
my $oldmask;
my $newmask;
if ($mask2 > $mask) {
$oldmask = $mask;
$newmask = $mask2;
} else {
$oldmask = $mask2;
$newmask = $mask;
}
@dq = split //,unpack("B*",$bin);
if ($mark_classbits) {
$dq = $ccolor;
} else {
$dq = $color;
}
for ($j = 0; $j < 4 ; $j++) {
for ($i = 0; $i < 8; $i++) {
if (! defined ($bit = $dq[$i+($j*8)]) ) {
$bit = '0';
}
if ( $mark_newbits &&((($j*8) + $i + 1) == ($oldmask + 1)) ) {
$dq .= "$dcolor";
}
$dq .= $bit;
if ( ($mark_classbits &&
$is_classbit && $bit == 0)) {
$dq .= $color;
$is_classbit = 0;
}
if ( (($j*8) + $i + 1) == $actual_mask ) {
$dq .= " ";
}
if ( $mark_newbits &&((($j*8) + $i + 1) == $newmask) ) {
$dq .= "$color";
}
}
push @dq2, $dq;
$dq = '';
}
return (join ".",@dq2) . $ncolor;
;
}
sub dqtobin {
my @dq;
my $q;
my $i;
my $bin;
foreach $q (split /\./,$_[0]) {
push @dq,$q;
}
for ($i = 0; $i < 4 ; $i++) {
if (! defined $dq[$i]) {
push @dq,0;
}
}
$bin = pack("CCCC",@dq); # 4 unsigned chars
return $bin;
}
sub bintodq {
my $dq = join ".",unpack("CCCC",$_[0]);
print
return $dq;
}
sub inttobin {
return pack("N",$_[0]);
}
sub bintoint {
return unpack("N",$_[0]);
}
sub is_valid_dq {
my $value = $_[0];
my $test = $value;
my $i;
my $corrected;
$test =~ s/\.//g;
if ($test !~ /^\d+$/) {
return 0;
}
my @value = split /\./, $value, 4;
for ($i = 0; $i<4; $i++) {
if (! defined ($value[$i]) ) {
$value[$i] = 0;
}
if ( ($value[$i] !~ /^\d+$/) ||
($value[$i] < 0) ||
($value[$i] > 255) )
{
return 0;
}
}
$corrected = join ".", @value;
return $corrected;
}
sub is_valid_netmask {
my $mask = $_[0];
if ($mask =~ /^\d+$/) {
if ( ($mask > 32) || ($mask < 1) ) {
return 0;
}
} else {
if (! ($mask = &is_valid_dq($mask)) ) {
return 0;
}
$mask = dqtocidr($mask);
}
return $mask;
}
sub cidrtobin {
my $cidr = $_[0];
pack( "B*",(1 x $cidr) . (0 x (32 - $cidr)) );
}
sub dqtocidr {
my $dq = $_[0];
$b = &dqtobin($dq);
my $cidr = 1;
my $firstbit = unpack("B1",$b) ^ 1;
while (unpack("B$cidr",$b) !~ /$firstbit/) {
$cidr++;
last if ($cidr == 33);
}
$cidr--;
#print "CIDR: $cidr\n";
#print "DQ: $dq\n";
my $m = cidrtobin($cidr);
#print "NM: " . bintodq($m) . "\n";
#print "NM2: " . bintodq(~$m) . "\n";
if (bintodq($m) ne $dq && bintodq(~$m) ne $dq) {
print "$mcolor Corrected illegal netmask: $dq" . "$ncolor\n";
}
return $cidr;
}
sub usage {
print << "EOF";
Usage: ipcalc [-n|-h|-v|-help] <ADDRESS>[[/]<NETMASK>] [NETMASK]
ipcalc takes an IP address and netmask and calculates the resulting broadcast,
network, Cisco wildcard mask, and host range. By giving a second netmask, you
can design sub- and supernetworks. It is also intended to be a teaching tool
and presents the results as easy-to-understand binary values.
-n Don't display ANSI color codes
-b Suppress the bitwise output
-c Just print bit-count-mask of given address
-h Display results as HTML
-help Longer help text
-v Print Version
Examples:
ipcalc 192.168.0.1/24
ipcalc 192.168.0.1/255.255.128.0
ipcalc 192.168.0.1 255.255.128.0 255.255.192.0
ipcalc 192.168.0.1 0.0.63.255
EOF
}
sub help {
print << "EOF";
IP Calculator $version
Enter your netmask(s) in CIDR notation (/25) or dotted decimals (255.255.255.0).
Inverse netmask are recognized. If you mmit the netmask, ipcalc uses the default
netmask for the class of your network.
Look at the space between the bits of the addresses: The bits before it are
the network part of the address, the bits after it are the host part. You can
see two simple facts: In a network address all host bits are zero, in a
broadcast address they are all set.
The class of your network is determined by its first bits.
If your network is a private internet according to RFC 1918 this is remarked.
When displaying subnets the new bits in the network part of the netmask are
marked in a different color.
The wildcard is the inverse netmask as used for access control lists in Cisco
routers. You can also enter netmasks in wildcard notation.
Do you want to split your network into subnets? Enter the address and netmask
of your original network and play with the second netmask until the result
matches your needs.
Questions? Comments? Drop me a mail...
krischan at jodies.de
http://jodies.de/ipcalc
Thanks for your nice ideas and help to make this tool more useful:
Hermann J. Beckers hj.beckers(a)kreis-steinfurt.de
Kevin Ivory ki(a)sernet.de
Frank Quotschalla gutschy(a)netzwerkinfo.de
Sven Anderson sven(a)anderson.de
Scott Davis sdavis(a)austin-texas.net
Denis A. Hainsworth denis(a)ans.net
Steve Kent stevek(a)onshore.com
Igor Zozulya izozulya(a)yahoo.com
EOF
usage();
exit;
}

4
operation/makeinitrd Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
modules=$(ls /Rocky/modules/|grep -v .bak|grep -v .old)
mkinitrd /mnt/boot/initrd.gz $modules --without-usb --without-multipath --fstab=/mnt/etc/fstab -f

129
operation/mk_serv_autoboot.sh Executable file
View File

@@ -0,0 +1,129 @@
#!/bin/bash
#
# DESCRIPTION: this script use for start system autoboot services.
# have to make a sysmbol link to script of autotboot services,
# and generate $pkgname-serv.conf, this configure file use by post_add.
#
# Usage: echo "netkit-base inetd rsh S310"|./mk_serv_autoboot.sh
#
# SCRIPT NAME: mk_serv_autoboot.sh
#
# Input: stdin
# 1. package name of autoboot services
# 2. boot script
# 3. boot service
# 4. boot number
#
# Output:
# 1 argument error
# 2 boot script doesn't exist
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-23
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-23 create
#
#
#
source ./functions
make_sysmbol_link ()
{
if [ $# -ne 2 ];then
err "$FUNCNAME function argument error, it must be 2 !"
return 1
fi
local script="$1"
local number="$2"
for dir in $rc_dir; do
pushd $dir >$dev_LOG &&
if [ -e $init_dir/$script ];then
if [ -L "$dir/$number$script" ];then
# may be the symbol link has already exist, skip it,
# mulit-services, may have common script to boot it.
# ex: rsh and rlogin service start through inetd script.
:
else
ln -sf ../init.d/$script ./$number$script
fi
else
err "$script doesn't exist in $init_dir"
return 2
fi
popd >$dev_LOG
done
}
# generate $pkgname-serv.conf, use by $pkgname.post_add
gen_serv_cnf ()
{
if [ $# -ne 2 ];then
err "$FUNCNAME function argument error, it must be 2 !"
return 1
fi
local pkgname="$1"
local service="$2"
# may be some boot services needn't configure also generate pkgname-serv.conf
# ex: at service, if it need autoboot, it also generate at-serv.conf,
# although it needn't configure
if [ -e "$serv_cfg_dir/$pkgname-serv.conf" ];then
# to avoid duplicate-line in $pkgname-serv.conf, we only append it when $service=yes
# not exist in $pkgname-serv.conf
if [ -z "$(grep "$service=yes" "$serv_cfg_dir/$pkgname-serv.conf")" ];then
printf "%s=yes\n" $service >> "$serv_cfg_dir"/"$pkgname-serv.conf"
fi
else
printf "%s=yes\n" $service > "$serv_cfg_dir"/"$pkgname-serv.conf"
fi
}
mk_serv_autoboot ()
{
local pkgname="$1"
local script="$2"
local service="$3"
local number="$4"
make_sysmbol_link "$script" "$number"
erv
gen_serv_cnf "$pkgname" "$service"
erv
}
main ()
{
while read line;do
if [ -n "$line" ];then
mk_serv_autoboot $line
erv
fi
done
}
rcd="$TARGET/etc/rc.d"
init_dir="$rcd/init.d"
# according old Rocky installer, make symbol link in rc3.d and rc5.d
rc_dir="$rcd/rc3.d $rcd/rc5.d"
serv_cfg_dir="$TARGET/var/lib/pkg"
main $@

96
operation/mount_partition.sh Executable file
View File

@@ -0,0 +1,96 @@
#!/bin/bash
#
# DESCRIPTION: mounting all partitions which from stdin
#
# SCRIPT NAME: mount_partition.sh
#
# Usage: echo "/dev/sda1 / ext3" |./mount_partition.sh
#
# Notice: don't expect mount swap partition : )
#
# Input: stdin
# 1. partition
# 2. mountpoint
# 3. filesystem type
# below input is optional, if not set, we mount default configure,
# 4. fs_mntops: set mount options
# Output:
# 1 argument error
# 2 lack input (reserve)
# 3 device node doesn't exist
# 32 mount failure
#
# AUTHOR: Qin Bo
#
# EMAIL: bqin@linx-info.com
#
# DATE: 2010-08-06
#
# HISTORY:
# REVISOR DATE MODIFICATION
# Qin Bo 2010-08-06 create
#
#
#
source ./functions
mount_partition ()
{
local devname="$1"
local mountpoint="$2"
local fs_type="$3"
local fs_mntops="$4"
if [ ! -e "$devname" ];then
err "$devname node doesn't exist !"
return 3
fi
if [ "$mountpoint" == "/" ];then
mount_pos="$TARGET"
else
mount_pos="$TARGET$mountpoint"
fi
# mount filesystem for default option
# after install will set acl, so we use acl option mount here
# this configure according old Rocky installer
case $fs_type in
ext2|ext3|reiserfs)
[ -z "$fs_mntops" ] && fs_mntops="acl" ;;
*)
[ -z "$fs_mntops" ] && fs_mntops="defaults" ;;
esac
if [ ! -d "$mount_pos" ];then
info "create directory $mount_pos ..."
mkdir -p "$mount_pos"
fi
# mountpoint has already mounted, umount it
if mountpoint -q $mount_pos;then
# may be have mountpoint under the mountpoint directory
reumount $mount_pos
fi
info "mount $devname on $mount_pos with $fs_type filesystem"
mount -t "$fs_type" -o $fs_mntops "$devname" "$mount_pos" 1>"$dev_LOG" 2>&1
}
main()
{
while read line; do
echo $line
done|sort -k 2 -u|
while read line; do
if [ -n "$line" ];then
mount_partition $line
erv
fi
done
}
main "$@"