歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> 教你自動下載文件並制作OpenBSD ISO

教你自動下載文件並制作OpenBSD ISO

日期:2017/2/27 11:57:41   编辑:Linux文化

如果可能的話,請購買 OpenBSD 官方制作的 CD 套裝。

詳情請訪問:http://www.openbsd.org/faq/faq3.html#BuyCD

腳本的使用方法:

$ ./mk_openbsd_iso-0.1.sh 3.9 i386

您只要指定需要制作的 OpenBSD 版本和平台架構,即可生成對應的 ISO 文件。

[color=red]此腳本需要 wget / mkisofs 這兩個工具才能制作ISO。

wget 用於下載文件,mkisofs 用於制作 ISO。[/color]

注意事項:

並不是每個平台都可以使用 CD 啟動安裝,詳情請訪問:

http://www.openbsd.org/faq/faq4.html#Overview

默認創建的 ISO 文件不會帶有任何的 packages,如果你需要將 packages 包含進去,

請閱讀腳本中函數 FETCH_PKGS() 的說明。

以下是完整的腳本:

#!/bin/sh

# Author : MichaelBibby

# Date : 2006.07.22

# Purpose : Automatic download file sets and create an OpenBSD -release or

# -snapshots ISO.

# Version : 0.1

# Usage : ./mk_openbsd_iso.sh [3.9|4.0|snapshots] [i386|amd64|sparc64]

VERSION="$1" # Special OpenBSD version, like 3.9, 4.0, snapshots.

ARCH="$2" # Maechine architecture, like i386, amd64.

TMP_ARCHIVE="$HOME/tmp/openbsd" # Store all openbsd file sets.

SETS_ARCHIVE="$TMP_ARCHIVE/$VERSION/$ARCH" # Store all installation file sets.

PKGS_ARCHIVE="$TMP_ARCHIVE/$VERSION/$ARCH/packages" # Store all packages.

FETCH_CMD="wget"

CDROM_FS=$(basename ${SETS_ARCHIVE}/cdrom*.fs)

# Check the following URL to choose a mirror near you:

# http://www.openbsd.org/ftp.html

#MIRROR="ftp://ftp.openbsd.org/pub/OpenBSD"

MIRROR="http://mirror.openbsd.org.cn/ftp"

MKISOFS_CMD="mkisofs -vrlTJV "OpenBSD_${VERSION}_$ARCH" \

-b $VERSION/$ARCH/${CDROM_FS} \

-c boot.catalog \

-o $HOME/OpenBSD_${VERSION}_$ARCH.iso $TMP_ARCHIVE"

USAGE()

{

if [ X"$#" != X"2" ]; then

echo "USAGE: $0 VERSION ARCH"

echo "e.g.: $0 [3.9|4.0|snapshots] [i386|amd64|...]"

exit 255

fi

}

CHECK_APPS()

{

# Set all nessessary applications into an ARRAY: APPS.

APPS_ARRAY="mkisofs $FETCH_CMD"

echo "Checking neccessary applications..."

for i in $APPS_ARRAY

do

if [ ! $(whereis "$i") ]

then

echo "ERROR: $i is not installed, you should installed first"

case $i in

mkisofs)

echo "mkisofs is always included in package 'cdrtools'.";;

esac

exit

fi

done

}

CHECK_DIRS()

{

# Set all nessessary dir into an ARRAY: DIRS.

DIRS_ARRAY="$SETS_ARCHIVE $PKGS_ARCHIVE"

echo "Checking neccessary directories..."

# Check and create dirs.

for dir in ${DIRS_ARRAY}

do

if [ ! -d "$dir" ]; then

echo -ne "\tWARNNING: $dir NOT exist, creating it..."

mkdir -p $dir

echo "DONE"

fi

done

}

# Fetch OpenBSD's installation file sets, like base39.tgz, comp39.tgz.

FETCH_SETS()

{

TMP_OB_FILES_SETS="/tmp/ob_file_sets"

# If you want to specify which file sets will be contained in the iso file,

# you should comment the following 2 lines, and create '/tmp/ob_file_sets'

# manually, and then write the file sets' names in it. Finally, maybe you

# want to comment the line following: 'rm -f $TMP_OB_FILES_SETS'.

# ------------------------------------------------------------------------

echo "Downloading OpenBSD file sets' index file..."

$FETCH_CMD -O $TMP_OB_FILES_SETS $MIRROR/$VERSION/$ARCH/index.txt

# ------------------------------------------------------------------------

for i in $(cat $TMP_OB_FILES_SETS)

do

echo "Downloading file set: $i..."

$FETCH_CMD -c -O $SETS_ARCHIVE/$i $MIRROR/$VERSION/$ARCH/$i

done

#rm -f $TMP_OB_FILES_SETS

}

FETCH_PKGS()

{

TMP_OB_PKG_SETS="/tmp/ob_pkg_sets"

# If you want to specify which packages will be contained in the iso file,

# you should comment the following 2 lines, and create '/tmp/ob_pkg_sets'

# manually, and then write the packages' name in it. Finally, maybe you

# want to comment the line following: 'rm -f $TMP_OB_PKG_SETS'.

# ------------------------------------------------------------------------

#echo "Downloading OpenBSD package sets' index file..."

#$FETCH_CMD -c -O $TMP_OB_PKG_SETS $MIRROR/$VERSION/packages/$ARCH/index.txt

# ------------------------------------------------------------------------

for i in $(cat $TMP_OB_PKG_SETS)

do

echo "Downloading package: $i..."

$FETCH_CMD -O $PKGS_ARCHIVE/$i $MIRROR/$VERSION/packages/$ARCH/$i

done

#rm -f $TMP_OB_PKG_SETS

}

# ----------- SCRIPT MAIN -------------

clear

echo -e "\n\

\t# --------------------------------------------------------------------------#

\t# ------- We recommend you buy OpenBSD's Offical CD sets to support ------#

\t# ------- ongoing development of OpenBSD. There are many good reasons ------#

\t# ------- to own an OpenBSD CD set: ------#

\t# ------- http://www.openbsd.org/faq/faq3.html#BuyCD ------#

\t# --------------------------------------------------------------------------#

\t# ------- Warnning: Not every platform supports all boot options. For ------#

\t# ------- more information, see also: ------#

\t# ------- http://www.openbsd.org/faq/faq4.html#Overview ------#

\t# --------------------------------------------------------------------------#

\t# ------- Note: If you want to include some packages in the ISO file, ------#

\t# ------- please read the function: FETCH_PKGS, and uncomment the ------#

\t# ------- function at the end of script: ------#

\t# ------- FETCH_PKGS && \ ------#

\t# --------------------------------------------------------------------------#

"

sleep 10

USAGE "$@" && \

CHECK_APPS && \

CHECK_DIRS && \

FETCH_SETS && \

#FETCH_PKGS && \

$MKISOFS_CMD && \

echo "GOOD, ISO has been created:\n\t$HOME/OpenBSD_${VERSION}_${ARCH}.iso"

Copyright © Linux教程網 All Rights Reserved