Commit 554dd8a4 authored by Natanael Copa's avatar Natanael Copa

setup-apkcache: new setup tool

A tool to setup the apk cache. This and setup-lbu replaces the
setup-apklbu tool.
parent 2d40c0f4
......@@ -5,6 +5,7 @@ setup-acf
setup-ads
setup-alpine
setup-alpine-web
setup-apkcache
setup-apkrepos
setup-bootable
setup-cryptswap
......
......@@ -13,7 +13,7 @@ SBIN_FILES := lbu\
setup-ads\
setup-alpine\
setup-alpine-web\
setup-apklbu\
setup-apkcache\
setup-apkrepos\
setup-ntp\
setup-cryptswap\
......
......@@ -88,7 +88,9 @@ NTPOPTS="-c openntpd"
DISKOPTS="-m data /dev/sda"
# Setup in /media/sdb1
APKLBUOPTS="-m sdb1"
LBUOPTS="/media/sdb1"
APKCACHEOPTS="/media/sdb1/cache"
__EOF__
echo "Answer file $CREATEANSWERFILE has been created. Please add or remove options as desired in that file"
exit 0
......@@ -155,5 +157,6 @@ DEFAULT_DISK=none \
$PREFIX/sbin/setup-disk -q ${DISKOPTS}
if [ "`cat /tmp/alpine-install-diskmode.out`" != "sys" ]; then
$PREFIX/sbin/setup-apklbu -i ${APKLBUOPTS}
$PREFIX/sbin/setup-lbu ${LBUOPTS}
$PREFIX/sbin/setup-apkcache ${APKCACHEOPTS}
fi
#!/bin/sh
PREFIX=
. "$PREFIX/lib/libalpine.sh"
usage() {
cat <<__EOF__
usage: setup-apkcache [-h] [DIR]
Setup apk caching.
If DIR is not specified user will be asked for location.
options:
-h Show this help
__EOF__
exit 1
}
is_mounted() {
awk '{print $2}' /proc/mounts | grep -q "^$1$"
}
# figure out mount point
find_mount_point() {
local dir="$1"
while ! [ -d "$dir" ]; do
dir=${dir%/*}
done
local fs_id=$(stat -f -c %i "$dir")
local parent="${dir%/*}"
while [ -n "$parent" ] && [ "$(stat -f -c %i $parent)" = "$fs_id" ]; do
dir=$parent
parent=${parent%/*}
done
[ -z "$dir" ] && dir=/
echo $dir
}
get_mount_opts() {
local mnt="$1"
awk "\$2 == \"$mnt\" {gsub(/,/, \" \", \$4); print \$4}" /proc/mounts
}
is_mounted_ro() {
local mnt="$1"
local opts=$(get_mount_opts $mnt)
local opt=
for opt in $opts; do
if [ "$opt" = "ro" ]; then
return 0
fi
done
return 1
}
while getopts "h" opt; do
case $opt in
h) usage;;
esac
done
shift $(( $OPTIND - 1 ))
# try auto detetect what we suggest
suggestion=
if [ -L /etc/apk/cache ]; then
suggestion=$(readlink $suggestion)
if [ -z "$suggestion" ] && [ -f /etc/lbu/lbu.conf ]; then
. /etc/lbu/lbu.conf
if [ -n "$LBU_MEDIA" ]; then
suggestion=/media/$LBU_MEDIA/cache
fi
fi
if [ -z "$suggestion" ] && [ -L /dev/usbdisk ]; then
suggestion=/media/usb/cache
fi
if [ -z "$suggestion" ]; then
suggestion=none
fi
cachedir=$1
while [ -z "$cachedir" ]; do
echo -n "Where would you like to store apk cache? (or none) [$suggestion] "
default_read cachedir $suggestion
done
if [ "$cachedir" = "none" ]; then
exit 0
fi
mount=$(find_mount_point $cachedir)
cleanup=
if ! is_mounted $mount; then
mount $mount || exit 1
cleanup="umount"
elif is_mounted_ro $mount; then
mount -o remount,rw $mount || exit 1
cleanup="remount"
fi
mkdir -p $cachedir
if [ -L /etc/apk/cache ]; then
rm -f /etc/apk/cache
fi
ln -s $cachedir /etc/apk/cache
case "$cleanup" in
umount) umount $mount;;
remount) mount -o remount,ro $mount;;
esac
#!/bin/sh
PREFIX=
. "$PREFIX/lib/libalpine.sh"
usage() {
cat <<__EOF__
usage: setup-apklbu [-hi] [-m relative mountpoint]
Setup apk caching and lbu settings.
options:
-h Show this help
-i Run in installer mode (usually only when called by setup-alpine)
-m Specify mountpoint under /media for lbu backups (default is usb)
__EOF__
exit 1
}
while getopts "im:h" opt; do
case $opt in
i) VERBOSE="1";;
h) usage;;
m) MOUNTPOINT="$OPTARG";;
esac
done
if [ "$VERBOSE" = "1" ]; then
echo "Setup apk caching and lbu? (y/N)"
default_read setupapklbu
if [ "$setupapklbu" = "N" ] || [ "$setupapklbu" = "n" ]; then
exit 0
fi
if [ -z $MOUNTPOINT ]; then
MOUNTPOINT="usb"
echo "Please enter mountpoint directory under /media for lbu [$MOUNTPOINT]:"
default_read MOUNTPOINT "$MOUNTPOINT"
fi
fi
if [ -z $MOUNTPOINT ]; then
MOUNTPOINT="usb"
fi
mountstatus="`mount | grep /media/${MOUNTPOINT}`"
if [ -z $mountstatus ]; then
echo "$MOUNTPOINT is not mounted" && exit 1
fi
readwritestatus="`echo $mountstatus | awk -F '(' '{print $2}' | awk -F ',' '{print $1}'`"
if [ "$readwritestatus" = "ro" ]; then
rewrite=1
fi
if [ "$rewrite" = 1 ]; then
mount -o remount,rw /media/${MOUNTPOINT} || die "Failed to remount media rw"
fi
mkdir -p /media/${MOUNTPOINT}/cache || die "Failed to create /media/${MOUNTPOINT}/cache"
ln -s /media/${MOUNTPOINT}/cache /etc/apk/cache || die "Failed to create apk cache softlink"
apk cache sync
cat > /etc/lbu/lbu.conf <<EOF
# what cipher to use with -e option
DEFAULT_CIPHER=aes-256-cbc
# Uncomment the row below to encrypt config by default
# ENCRYPTION=$DEFAULT_CIPHER
# Uncomment below to avoid <media> option to 'lbu commit'
# Can also be set to 'floppy'
LBU_MEDIA=$MOUNTPOINT
# Uncomment below to let lbu make up to 3 backups
# BACKUP_LIMIT=3
EOF
lbu package /media/"$MOUNTPOINT" || die "Failed to lbu apkovl on /media/${MOUNTPOINT}"
sync
if [ "$rewrite" = 1 ]; then
mount -o remount,ro /media/${MOUNTPOINT} || die "Failed to remount media ro"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment