# - このスクリプトでchroot環境を構築後に、スクリプト再実行すると上書きされる
# ので、chroot環境のファイルを修正した場合は、注意する事
#
-# $Id: chroot.sh,v 1.2 2022/10/18 08:43:47 dev Exp $
+# $Id: chroot.sh,v 1.3 2022/10/18 10:59:16 dev Exp $
#
#####################################################################################
/etc/profile.d
/usr/share/terminfo
)
+
LINKED_FILES=(
/etc/profile
/etc/bashrc
/usr/libexec/grepconf.sh
)
+DELETE_FILES=(
+ /etc/profile.d/which2.csh
+ /etc/profile.d/which2.sh
+)
+
# Init
-FLG=0
+ALL_CMDLIST=("${CMD_LIST[@]} ${REQUIRED_CMD[@]}")
+
EXEC_CMD=(
/usr/bin/which
/usr/bin/install
/usr/bin/chmod
)
+FLG=0
for valf in ${EXEC_CMD[@]}
do
- if [ ! -x $valf ]; then
- echo "File ($valf) not found"
- FLG=1
- fi
+ if [ ! -x $valf ]; then
+ echo "File ($valf) not found"
+ FLG=1
+ fi
done
if [ $FLG -eq 1 ]; then
- echo "--- Error ---"
- exit 1
+ echo "--- Error ---"
+ exit 1
fi
# Main
done
# 利用コマンドとライブラリーのコピー
-for valp in `which $CMD_LIST`;
+for valp in `which $ALL_CMDLIST`;
do
# command
test -e ./$valp && continue
# library
LIBS=`ldd $valp | awk '{ print $3 }'`
if [ ${#LIBS[*]} -gt 0 ]; then
- for valf in $LIBS;
- do
- test ! -d `dirname ${CHG_ROOT}$valf` && install -m 0755 -o root -g root -d `dirname ${CHG_ROOT}$valf`
- test ! -f ${CHG_ROOT}$valf && cp -p $valf ./$valf
- done
+ for valf in $LIBS;
+ do
+ test ! -d `dirname ${CHG_ROOT}$valf` && install -m 0755 -o root -g root -d `dirname ${CHG_ROOT}$valf`
+ test ! -f ${CHG_ROOT}$valf && cp -p $valf ./$valf
+ done
fi
done
test ! -c ${CHG_ROOT}/dev/urandom && mknod ${CHG_ROOT}/dev/urandom c 1 9
chmod 0666 ${CHG_ROOT}/dev/{null,zero,random,urandom}
+# ディレクトリコピー後の指定ファイルの削除
+for valf in ${DELETE_FILES[@]}
+do
+ test -f ${CHG_ROOT}$valf && rm -f ${CHG_ROOT}$valf
+done
+
# rootユーザー情報の追加
grep /etc/passwd -e "^root" > ${CHG_ROOT}/etc/passwd
grep /etc/group -e "^root" > ${CHG_ROOT}/etc/group