initial commit

This commit is contained in:
Dave Reisner 2012-06-17 15:17:10 -04:00
commit f614a4ee87
3 changed files with 210 additions and 0 deletions

71
common Normal file
View File

@ -0,0 +1,71 @@
#!/bin/bash
out() { printf "$1 $2\n" "${@:3}"; }
error() { out "==> ERROR:" "$@"; }
msg() { out "==>" "$@"; }
msg2() { out " ->" "$@";}
die() { error "$@"; exit 1; }
in_array() {
local i
for i in "${@:2}"; do
[[ $1 = "$i" ]] && return
done
}
api_fs_mount() {
mount -t proc proc "$1/proc" -o nosuid,noexec,nodev || return 1
mount -t sysfs sys "$1/sys" -o nosuid,noexec,nodev || return 1
mount -t devtmpfs udev "$1/dev" -o mode=0755,nosuid || return 1
mount -t devpts devpts "$1/dev/pts" -o mode=0620,gid=5,nosuid,noexec || return 1
mount -t tmpfs shm "$1/dev/shm" -o mode=1777,nosuid,nodev || return 1
mount -t tmpfs run "$1/run" -o nosuid,nodev,mode=0755 || return 1
mount -t tmpfs tmp "$1/tmp" -o mode=1777,strictatime,nodev,nosuid,size=50M || return 1
}
api_fs_umount() {
umount \
"$1/tmp" \
"$1/run" \
"$1/dev/shm" \
"$1/dev/pts" \
"$1/dev" \
"$1/sys" \
"$1/proc"
}
fstype_is_pseudofs() {
# list taken from util-linux source: libmount/src/utils.c
local pseudofs_types=('anon_inodefs'
'autofs'
'bdev'
'binfmt_misc'
'cgroup'
'configfs'
'cpuset'
'debugfs'
'devfs'
'devpts'
'devtmpfs'
'dlmfs'
'fuse.gvfs-fuse-daemon'
'fusectl'
'hugetlbfs'
'mqueue'
'nfsd'
'none'
'pipefs'
'proc'
'pstore'
'ramfs'
'rootfs'
'rpc_pipefs'
'securityfs'
'sockfs'
'spufs'
'sysfs'
'tmpfs')
in_array "$1" "${pseudofs_types[@]}"
}

94
genfstab Executable file
View File

@ -0,0 +1,94 @@
#!/bin/bash
. ./common
shopt -s extglob
write_source() {
local tag= spec=
if (( bylabel )); then
tag=LABEL
spec=$(lsblk -rno LABEL "$1" 2>/dev/null)
elif (( byuuid )); then
tag=UUID
spec=$(lsblk -rno UUID "$1" 2>/dev/null)
fi
if [[ $spec ]]; then
printf '# %s\n' "$source"
printf '%-20s' "$tag=$spec"
else
printf '%-20s' "$source"
fi
}
root=/mnt
while getopts ':LUr:' flag; do
case $flag in
L)
bylabel=1
;;
U)
byuuid=1
;;
r)
# trim trailing slashes
root=${OPTARG%%+(/)}
;;
?)
die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
;;
esac
done
shift $(( OPTIND - 1 ))
if (( bylabel && byuuid )); then
die "cannot specify both -U and -L"
fi
# handle block devices
findmnt -Recvruno SOURCE,TARGET,FSTYPE,VFS-OPTIONS "$root" |
while read -r source target fstype opts; do
# default 5th and 6th columns
dump=0 pass=2
# this is root
target=${target#$root}
if [[ $target = ?(/) ]]; then
target=/
pass=1
fi
# we don't fsck pseudofs
if fstype_is_pseudofs "$fstype"; then
continue
pass=0
fi
# write one line
write_source "$source"
printf '\t%-10s' "$target" "$fstype" "$opts"
printf '\t%s %s' "$dump" "$pass"
printf '\n\n'
done
# handle swaps devices
{
# ignore header
read
while read -r device _ _ _ prio; do
options=defaults
if [[ $prio != -1 ]]; then
options+=,pri=$prio
fi
printf -v device '%b' "$device"
printf '%-20s\t%-10s\t%-10s\t%-10s\t0 0\n' "$device" 'none' 'swap' "$options"
done
} </proc/swaps
# vim: et ts=2 sw=2 ft=sh :

45
pacstrap Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
#
# Assumptions:
# 1) User has partitioned, formatted, and mounted partitions on /mnt
# 2) Network is functional
# 3) Arguments passed to the script are valid pacman targets
# 4) A valid mirror appears in /etc/pacman.d/mirrorlist
#
source ./common
declare newroot=/mnt
while getopts ':r:' flag; do
case $flag in
r)
newroot=$OPTARG
;;
?)
die '%s: invalid option -- '\''%s'\' "${0##*/}" "$OPTARG"
;;
esac
done
shift $(( OPTIND - 1 ))
if (( $# )); then
packages=("$@")
else
packages=('base' 'base-devel')
fi
rootdev=$(findmnt -runo SOURCE "$newroot") || die '%s is not a mountpoint!' "$newroot"
# create obligatory directories
msg 'Creating install root at %s' "$newroot"
mkdir -p "$newroot/var/lib/pacman" /mnt/{dev,proc,sys,run,tmp,etc}
# mount API filesystems
api_fs_mount "$newroot"
msg 'Installing packages to %s' "$newroot"
pacman -r "$newroot" -Sy "${package[@]}"
api_fs_mount "$newroot"