#!/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 __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 fi if [ -z $MOUNTPOINT ]; then MOUNTPOINT="usb" echo "Please enter mountpoint directory under /media for lbu [$MOUNTPOINT]:" default_read MOUNTPOINT "$MOUNTPOINT" 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 < 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