update opteration
install.txt from install_0.4.txt
This commit is contained in:
218
operation/configure_bootloader_cnf.sh
Executable file
218
operation/configure_bootloader_cnf.sh
Executable file
@@ -0,0 +1,218 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# DESCRIPTION: configure configuration file of bootloader
|
||||
#
|
||||
# SCRIPT NAME: configure_bootloader_cnf.sh
|
||||
#
|
||||
# Input:
|
||||
# argument:
|
||||
# [-r|--root] partition mount by root
|
||||
# <-b|--boot> partition mount by boot (optional,if the boot is not mount by stand alone)
|
||||
# [-k|--kparameter] kernel parameter
|
||||
# [-o|--osversion] OS version
|
||||
#
|
||||
# Output:
|
||||
# NULL
|
||||
# Return value:
|
||||
# 1 argument error
|
||||
# 2 bootloader type doesn't specify
|
||||
# 3 bootloader no implement
|
||||
# 4 bootloader configuration file doesn't exist
|
||||
#
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
#
|
||||
# EMAIL: bqin@linx-info.com
|
||||
#
|
||||
# DATE: 2010-09-07
|
||||
#
|
||||
# HISTORY:
|
||||
# REVISOR DATE MODIFICATION
|
||||
# Qin Bo 2010-09-07 create
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
source ./functions
|
||||
|
||||
usage ()
|
||||
{
|
||||
if [ "$1" == "-n" ];then
|
||||
cmd="info"
|
||||
ret=0
|
||||
else
|
||||
cmd="err"
|
||||
ret=1
|
||||
fi
|
||||
$cmd "
|
||||
This script will install boot loader for system
|
||||
|
||||
Usage: $0 options
|
||||
|
||||
options:
|
||||
[--help] show this message
|
||||
[-t|--type ] boot loader type:grub,etc.
|
||||
[-r|--root] partition mount by root
|
||||
<-b|--boot> partition mount by boot (optional,if the boot is not mount by stand alone)
|
||||
[-k|--kparameter] kernel parameter
|
||||
[-o|--osversion] OS version
|
||||
"
|
||||
return $ret
|
||||
}
|
||||
|
||||
configure_grub_cnf ()
|
||||
{
|
||||
|
||||
local root_hd
|
||||
local part_num
|
||||
local root
|
||||
local hd_dev
|
||||
local devname
|
||||
local root_dev
|
||||
|
||||
if [ ! -e "$GRUBCNF" ];then
|
||||
err "$GRUBCNF doesn't exist"
|
||||
return 4
|
||||
fi
|
||||
|
||||
# get the boot directory in which hard disk
|
||||
if [ -n "$BOOT_PARTITION" ];then
|
||||
root_hd=$(echo "$BOOT_PARTITION"|sed 's/[0-9]//g')
|
||||
part_num=${BOOT_PARTITION##*[a-z]}
|
||||
let $((part_num-=1))
|
||||
else
|
||||
root_hd=$(echo "$ROOT_PARTITION"|sed 's/[0-9]//g')
|
||||
part_num=${ROOT_PARTITION##*[a-z]}
|
||||
let $((part_num-=1))
|
||||
fi
|
||||
|
||||
if [ ! -e "$DEVICEMAP" ];then
|
||||
warn "$DEVICEMAP doesn't exist, creat it"
|
||||
# generate device.map
|
||||
grub --batch --no-floppy --device-map="$DEVICEMAP" << EOF 1>>"$DEV_LOG" 2>&1
|
||||
quit
|
||||
EOF
|
||||
fi
|
||||
|
||||
hd_dev=$(grep "$root_hd" "$DEVICEMAP" | awk '{print $1}' | sed 's/(//' | sed 's/)//') #e.g. hd_dev=hd0
|
||||
info "hd_dev: $hd_dev part_num: $part_num"
|
||||
root="($hd_dev,$part_num)"
|
||||
info "root: $root"
|
||||
|
||||
# use UUID in menu.lst except md,
|
||||
# because when I use UUID of raid device in menu.lst,
|
||||
# initrd can't switch root .
|
||||
devname=$(basename $ROOT_PARTITION)
|
||||
if [[ "$devname" =~ ^md[0-9]*$ ]];then
|
||||
root_dev="$ROOT_PARTITION"
|
||||
else
|
||||
by_uuid=$(get_disk_sym $devname "by-uuid")
|
||||
if [ -n "$by_uuid" ];then
|
||||
root_dev="UUID=$(echo $by_uuid|sed 's/.*\///')"
|
||||
else
|
||||
root_dev="$ROOT_PARTITION"
|
||||
fi
|
||||
fi
|
||||
info "root_dev: $root_dev"
|
||||
|
||||
# modify grub.conf.sample from here
|
||||
# modify root
|
||||
sed "/^splashimage / s/(hd0,0)/$root/
|
||||
/^kernel / s/(hd0,0)/$root/" "$GRUBCNF" >"$GRUBMENU"
|
||||
|
||||
# modify boot directory
|
||||
# boot directory mount stand alone
|
||||
if [ -n "$BOOT_PARTITION" ];then
|
||||
sed -i "/^kernel / s@/boot@@
|
||||
/^initrd / s@/boot@@" "$GRUBMENU"
|
||||
fi
|
||||
|
||||
# modify OS version
|
||||
sed -i "/^title / s/Secure System/Secure Operating System Version $OSVERSION/" "$GRUBMENU"
|
||||
# modify root partition
|
||||
sed -i "/^kernel / s@root=/dev/hda1@root=$root_dev@" "$GRUBMENU"
|
||||
# append kernel parameter
|
||||
sed -i "s/^kernel .*$/& $KPARAMETER/g" $GRUBMENU
|
||||
}
|
||||
|
||||
main ()
|
||||
{
|
||||
if [ $# -eq 0 ];then
|
||||
usage; erv
|
||||
fi
|
||||
|
||||
tmp=$(getopt -o t:r:b:k:o: --long type:,root:,boot:,kparameter:,osversion:,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
|
||||
-t|--type) TYPE="$2"
|
||||
info "bootloader type: $TYPE"
|
||||
shift 2
|
||||
;;
|
||||
-r|--root) ROOT_PARTITION="$2"
|
||||
info "root partition: $ROOT_PARTITION"
|
||||
shift 2
|
||||
;;
|
||||
-b|--boot) BOOT_PARTITION="$2"
|
||||
info "boot partition: $BOOT_PARTITION"
|
||||
shift 2
|
||||
;;
|
||||
-k|--kparameter) KPARAMETER="$2"
|
||||
info "kernel parameter: $KPARAMETER"
|
||||
shift 2
|
||||
;;
|
||||
-o|--osversion) OSVERSION="$2"
|
||||
info "version of opterating system: $OSVERSION"
|
||||
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 [ -n "$TYPE" ];then
|
||||
case "$TYPE" in
|
||||
grub)
|
||||
if [ -z "$ROOT_PARTITION" ]; then
|
||||
err "configure grub configuration file root partition can't be empty"
|
||||
exit 1
|
||||
fi
|
||||
configure_grub_cnf
|
||||
erv
|
||||
;;
|
||||
*)
|
||||
err "$TYPE bootloader no implement yet !"
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
else
|
||||
err "bootloader type doesn't specify"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
TYPE=""
|
||||
ROOT_PARTITION=""
|
||||
BOOT_PARTITION=""
|
||||
KPARAMETER=""
|
||||
OSVERSION=""
|
||||
GRUB_DIR="$TARGET/boot/grub"
|
||||
GRUBMENU="$GRUB_DIR/menu.lst"
|
||||
GRUBCNF="$GRUB_DIR/grub.conf.sample"
|
||||
DEVICEMAP="$GRUB_DIR/device.map"
|
||||
|
||||
# The quotes around '$@' are essential!
|
||||
# in this way we can accept whitespace as parameter.
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# DESCRIPTION: configure fstab
|
||||
# this script will modify $TARGT/etc/fstab,
|
||||
# append the mountpoint to $TARGET/etc/fstab.
|
||||
# mountpoint, swap use by-id, other device use by-uuid.
|
||||
# if can't get by-id or by-uuid use device name.
|
||||
#
|
||||
# SCRIPT NAME: configure_fstab.sh
|
||||
#
|
||||
@@ -19,9 +21,9 @@
|
||||
# 6. fs_passno
|
||||
#
|
||||
# Output:
|
||||
# NULL
|
||||
# Returne value:
|
||||
# 1 fstab doesn't exist
|
||||
# 2 lack input (reserve)
|
||||
# 3 device node doesn't exist
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
#
|
||||
@@ -38,32 +40,39 @@
|
||||
|
||||
source ./functions
|
||||
|
||||
#
|
||||
# if you redirect to /etc/fstab, don't print redundant to stdout in this function
|
||||
#
|
||||
configure_fstab ()
|
||||
{
|
||||
local devname="$1"
|
||||
local device="$1"
|
||||
local mountpoint="$2"
|
||||
local fs_type="$3"
|
||||
|
||||
local fs_mntops="$4"
|
||||
local fs_freq="$5"
|
||||
local fs_passno="$6"
|
||||
# store uuid of by-id
|
||||
local devname=""
|
||||
|
||||
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"
|
||||
# in Rocky4.2 udev-117: udevinfo couldn't get by-id of raid,
|
||||
# also couldn't get by-uuid of swap, raid and swap can't unification ,
|
||||
# so get device's uuid expect swap, only get device's by-id for swap.
|
||||
# if partition not exist, or couldn't get partition information
|
||||
# set $devname as default
|
||||
|
||||
partition=$(echo $device|sed 's/.*\///')
|
||||
if [ "$mountpoint" == "swap" -a "$fs_type" == "swap" ];then
|
||||
by_id=$(get_disk_sym $partition "by-id")
|
||||
if [ -n "$by_id" ];then
|
||||
devname="/dev/$by_id"
|
||||
else
|
||||
devname="$device"
|
||||
fi
|
||||
else
|
||||
devname="$devname"
|
||||
by_uuid=$(get_disk_sym $partition "by-uuid")
|
||||
if [ -n "$by_uuid" ];then
|
||||
devname="UUID=$(echo $by_uuid|sed 's/.*\///')"
|
||||
else
|
||||
devname="$device"
|
||||
fi
|
||||
fi
|
||||
|
||||
# configure fstab options here
|
||||
@@ -85,29 +94,34 @@ configure_fstab ()
|
||||
[ -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
|
||||
info "$devname $mountpoint $fs_type $fs_mntops $fs_freq $fs_passno"
|
||||
printf "%-60s %-10s %-10s %-25s %-1s %-1s\n" $devname $mountpoint $fs_type $fs_mntops $fs_freq $fs_passno >>"$TARGET/etc/fstab"
|
||||
|
||||
}
|
||||
|
||||
|
||||
main ()
|
||||
{
|
||||
local line
|
||||
|
||||
if [ -e "$TARGET/etc/fstab" ];then
|
||||
sed -i '/^#devpts/ s/#//
|
||||
/^#sysfs/ s/#//
|
||||
/^#shm/ s/#shm /tmpfs/ ' "$TARGET/etc/fstab"
|
||||
|
||||
info "configure fstab"
|
||||
while read line;do
|
||||
if [ -n "$line" ];then
|
||||
configure_fstab $line >> "$TARGET/etc/fstab"
|
||||
configure_fstab $line
|
||||
erv
|
||||
fi
|
||||
done
|
||||
info "configure fstab success"
|
||||
else
|
||||
err "$TARGET/etc/fstab doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -6,23 +6,26 @@
|
||||
#
|
||||
# Input: argument
|
||||
# [--help] show usage
|
||||
# [-t|--type] \"manual\" or \"dynamic\"
|
||||
# manual argument:
|
||||
# [-t|--type] "static" or "dynamic"
|
||||
# static argument:
|
||||
# [-h|--hostname] hostname
|
||||
# [-d|--domainname] domainname
|
||||
# [-i|--ip] ip address
|
||||
# [-n|--netmask] netmask
|
||||
# [-g|--gateway] gateway
|
||||
# [-p|--pdns] priamaryDNS
|
||||
# [-s|--sdns] secondaryDNS
|
||||
# <-d|--domainname> domainname
|
||||
# <-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:
|
||||
# NULL
|
||||
# Return value:
|
||||
# 1 argument error
|
||||
# 2 ip/netmask/gateway address incorrect
|
||||
# 3 hosts/resolv.conf/ifcfg-eth0/network doesn't exist
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
#
|
||||
@@ -56,15 +59,15 @@ Usage: $0 options:
|
||||
|
||||
options:
|
||||
[--help] show this message
|
||||
[-t|--type] \"manual\" or \"dynamic\"
|
||||
manual argument:
|
||||
[-t|--type] \"static\" or \"dynamic\"
|
||||
static argument:
|
||||
[-h|--hostname] hostname
|
||||
[-d|--domainname] domainname
|
||||
[-i|--ip] ip address
|
||||
[-n|--netmask] netmask
|
||||
[-g|--gateway] gateway
|
||||
[-p|--pdns] priamaryDNS
|
||||
[-s|--sdns] secondaryDNS
|
||||
<-d|--domainname> domainname
|
||||
<-p|--pdns> priamaryDNS
|
||||
<-s|--sdns> secondaryDNS
|
||||
<-e|--device> network device. if no configure, default is eth0.
|
||||
dynamic argument:
|
||||
[-h|--hostname] hostname
|
||||
@@ -88,24 +91,29 @@ check_ip ()
|
||||
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='.'
|
||||
OIFS=$IFS
|
||||
IFS='.'
|
||||
# set $ip to ip array
|
||||
ip=($ip)
|
||||
ip=($ip)
|
||||
# restore IFS
|
||||
IFS=$OIFS
|
||||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||||
ret=$?
|
||||
fi
|
||||
IFS=$OIFS
|
||||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||||
ret=$?
|
||||
fi
|
||||
|
||||
return $ret
|
||||
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 [ $# -eq 0 ];then
|
||||
usage
|
||||
return 1
|
||||
fi
|
||||
|
||||
tmp=$(getopt -o t:h:d:i:n:g:p:s:e:? --long type:,hostname:,domainname:,ip:,netmask:,gateway:,pdns:,sdns:,device:,help -- "$@" 2>>$DEV_LOG)
|
||||
if [ $? -ne 0 ];then
|
||||
usage
|
||||
return 1
|
||||
@@ -116,23 +124,23 @@ parse_arg ()
|
||||
|
||||
while true ; do
|
||||
case $1 in
|
||||
-t|--type) type="$2" ;
|
||||
info "network configure type: $type" ;
|
||||
-t|--type) TYPE="$2" ;
|
||||
info "network configure type: $TYPE" ;
|
||||
shift 2;;
|
||||
-h|--hostname) hostname="$2";
|
||||
info "hostname: $hostname" ;
|
||||
-h|--hostname) HOSTNAME="$2";
|
||||
info "hostname: $HOSTNAME" ;
|
||||
shift 2 ;;
|
||||
-d|--domainname) domainname="$2";
|
||||
info "domainname: $domainname" ;
|
||||
-d|--domainname) DOMAINNAME="$2";
|
||||
info "domainname: $DOMAINNAME" ;
|
||||
shift 2 ;;
|
||||
-i|--ip) ip="$2";
|
||||
info "ip: $ip" ;
|
||||
-i|--ip) IP="$2";
|
||||
info "ip: $IP" ;
|
||||
shift 2 ;;
|
||||
-n|--netmask) netmask="$2";
|
||||
info "netmask: $netmask" ;
|
||||
-n|--netmask) NETMASK="$2";
|
||||
info "netmask: $NETMASK" ;
|
||||
shift 2 ;;
|
||||
-g|--gateway) gateway="$2";
|
||||
info "gateway: $gateway" ;
|
||||
-g|--gateway) GATEWAY="$2";
|
||||
info "gateway: $GATEWAY" ;
|
||||
shift 2 ;;
|
||||
-p|--pdns) primaryDNS="$2";
|
||||
info "primaryDNS: $primaryDNS" ;
|
||||
@@ -141,8 +149,8 @@ parse_arg ()
|
||||
info "secondaryDNS: $secondaryDNS" ;
|
||||
shift 2 ;;
|
||||
# may be have mulit-network devices
|
||||
-e|--device) device="$2";
|
||||
info "device: $device" ;
|
||||
-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;;
|
||||
@@ -151,47 +159,54 @@ parse_arg ()
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
if [ "$type" != "manual" -a "$type" != "dynamic" ];then
|
||||
usage
|
||||
if [ "$TYPE" != "static" -a "$TYPE" != "dynamic" ];then
|
||||
err "configure network must be static or dynamic"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$hostname" ];then
|
||||
err "you must specify hostname"
|
||||
if [ -z "$HOSTNAME" ];then
|
||||
err "HOSTNAME can't be empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# default device is eth0
|
||||
if [ -z "$device" ];then
|
||||
device="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"
|
||||
if [ "$TYPE" == "static" ];then
|
||||
if [ -z "$DOMAINNAME" ];then
|
||||
err "static configure network, DOMAINNAME can't be empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$IP" ];then
|
||||
err "static configure network, IP address can't be empty"
|
||||
return 1
|
||||
else
|
||||
info "checking ip: $ip"
|
||||
if ! check_ip "$ip"; then
|
||||
info "checking ip: $IP"
|
||||
if ! check_ip "$IP"; then
|
||||
err "ip: $IP incorrect"
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
if [ -z "$netmask" ];then
|
||||
err "manual configure network, netmask address can't be empty"
|
||||
if [ -z "$NETMASK" ];then
|
||||
err "static configure network, netmask address can't be empty"
|
||||
return 1
|
||||
else
|
||||
info "checking netmask: $netmask"
|
||||
if ! check_ip "$netmask"; then
|
||||
info "checking netmask: $NETMASK"
|
||||
if ! check_ip "$NETMASK"; then
|
||||
err "netmask: $NETMASK incorrect"
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
if [ -z "$gateway" ];then
|
||||
err "manual configure network, gateway address can't be empty"
|
||||
if [ -z "$GATEWAY" ];then
|
||||
err "static configure network, gateway address can't be empty"
|
||||
return 1
|
||||
else
|
||||
info "checking gateway: $gateway"
|
||||
if ! check_ip "$gateway"; then
|
||||
info "checking gateway: $GATEWAY"
|
||||
if ! check_ip "$GATEWAY"; then
|
||||
err "gateway: $GATEWAY incorrect"
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
@@ -201,55 +216,111 @@ parse_arg ()
|
||||
|
||||
configure_network ()
|
||||
{
|
||||
if [ "$type" == "manual" ];then
|
||||
if [ "$TYPE" == "static" ];then
|
||||
# configure /etc/hosts
|
||||
printf "%s %s.%s %s\n" $ip $hostname $domainname $hostname >>"$TARGET/etc/hosts"
|
||||
if [ -e "$TARGET/etc/hosts" ];then
|
||||
sed -i "s/^#<ip-address>/$IP/
|
||||
s/<HOSTNAME.domain.org>/$HOSTNAME\.$DOMAINNAME/
|
||||
s/<HOSTNAME>/$HOSTNAME/" "$TARGET/etc/hosts"
|
||||
else
|
||||
err "$TARGET/etc/hosts doesn't exist"
|
||||
return 3
|
||||
fi
|
||||
|
||||
# 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"
|
||||
if [ -e "$TARGET/etc/resolv.conf" ];then
|
||||
sed -i "s/^#search <domain.org>$/search $DOMAINNAME/
|
||||
s/^#domain <domain.org>$/domain $DOMAINNAME/" "$TARGET/etc/resolv.conf"
|
||||
if [ -n "$primaryDNS" ];then
|
||||
sed -i "s/^#nameserver <ip-address>$/nameserver $primaryDNS/" "$TARGET/etc/resolv.conf"
|
||||
fi
|
||||
if [ -n "$secondaryDNS" ];then
|
||||
sed -i "/nameserver/a\nameserver $secondaryDNS" "$TARGET/etc/resolv.conf"
|
||||
fi
|
||||
else
|
||||
err "$TARGET/etc/resolv.conf doesn't exist"
|
||||
return 3
|
||||
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"
|
||||
if [ -e "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0" ];then
|
||||
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"
|
||||
else
|
||||
err "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0 doesn't exist"
|
||||
return 3
|
||||
fi
|
||||
|
||||
sed -i '/HOSTNAME/ c\HOSTNAME='$hostname'' "$TARGET/etc/sysconfig/network"
|
||||
|
||||
else [ "$type" == "dynamic" ]
|
||||
printf "%s\n" $hostname >> "$TARGET/etc/hosts"
|
||||
# configure /etc/sysconfig/network
|
||||
if [ -e "$TARGET/etc/sysconfig/network" ];then
|
||||
sed -i '/HOSTNAME/ c\HOSTNAME='$HOSTNAME'' "$TARGET/etc/sysconfig/network"
|
||||
printf "DOMAIN=%s\n" "$DOMAINNAME" >>"$TARGET/etc/sysconfig/network"
|
||||
else
|
||||
err "$TARGET/etc/sysconfig/network doesn't exist"
|
||||
return 3
|
||||
fi
|
||||
else [ "$TYPE" == "dynamic" ]
|
||||
# configure /etc/hosts
|
||||
if [ -e "$TARGET/etc/hosts" ];then
|
||||
printf "%s\n" $HOSTNAME >> "$TARGET/etc/hosts"
|
||||
else
|
||||
err "$TARGET/etc/hosts doesn't exist"
|
||||
return 3
|
||||
fi
|
||||
|
||||
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"
|
||||
# configure /etc/sysconfig/network-devices/ifcfg-eth0
|
||||
if [ -e "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0" ];then
|
||||
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"
|
||||
else
|
||||
err "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0 doesn't exist"
|
||||
return 3
|
||||
fi
|
||||
|
||||
sed -i '/HOSTNAME/ c\HOSTNAME='$hostname'' "$TARGET/etc/sysconfig/network"
|
||||
# configure /etc/sysconfig/network
|
||||
if [ -e "$TARGET/etc/sysconfig/network" ];then
|
||||
sed -i '/HOSTNAME/ c\HOSTNAME='$HOSTNAME'' "$TARGET/etc/sysconfig/network"
|
||||
else
|
||||
err "$TARGET/etc/sysconfig/network doesn't exist"
|
||||
return 3
|
||||
fi
|
||||
fi
|
||||
if [ "$device" != "eth0" ];then
|
||||
mv "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0" "$TARGET/etc/sysconfig/network-devices/ifcfg-$device"
|
||||
if [ "$DEVICE" != "eth0" ];then
|
||||
mv "$TARGET/etc/sysconfig/network-devices/ifcfg-eth0" "$TARGET/etc/sysconfig/network-devices/ifcfg-$DEVICE"
|
||||
fi
|
||||
}
|
||||
|
||||
main ()
|
||||
{
|
||||
parse_arg $@
|
||||
info "configure network"
|
||||
parse_arg "$@"
|
||||
erv
|
||||
configure_network
|
||||
erv
|
||||
info "configure network success"
|
||||
}
|
||||
|
||||
main $*
|
||||
TYPE=""
|
||||
HOSTNAME=""
|
||||
DOMAINNAME=""
|
||||
IP=""
|
||||
NETMASK=""
|
||||
GATEWAY=""
|
||||
primaryDNS=""
|
||||
secondaryDNS=""
|
||||
DEVICE=""
|
||||
|
||||
# The quotes around '$@' are essential!
|
||||
# in this way we can accept whitespace as parameter.
|
||||
main "$@"
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
# 2.
|
||||
#
|
||||
# Output:
|
||||
# 1
|
||||
# 2
|
||||
# NULL
|
||||
# Return value:
|
||||
# 1 kernel directory/modules directory/initrd.gz/makeinitrd doesn't exist
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
#
|
||||
@@ -29,11 +30,42 @@ 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
|
||||
info "copy $KERNELS/* to $TARGET/boot/"
|
||||
if [ -d "$KERNELS" ];then
|
||||
cp -r "$KERNELS"/* "$TARGET/boot/" 2>>$DEV_LOG
|
||||
else
|
||||
err "$KERNELS directory doesn't exist "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
./makeinitrd
|
||||
info "copy $MODULES/* to $TARGET/lib/modules/"
|
||||
if [ -d "$MODULES" ];then
|
||||
cp -r "$MODULES"/* "$TARGET/lib/modules/" 2>>$DEV_LOG
|
||||
else
|
||||
err "$MODULES directory doesn't exist "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
info "copy $INITRD/initrd.gz to $TARGET/boot/initrd.gz.old"
|
||||
if [ -e "$INITRD/initrd.gz" ];then
|
||||
cp "$INITRD/initrd.gz" "$TARGET/boot/initrd.gz.old" 2>>$DEV_LOG
|
||||
else
|
||||
err "$INITRD/initrd.gz doesn't exist "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
info "runing makeinitrd"
|
||||
if [ -e ./makeinitrd ];then
|
||||
./makeinitrd 2>>$DEV_LOG
|
||||
else
|
||||
err "makeinitrd doesn't exist "
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main $@
|
||||
KERNELS="/Rocky/kernels"
|
||||
MODULES="/Rocky/modules"
|
||||
INITRD="/Rocky/initrd"
|
||||
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
# 1. script name which need run after installation
|
||||
#
|
||||
# Output:
|
||||
# 1
|
||||
# 2
|
||||
# NULL
|
||||
# Return value:
|
||||
# dependency return value of execute script, if 0 is success.
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
#
|
||||
@@ -31,8 +32,10 @@ source ./functions
|
||||
|
||||
prep ()
|
||||
{
|
||||
if [ ! -d $finish_install_dir ];then
|
||||
mkdir -p $finish_install_dir
|
||||
local mp
|
||||
|
||||
if [ ! -d $FINISH_INSTALL_DIR ];then
|
||||
mkdir -p $FINISH_INSTALL_DIR
|
||||
fi
|
||||
|
||||
for mp in /dev /proc /sys
|
||||
@@ -41,23 +44,31 @@ prep ()
|
||||
done
|
||||
}
|
||||
|
||||
# copy the script to $TARGET/opt, and chroot execute it
|
||||
exec_script ()
|
||||
{
|
||||
local src
|
||||
local src_name
|
||||
|
||||
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"
|
||||
chroot $TARGET "/opt/$src_name" >>$DEV_LOG 2>&1 && rm -f "$TARGET/opt/$src_name"
|
||||
}
|
||||
|
||||
|
||||
|
||||
main ()
|
||||
{
|
||||
local line
|
||||
local base
|
||||
local script
|
||||
|
||||
prep
|
||||
|
||||
while read line ;do
|
||||
if [ -n "$line" ];then
|
||||
cp $line $finish_install_dir/
|
||||
cp $line $FINISH_INSTALL_DIR/
|
||||
else
|
||||
break
|
||||
fi
|
||||
@@ -65,7 +76,7 @@ main ()
|
||||
|
||||
# run all the script in /var/finish_install,
|
||||
# execute sequence through number of script name
|
||||
for script in "$finish_install_dir"/*; do
|
||||
for script in "$FINISH_INSTALL_DIR"/*; do
|
||||
base=$(basename $script | sed 's/[0-9]*//')
|
||||
if [ -x "$script" ];then
|
||||
info "Running $base"
|
||||
@@ -75,9 +86,12 @@ main ()
|
||||
warn "Unable to execute $script"
|
||||
fi
|
||||
done
|
||||
info "Running finish install success"
|
||||
[ ! -c "$LOG_FILE" ] && cp $LOG_FILE "$TARGET/var/log"
|
||||
[ ! -c "$DEV_LOG" ] && cp $DEV_LOG "$TARGET/var/log"
|
||||
}
|
||||
|
||||
finish_install_dir="/var/finish_install"
|
||||
FINISH_INSTALL_DIR="/var/finish_install"
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# DESCRIPTION: formating partition with a filesystem
|
||||
# NOTICE: if have duplicate partition, it will format the final filesystem type.
|
||||
# if have duplicate partition, it will format the finally filesystem type.
|
||||
#
|
||||
# SCRIPT NAME: format_partition.sh
|
||||
#
|
||||
@@ -10,14 +10,14 @@
|
||||
# Input: stdin
|
||||
# 1. partition
|
||||
# 2. filesystem type
|
||||
# 1,2 separate with space
|
||||
#
|
||||
# Output:
|
||||
# 0 success
|
||||
# success:
|
||||
# @ format $devname success
|
||||
# Return value:
|
||||
# 1 argument error
|
||||
# 2 lack input (reserve)
|
||||
# 3 deivce node doesn't exist
|
||||
# 4 filesystem no implement
|
||||
# 2 deivce node doesn't exist
|
||||
# 3 filesystem no implement
|
||||
# 127 format partition utils not found
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
@@ -43,64 +43,68 @@ format_partition ()
|
||||
return 1
|
||||
fi
|
||||
|
||||
devname="$1"
|
||||
fs_type="$2"
|
||||
local devname="$1"
|
||||
local fs_type="$2"
|
||||
|
||||
if [ ! -e "$devname" ];then
|
||||
err "$devname node doesn't exist !"
|
||||
return 3
|
||||
return 2
|
||||
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
|
||||
reumount $devname 1>>"$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
|
||||
mkfs.ext2 -F "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
;;
|
||||
ext3)
|
||||
mkfs.ext3 -F "$devname" 1>"$dev_LOG" 2>&1
|
||||
mkfs.ext3 -F "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
;;
|
||||
reiserfs)
|
||||
yes | mkfs.reiserfs -f "$devname" 1>"$dev_LOG" 2>&1
|
||||
yes | mkfs.reiserfs -f "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
;;
|
||||
xfs)
|
||||
yes | mkfs.xfs -f "$devname" 1>"$dev_LOG" 2>&1
|
||||
yes | mkfs.xfs -f "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
;;
|
||||
jfs)
|
||||
yes | mkfs.jfs -q "$devname" 1>"$dev_LOG" 2>&1
|
||||
yes | mkfs.jfs -q "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
;;
|
||||
swap)
|
||||
mkswap -f "$devname" 1>"$dev_LOG" 2>&1
|
||||
mkswap -f "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
swapon "$devname"
|
||||
;;
|
||||
fat)
|
||||
mkfs.vfat "$devname" 1>"$dev_LOG" 2>&1
|
||||
mkfs.vfat "$devname" 1>>"$DEV_LOG" 2>&1
|
||||
;;
|
||||
*)
|
||||
err ""$fs_type" filesystem no implement yet !"
|
||||
return 4
|
||||
return 3
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main ()
|
||||
{
|
||||
local line
|
||||
|
||||
while read line;do
|
||||
if [ -n "$line" ];then
|
||||
# Notice: don't use "$line"
|
||||
format_partition $line
|
||||
erv
|
||||
info "format $(echo $line|awk '{print $1}') success" stdout
|
||||
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
# vim:set ts=4 sw=4;
|
||||
|
||||
|
||||
@@ -1,37 +1,59 @@
|
||||
LOG_FILE="/var/log/install.log"
|
||||
dev_LOG="/dev/tty6"
|
||||
TARGET="/mnt"
|
||||
TMP_DIR="/tmp"
|
||||
# LOG_FILE, LOG, DEV_LOG, TARGET is global variable,
|
||||
# they can export from environment variable,
|
||||
# if not definition, will configure default value.
|
||||
|
||||
# just for debug, also can use in run time
|
||||
LOG="stdout"
|
||||
#PKG_SOURCE_DIR="/Rocky/packages"
|
||||
# installation log file
|
||||
[ -z "$LOG_FILE" ] && LOG_FILE="/var/log/install.log"
|
||||
|
||||
# LOG have two value, true and stdout
|
||||
# true: log will record to $LOG_FILE
|
||||
# stdout: log will print to stand out, very usefull for debug
|
||||
[ -z "$LOG" ] && LOG="true"
|
||||
|
||||
# the log of command operation
|
||||
# ex: stdout of command: mkfs.ext3 /dev/hda2
|
||||
[ -z "$DEV_LOG" ] && DEV_LOG="/dev/tty8"
|
||||
|
||||
# the root directory of hardisk mount
|
||||
[ -z "$TARGET" ] && TARGET="/mnt"
|
||||
|
||||
|
||||
DATE=$(date "+%Y/%m/%d %T")
|
||||
mkdir -p $(dirname $LOG_FILE)
|
||||
mkdir -p $(dirname $DEV_LOG)
|
||||
mkdir -p "$TARGET"
|
||||
|
||||
stdout ()
|
||||
{
|
||||
printf "$*\n"
|
||||
}
|
||||
|
||||
log ()
|
||||
{
|
||||
local DATE=$(date "+%Y/%m/%d %T")
|
||||
|
||||
case "$LOG" in
|
||||
true) printf "$DATE $*\n" >>"$LOG_FILE" ;;
|
||||
stdout) printf "$DATE $*\n" ;;
|
||||
stdout) stdout "$DATE $*" ;;
|
||||
*) : ;;
|
||||
esac
|
||||
}
|
||||
|
||||
err ()
|
||||
{
|
||||
log "error: $0: $*" >&2
|
||||
log "error: $(basename $0): $*" >&2
|
||||
}
|
||||
|
||||
warn ()
|
||||
{
|
||||
log "warning: $0: $*" >&2
|
||||
log "warning: $(basename $0): $*" >&2
|
||||
}
|
||||
|
||||
info ()
|
||||
{
|
||||
log "info: $0: $*"
|
||||
log "info: $(basename $0): $1"
|
||||
if [ "$2" == "stdout" ];then
|
||||
stdout "@ $1"
|
||||
fi
|
||||
}
|
||||
|
||||
# erv stands for "Evaluate Return Value"
|
||||
@@ -43,86 +65,10 @@ erv ()
|
||||
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
|
||||
# recursively umount directory,
|
||||
# argument can be a device node or mountpoint.
|
||||
# if argument is a device node can umount a device which mounted multi-directory,
|
||||
# if argument is a mountpoint can't umount a device recursively, only recursively directory.
|
||||
# ex: 1.reumount /dev/hda5
|
||||
# 2.reumount /mnt/
|
||||
reumount ()
|
||||
@@ -132,16 +78,70 @@ reumount ()
|
||||
return 1
|
||||
fi
|
||||
|
||||
local arg="$1"
|
||||
local arg
|
||||
arg="$1"
|
||||
local mountpoint
|
||||
|
||||
# if arg is a device node
|
||||
if [ ! -d "$arg" ];then
|
||||
mountpoint=$(dirname `grep "^$arg " /proc/mounts|awk '{print $2}'`)
|
||||
mountpoint=$(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
|
||||
|
||||
# delete last "/" in mountpoint
|
||||
# mountpoint in /proc/mounts don't have "/" at last
|
||||
multi_mountpoint=$(echo $mountpoint|sed "s%/$%%")
|
||||
|
||||
# may be a device has been mounted in multi-mountpoint.
|
||||
# ex: /dev/hda5 mount at /mnt and /cdrom at the same time,
|
||||
# this case appear when $TARGET has been changed, when mount paritions.
|
||||
for mmp in $multi_mountpoint; do
|
||||
# sort -k2 -r ensure long mountpoint sort at front of short mountpoint,
|
||||
# so, we can umount long mountpoint before short mountpoint.
|
||||
# ex: /usr/lib, /, /usr, after sort is /usr/lib, /usr, /
|
||||
# this mean that /usr/lib is umounted first, then umount /usr, finally umount /
|
||||
for mp in $(grep "$mmp" /proc/mounts|sort -k2 -r |awk '{print $2}');do
|
||||
umount $mp 1>>"$DEV_LOG" 2>&1
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
update_udev()
|
||||
{
|
||||
killall udevd
|
||||
start_udev
|
||||
}
|
||||
|
||||
#
|
||||
# get device uuid/by-id/by-path info
|
||||
# if not found return NULL
|
||||
# ex: get_disk_sym sda1 by-uuid
|
||||
#
|
||||
get_disk_sym ()
|
||||
{
|
||||
if [ $# -ne 2 ];then
|
||||
err "$FUNCNAME function argument error, it must be 2 !"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local partition="$1"
|
||||
local type="$2"
|
||||
local devname=""
|
||||
|
||||
# we find partition in /sys/block/,
|
||||
# "*" in oder to c0d0p1 match cciss!c0d0p1
|
||||
local path=$(find /sys/block/ -maxdepth 2 -name *$partition)
|
||||
|
||||
# scsci's by-id may be have multi-links, we get first link
|
||||
if [ -n "$path" -a -d "$path" ];then
|
||||
# update hard disk informations.
|
||||
# if not update udev, uuid or by-id may use old one.
|
||||
update_udev
|
||||
devname=$(udevinfo -q symlink -p $path|tr " " "\n"|grep "$type"|head -n 1)
|
||||
fi
|
||||
echo "$devname"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
# SCRIPT NAME: generate_issue.sh
|
||||
#
|
||||
# Input: argument
|
||||
# 1.version
|
||||
# 2.arch
|
||||
# 3.release
|
||||
# 4.date
|
||||
# [--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
|
||||
#
|
||||
# Output:
|
||||
# 1 argument error
|
||||
@@ -44,10 +45,10 @@ 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
|
||||
[-v|--version] version of OS
|
||||
[-a|--arch] architecture of OS
|
||||
[-r|--release] release of OS
|
||||
[-d|--date] date of generate OS
|
||||
|
||||
"
|
||||
return $ret
|
||||
@@ -69,8 +70,13 @@ generate_issue () {
|
||||
|
||||
main()
|
||||
{
|
||||
local tmp
|
||||
|
||||
if [ $# -eq 0 ];then
|
||||
usage;erv
|
||||
fi
|
||||
|
||||
tmp=$(getopt -o v:a:r:d: --long version:,arch:,release:,date:,help -- "$@" 2>$dev_LOG)
|
||||
tmp=$(getopt -o v:a:r:d: --long version:,arch:,release:,date:,help -- "$@" 2>>$DEV_LOG)
|
||||
if [ "$?" -ne 0 ];then
|
||||
usage
|
||||
erv
|
||||
@@ -92,15 +98,13 @@ main()
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$version" -a -z "$arch" -a -z "$release" -a -z "$date" ];then
|
||||
usage
|
||||
erv
|
||||
fi
|
||||
|
||||
info "generate issue"
|
||||
generate_issue "$version" "$arch" "$release" "$date" >"$TARGET/etc/issue"
|
||||
erv
|
||||
info "generate issue sucess"
|
||||
|
||||
}
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@ format_partition.sh
|
||||
1)partition:分区
|
||||
2)filesystem:文件系统类型
|
||||
输出:
|
||||
$?
|
||||
success:
|
||||
@ format $devname success
|
||||
返回值:
|
||||
1 argument error
|
||||
2 lack input (保留不用)
|
||||
3 deivce node doesn't exist
|
||||
4 filesystem no implement
|
||||
2 deivce node doesn't exist
|
||||
3 filesystem no implement
|
||||
127 format partition utils not found
|
||||
Usage:
|
||||
单个处理: echo "/dev/sda1 ext2" | ./format_partition.sh
|
||||
@@ -27,10 +28,10 @@ mount_partition.sh
|
||||
4)filsystem options:文件系统选项
|
||||
(这个为可选参数,不传这个参数会有默认的选项:文件系统是ext2|ext3|reiserfs,会以acl的选项挂载,其他则为defaults)
|
||||
输出:
|
||||
$?
|
||||
1 argument error
|
||||
2 lack input (保留不用)
|
||||
3 device node doesn't exist
|
||||
success:
|
||||
@ mount $devname success
|
||||
返回值:
|
||||
1 device node doesn't exist
|
||||
32 mount failure
|
||||
Usage:
|
||||
单个处理:echo "/dev/sda1 / ext3" |./mount_partition.sh
|
||||
@@ -43,37 +44,44 @@ Usage:
|
||||
1. pkgname
|
||||
argument:
|
||||
[--help] show usage
|
||||
[-s|--source] Package source directory
|
||||
输出:
|
||||
$?
|
||||
<-s|--source> package source directory, if not specify, default is /Rocky/packages.
|
||||
输出: sucess:
|
||||
@ install $pkgname success.
|
||||
返回值:
|
||||
1 argument error
|
||||
2 package in source doesn't exist
|
||||
2 source directory $PKG_SOURCE_DIR doesn't exist
|
||||
3 pkgname doesn't exist in source directory
|
||||
|
||||
Usage:
|
||||
单个处理:echo "acl" |./install_pkg.sh -s /Rocky/packages
|
||||
批量处理:文件格式和单个处理一致
|
||||
说明:
|
||||
由安装程序生成/var/lib/pkg/db的空文件。
|
||||
1.由安装程序生成/var/lib/pkg/db的空文件;
|
||||
2.默认用/Rocky/packages下面的软件包,如果不指定-s参数。
|
||||
|
||||
4.配置、生成系统文件:
|
||||
|
||||
配置fstab,configure_fstab.sh
|
||||
输入:
|
||||
stdin
|
||||
1)block devices:块设备
|
||||
1)block devices:块设备,(swap则用by-id,其他都用by-uuid)
|
||||
2)mount point:挂载点
|
||||
3)filesystem type:文件系统类型
|
||||
以下参数为可选参数,如果不指定,会有默认的配置
|
||||
以下参数为可选参数,如果不指定,会有默认的配置,如果指定5)那么4)也需要指定,依次类推
|
||||
4)fs_mntops: ext2|ext3|reiserfs的默认配置是acl,其他都是defaults。
|
||||
5)fs_freq:默认配置:swap是0,其他都是1
|
||||
6)fs_passno:默认配置:swap是0,其他都是1
|
||||
输出:
|
||||
无
|
||||
返回值:
|
||||
1 fstab doesn't exist
|
||||
2 lack input (保留不用)
|
||||
3 device node doesn't exist
|
||||
Usage:
|
||||
单个处理:echo "/dev/hda2 /home ext3"|./configure_fstab.sh
|
||||
批量处理:文件格式和单个处理一致
|
||||
说明:
|
||||
需要处理swap
|
||||
1.需要处理swap;
|
||||
2.块设备:如果是swap则转成by-id,其他都转成by-uuid,
|
||||
这个是因为udev-117的udevinfo不能查出查出raid的by-id,也不能查出swap的uuid。
|
||||
|
||||
生成issue文件
|
||||
generate_issue.sh
|
||||
@@ -85,19 +93,19 @@ generate_issue.sh
|
||||
[-r|--release] release of OS(base or security)
|
||||
[-d|--date] date of generate OS
|
||||
输出:
|
||||
$?
|
||||
无
|
||||
返回值:
|
||||
1 argument error
|
||||
说明:
|
||||
1.生成$TARGET/etc/issue文件,一般TARGET=/mnt;
|
||||
2.不给参数也不给warning,如果只给定了一个参数,那么必须把所有参数补全。
|
||||
|
||||
1.生成$TARGET/etc/issue文件,一般TARGET=/mnt;
|
||||
2.可以只给一个参数,但是这样其他参数则为空值。
|
||||
|
||||
配置网络:
|
||||
configure_network.sh
|
||||
输入:
|
||||
argument:
|
||||
[-t|--type] \"manual\" or \"dynamic\"
|
||||
manual argument:
|
||||
[-t|--type] "static" or "dynamic"
|
||||
static argument:
|
||||
[-h|--hostname] hostname
|
||||
|
||||
[-i|--ip] ip address
|
||||
@@ -111,20 +119,18 @@ configure_network.sh
|
||||
[-h|--hostname] hostname
|
||||
<-e|--device> network device. if no configure, default is eth0.
|
||||
输出:
|
||||
$?
|
||||
无
|
||||
返回值:
|
||||
1 argument error
|
||||
2 ip/netmask/gateway address incorrect
|
||||
3 hosts doesn't exist
|
||||
4 resolv.conf doesn't exist
|
||||
5 ifcfg-eth0 doesn't exist
|
||||
6 network doesn't exist
|
||||
3 hosts/resolv.conf/ifcfg-eth0/network doesn't exist
|
||||
Usage:
|
||||
./configure_network.sh -t manual -h QinBo -d in.linx -i 192.168.1.110 -n 255.255.255.0 -g 192.168.1.254 -p 172.16.0.254
|
||||
./configure_network.sh -t static -h QinBo -d in.linx -i 192.168.1.110 -n 255.255.255.0 -g 192.168.1.254 -p 172.16.0.254
|
||||
说明:
|
||||
1.type必须为manual或者dynamic;
|
||||
2.不管哪种type,hostname是必须的;
|
||||
3.type=manual的时候IP、子网掩码、网关是必须的;
|
||||
4.device:多网卡的时候,可以指定用哪个网卡,默认用的是eth0。
|
||||
1.type必须为static或者dynamic;
|
||||
2.不管哪种type,hostname是必须的;
|
||||
3.type=static的时候IP、域名、子网掩码、网关是必须的;
|
||||
4.device:多网卡的时候,可以指定用哪个网卡,默认用的是eth0。
|
||||
|
||||
做自启服务:
|
||||
mk_serv_autoboot.sh
|
||||
@@ -135,15 +141,15 @@ mk_serv_autoboot.sh
|
||||
3)boot service:需要启动的服务
|
||||
4)boot number:启动号
|
||||
输出:
|
||||
$?
|
||||
无
|
||||
返回值:
|
||||
1:argument error
|
||||
2:boot script doesn't exist
|
||||
Usage:
|
||||
单个处理:echo "netkit-base inetd rsh S310"|./mk_serv_autoboot.sh
|
||||
批量处理:文件格式和单个处理一致
|
||||
说明:
|
||||
默认在/etc/rc.d/{rc3.d,rc5.d}建立链接。
|
||||
|
||||
默认在/etc/rc.d/{rc3.d,rc5.d}建立链接。
|
||||
|
||||
5.拷贝kernel、modules和生成initrd
|
||||
copy_kernels.sh
|
||||
@@ -151,40 +157,14 @@ copy_kernels.sh
|
||||
无
|
||||
输出:
|
||||
无
|
||||
返回值:
|
||||
1 kernel directory/modules directory/initrd.gz/makeinitrd doesn't exist
|
||||
说明:
|
||||
1.此脚本从 /Rocky/kernels和/Rocky/modules目录下拷贝kernel和modules,
|
||||
2.把/Rocky/initrd/initrd.gz,拷贝到硬盘上的/boot/initrd.gz.old,
|
||||
3.生成initrd调用原来的makeinitrd脚本生成
|
||||
1.此脚本从 /Rocky/kernels和/Rocky/modules目录下拷贝kernel和modules,
|
||||
2.把/Rocky/initrd/initrd.gz,拷贝到硬盘上的/boot/initrd.gz.old,
|
||||
3.生成initrd调用原来的makeinitrd脚本生成。
|
||||
|
||||
|
||||
6.安装完成执行的脚本
|
||||
exec_finish_install.sh
|
||||
输入:
|
||||
stdin
|
||||
1)脚本的名字
|
||||
输出:
|
||||
无
|
||||
说明:
|
||||
此脚本把99finish_install.sh拷贝到/var/finish_install目录下,
|
||||
然后把/var/finish_install目录下面的脚本,按照脚本名字前面
|
||||
的数字顺序从小到大依次拷贝到硬盘系统里面执行。
|
||||
|
||||
99finish_install.sh
|
||||
原来的firstboot.sh
|
||||
|
||||
7.安装bootloader,生成bootloader对应的配置文件
|
||||
install_bootloader.sh
|
||||
安装bootloader
|
||||
输入:
|
||||
arguments:
|
||||
[--help] show this message
|
||||
[-t|--type] boot loader type:grub,etc.
|
||||
输出:
|
||||
$?
|
||||
1 argument error
|
||||
2 bootloader type doesn't specify
|
||||
3 bootloader no implement
|
||||
127 bootloader utils not found
|
||||
6.生成bootloader对应的配置文件,安装bootloader
|
||||
configure_bootloader_cnf.sh
|
||||
配置bootloader配置文件
|
||||
输入:
|
||||
@@ -196,15 +176,51 @@ configure_bootloader_cnf.sh
|
||||
[-k|--kparameter] kernel parameter
|
||||
[-o|--osversion] OS version
|
||||
输出:
|
||||
$?
|
||||
无
|
||||
返回值:
|
||||
1 argument error
|
||||
2 bootloader type doesn't specify
|
||||
3 bootloader no implement
|
||||
4 bootloader configuration file doesn't exist
|
||||
说明:
|
||||
1.grub:对grub软件包里面的grub.conf.sample($TARGET/boot/grub/)进行相应的修改,
|
||||
grub:对grub软件包里面的grub.conf.sample($TARGET/boot/grub/)进行相应的修改,
|
||||
产生新的文件:$TARGET/boot/grub/menu.lst
|
||||
2.如果找不到相应设备的UUID则menu.lst使用设备名
|
||||
|
||||
install_bootloader.sh
|
||||
安装bootloader
|
||||
输入:
|
||||
arguments:
|
||||
[--help] show this message
|
||||
[-t|--type] boot loader type:grub,etc.
|
||||
输出:
|
||||
无
|
||||
返回值:
|
||||
1 argument error
|
||||
2 bootloader type doesn't specify
|
||||
3 bootloader no implement
|
||||
127 bootloader utils not found
|
||||
说明:
|
||||
此脚本把grub装在第一块硬盘上面,因为bios默认会从第一块硬盘启动,
|
||||
这样bios就能找到我们的装上去的gurb,从而正确引导系统。
|
||||
|
||||
|
||||
|
||||
7.安装完成执行的脚本
|
||||
exec_finish_install.sh
|
||||
输入:
|
||||
stdin
|
||||
1)脚本的名字
|
||||
输出:
|
||||
无
|
||||
返回值:
|
||||
根据具体执行脚本的返回值来确定,0是成功
|
||||
Usage:
|
||||
单个处理:echo "99finish_install.sh"| ./exec_finish_install.sh
|
||||
批量处理:文件格式和单个处理一致
|
||||
说明:
|
||||
此脚本把99finish_install.sh拷贝到/var/finish_install目录下,
|
||||
然后根据/var/finish_install目录下面的脚本名字前面的数字顺序,从小
|
||||
到大依次拷贝到硬盘系统里面执行。
|
||||
|
||||
99finish_install.sh
|
||||
原来的firstboot.sh
|
||||
|
||||
121
operation/install_bootloader.sh
Executable file
121
operation/install_bootloader.sh
Executable file
@@ -0,0 +1,121 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# DESCRIPTION: install bootloader for OS
|
||||
#
|
||||
# SCRIPT NAME: install_bootloader.sh
|
||||
#
|
||||
# Input:
|
||||
# [--help] show this message
|
||||
# [-t|--type] boot loader type:grub,etc.
|
||||
# Output:
|
||||
# NULL
|
||||
# Return value:
|
||||
# 1 argument error
|
||||
# 2 bootloader type doesn't specify
|
||||
# 3 bootloader no implement
|
||||
# 127 bootloader utils not found
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
#
|
||||
# EMAIL: bqin@linx-info.com
|
||||
#
|
||||
# DATE: 2010-09-02
|
||||
#
|
||||
# HISTORY:
|
||||
# REVISOR DATE MODIFICATION
|
||||
# Qin Bo 2010-09-02 create
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
source ./functions
|
||||
|
||||
usage ()
|
||||
{
|
||||
if [ "$1" == "-n" ];then
|
||||
cmd="info"
|
||||
ret=0
|
||||
else
|
||||
cmd="err"
|
||||
ret=1
|
||||
fi
|
||||
$cmd "
|
||||
This script will install boot loader for system
|
||||
|
||||
Usage: $0 options
|
||||
|
||||
options:
|
||||
[--help] show this message
|
||||
[-t|--type] boot loader type:grub, etc.
|
||||
|
||||
"
|
||||
return $ret
|
||||
}
|
||||
|
||||
install_grub ()
|
||||
{
|
||||
|
||||
# generate device.map
|
||||
grub --batch --no-floppy --device-map="$DEVICEMAP" << EOF 1>>"$DEV_LOG" 2>&1
|
||||
quit
|
||||
EOF
|
||||
# in order to let bios to load grub correct,
|
||||
# we install grub to first hard disk by default,
|
||||
# so even though OS install in secondary hard disk,
|
||||
# the OS still can be loaded from first hard disk.
|
||||
|
||||
f_hd=$(grep "(hd0)" "$DEVICEMAP"|awk '{print $NF}')
|
||||
|
||||
grub-install --no-floppy --root-directory=$TARGET $f_hd 1>>$DEV_LOG 2>&1
|
||||
}
|
||||
|
||||
main ()
|
||||
{
|
||||
if [ $# -eq 0 ];then
|
||||
usage; erv
|
||||
fi
|
||||
|
||||
tmp=$(getopt -o t: --long type:,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
|
||||
-t|--type)
|
||||
type="$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 [ -n "$type" ];then
|
||||
case "$type" in
|
||||
grub)
|
||||
install_grub
|
||||
erv
|
||||
;;
|
||||
*)
|
||||
err "$type bootloader no implement yet !"
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
else
|
||||
err "bootloader type doesn't specify"
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
GRUB_DIR="$TARGET/boot/grub"
|
||||
DEVICEMAP="$GRUB_DIR/device.map"
|
||||
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# DESCRIPTION: install package
|
||||
# DESCRIPTION: install package, if -s options not given,
|
||||
# get package from /Rocky/packages by default.
|
||||
#
|
||||
# SCRIPT NAME: install_pkg.sh
|
||||
#
|
||||
@@ -10,16 +11,20 @@
|
||||
# 1. pkgname
|
||||
# argument:
|
||||
# [--help] show usage
|
||||
# [-s|--source] Package source directory
|
||||
# <-s|--source> package source directory, if not specify, default is /Rocky/packages.
|
||||
#
|
||||
# Output:
|
||||
# sucess:
|
||||
# @ install $pkgname success.
|
||||
# Return value:
|
||||
# 1 argument error
|
||||
# 2 pkgname doesn't exist in source directory
|
||||
# 2 source directory $PKG_SOURCE_DIR doesn't exist
|
||||
# 3 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). if devices nearly no spaces left.
|
||||
#
|
||||
# 2. add install package from below media:
|
||||
# 1). install from network.
|
||||
@@ -61,8 +66,8 @@ This script will install a package
|
||||
Usage: $0 options
|
||||
|
||||
options:
|
||||
[--help] Show this message
|
||||
[-s | --source] Package source directory
|
||||
[--help] show this message
|
||||
<-s|--source> package source directory, if not specify, default is /Rocky/packages.
|
||||
|
||||
(ex: echo make|install_pkg.sh -s /Rocky/packages)
|
||||
"
|
||||
@@ -79,11 +84,12 @@ get_pkg_file ()
|
||||
|
||||
local pkg_name="$1"
|
||||
|
||||
# get the first package if have multi-package in source directory
|
||||
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
|
||||
return 3
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -95,7 +101,8 @@ add_pkg ()
|
||||
fi
|
||||
|
||||
local pkg_src=$1
|
||||
pkgadd -f -r $TARGET $pkg_src 1>$dev_LOG 2>&1
|
||||
|
||||
pkgadd -f -r $TARGET $pkg_src 1>>$DEV_LOG 2>&1
|
||||
}
|
||||
|
||||
install_pkg ()
|
||||
@@ -105,7 +112,12 @@ install_pkg ()
|
||||
return 1
|
||||
fi
|
||||
|
||||
local pkgname="$1"
|
||||
local pkgname
|
||||
local db_dir
|
||||
local db
|
||||
local pkg_src
|
||||
|
||||
pkgname="$1"
|
||||
|
||||
# create db for pkgutils
|
||||
db_dir="/var/lib/pkg"
|
||||
@@ -117,20 +129,23 @@ install_pkg ()
|
||||
touch "$db"
|
||||
fi
|
||||
|
||||
local pkg_src=$(get_pkg_file $pkgname)
|
||||
pkg_src=$(get_pkg_file $pkgname)
|
||||
erv
|
||||
|
||||
info "install $pkgname to $TARGET"
|
||||
info "installing $pkg_src to $TARGET"
|
||||
add_pkg $pkg_src
|
||||
erv
|
||||
}
|
||||
|
||||
main ()
|
||||
{
|
||||
tmp=$(getopt -o s: --long source:,help -- "$@" 2>$dev_LOG)
|
||||
local line
|
||||
local tmp
|
||||
local pkgname
|
||||
|
||||
tmp=$(getopt -o s: --long source:,help -- "$@" 2>>$DEV_LOG)
|
||||
if [ $? -ne 0 ];then
|
||||
usage
|
||||
erv
|
||||
usage; erv
|
||||
fi
|
||||
|
||||
# set all argument to arg variable
|
||||
@@ -149,12 +164,9 @@ main ()
|
||||
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
|
||||
if [ ! -e "$PKG_SOURCE_DIR" ];then
|
||||
err "source directory: $PKG_SOURCE_DIR doen't exist !"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
while read line ;do
|
||||
@@ -164,12 +176,13 @@ main ()
|
||||
if [ -n "$pkgname" ];then
|
||||
install_pkg "$pkgname"
|
||||
erv
|
||||
info "install $pkgname success" stdout
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
PKG_SOURCE_DIR=""
|
||||
PKG_SOURCE_DIR="/Rocky/packages"
|
||||
|
||||
main "$@"
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./functions
|
||||
|
||||
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
|
||||
mkinitrd "$TARGET"/boot/initrd.gz $modules --without-usb --without-multipath --fstab="$TARGET"/etc/fstab -f
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
#!/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.
|
||||
# DESCRIPTION: this script use for system autoboot services.
|
||||
# function:
|
||||
# 1.make a sysmbol link to script of autotboot services,
|
||||
# 2.generate $pkgname-serv.conf, this configure file use by post_add.
|
||||
#
|
||||
# Usage: echo "netkit-base inetd rsh S310"|./mk_serv_autoboot.sh
|
||||
#
|
||||
@@ -16,6 +16,8 @@
|
||||
# 4. boot number
|
||||
#
|
||||
# Output:
|
||||
# NULL
|
||||
# Return value:
|
||||
# 1 argument error
|
||||
# 2 boot script doesn't exist
|
||||
#
|
||||
@@ -45,9 +47,9 @@ make_sysmbol_link ()
|
||||
local script="$1"
|
||||
local number="$2"
|
||||
|
||||
for dir in $rc_dir; do
|
||||
pushd $dir >$dev_LOG &&
|
||||
if [ -e $init_dir/$script ];then
|
||||
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.
|
||||
@@ -57,10 +59,10 @@ make_sysmbol_link ()
|
||||
ln -sf ../init.d/$script ./$number$script
|
||||
fi
|
||||
else
|
||||
err "$script doesn't exist in $init_dir"
|
||||
err "$script doesn't exist in $INIT_DIR"
|
||||
return 2
|
||||
fi
|
||||
popd >$dev_LOG
|
||||
popd >>$DEV_LOG
|
||||
done
|
||||
|
||||
}
|
||||
@@ -76,17 +78,18 @@ gen_serv_cnf ()
|
||||
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
|
||||
# may be some boot services needn't configure,
|
||||
# it 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"
|
||||
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"
|
||||
printf "%s=yes\n" $service > "$SERV_CFG_DIR"/"$pkgname-serv.conf"
|
||||
fi
|
||||
|
||||
}
|
||||
@@ -109,21 +112,25 @@ mk_serv_autoboot ()
|
||||
|
||||
main ()
|
||||
{
|
||||
local line
|
||||
|
||||
info "configure auto boot service"
|
||||
while read line;do
|
||||
if [ -n "$line" ];then
|
||||
mk_serv_autoboot $line
|
||||
erv
|
||||
fi
|
||||
done
|
||||
info "configure auto boot service success"
|
||||
}
|
||||
|
||||
|
||||
rcd="$TARGET/etc/rc.d"
|
||||
init_dir="$rcd/init.d"
|
||||
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"
|
||||
RC_DIR="$RCD/rc3.d $RCD/rc5.d"
|
||||
SERV_CFG_DIR="$TARGET/var/lib/pkg"
|
||||
|
||||
main $@
|
||||
main "$@"
|
||||
|
||||
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
# 1. partition
|
||||
# 2. mountpoint
|
||||
# 3. filesystem type
|
||||
# below input is optional, if not set, we mount default configure,
|
||||
# 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
|
||||
# success:
|
||||
# @ mount $devname success
|
||||
# Return value:
|
||||
# 1 device node doesn't exist
|
||||
# 32 mount failure
|
||||
#
|
||||
# AUTHOR: Qin Bo
|
||||
@@ -37,25 +38,21 @@ source ./functions
|
||||
|
||||
mount_partition ()
|
||||
{
|
||||
|
||||
local devname="$1"
|
||||
local mountpoint="$2"
|
||||
local fs_type="$3"
|
||||
local fs_mntops="$4"
|
||||
local mount_pos="$TARGET$mountpoint"
|
||||
|
||||
if [ ! -e "$devname" ];then
|
||||
err "$devname node doesn't exist !"
|
||||
return 3
|
||||
return 1
|
||||
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
|
||||
# mount filesystem for default option,
|
||||
# after installation will set acl, so we use acl option mount here.
|
||||
# this configuration according old Rocky installer.
|
||||
case $fs_type in
|
||||
ext2|ext3|reiserfs)
|
||||
[ -z "$fs_mntops" ] && fs_mntops="acl" ;;
|
||||
@@ -68,18 +65,31 @@ mount_partition ()
|
||||
mkdir -p "$mount_pos"
|
||||
fi
|
||||
|
||||
# device node has already mounted on other directory, umount it.
|
||||
# ex: /dev/hda5 should mount on /mnt, but it has already mounted on /cdrom before,
|
||||
# so, we umount it
|
||||
if [ "$(grep "$devname" /proc/mounts|awk '{print $2}')" != "$mount_pos" ];then
|
||||
reumount $devname
|
||||
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
|
||||
info "mounting $devname on $mount_pos with $fs_type filesystem"
|
||||
mount -t "$fs_type" -o $fs_mntops "$devname" "$mount_pos" 1>>"$DEV_LOG" 2>&1
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
local line
|
||||
|
||||
# sort -k 2 ensure let short mountpoint sort at front of long mountpoint,
|
||||
# in this way, we can mount long mountpoint after short mountpoint.
|
||||
# ex: /usr/lib, /usr, /, after sort is /, /usr, /usr/lib
|
||||
# this mean that / is mounted first, then mount /usr, finally mount /usr/lib
|
||||
while read line; do
|
||||
echo $line
|
||||
done|sort -k 2 -u|
|
||||
@@ -87,10 +97,12 @@ main()
|
||||
if [ -n "$line" ];then
|
||||
mount_partition $line
|
||||
erv
|
||||
info "mount $(echo $line|awk '{print $1}') success" stdout
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
main "$@"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user