vhost-stack/bin/vhost-user-jails-cp.sh

61 lines
1.2 KiB
Bash
Raw Normal View History

2021-04-04 13:28:22 -07:00
#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
2021-04-04 14:15:16 -07:00
# load include file
source $(dirname $0)/vhost.sh
2021-04-04 13:28:22 -07:00
2021-09-16 16:21:35 -07:00
help()
{
thisfilename=$(basename -- "$0")
2021-10-05 11:33:24 -07:00
echo "Add file or directory to all existing jails."
2021-09-16 16:21:35 -07:00
echo ""
2021-10-05 11:33:24 -07:00
echo "usage: $thisfilename <path_to_file_or_directory>"
2021-09-16 16:21:35 -07:00
echo ""
echo " -h Print this help."
exit
}
2021-04-04 13:28:22 -07:00
# check for and set file to be copied in to jails
if [ -n "$1" ]; then
2021-09-16 16:21:35 -07:00
if [ $1 == "-h" ]; then
help
else
cpfile=$1
fi
2021-04-04 13:28:22 -07:00
else
2021-10-05 11:33:24 -07:00
echo "file or directory to copy in to jails not set"
2021-04-04 13:28:22 -07:00
exit 1
fi
# make sure file exists
2021-10-05 11:33:24 -07:00
if [[ ! -f $cpfile ]] && [[ ! -d $cpfile ]]; then
echo "invalid file or directory for copying in to jails"
2021-04-04 13:28:22 -07:00
exit 1
fi
# make sure jails dir exists
if [[ ! -e /usr/jails/ ]]; then
echo "/usr/jails does not exist"
exit 1
fi
# check for /usr/sbin/jk_cp
if [[ ! -x "/usr/sbin/jk_cp" ]]; then
echo "/usr/sbin/jk_cp does not exist or is not executable"
exit 1
fi
# get list of jails
cd /usr/jails/
jails=(*)
for jail in "${!jails[@]}"
do
jail=${jails[$jail]}
echo "adding $cpfile to $jail"
jk_cp -k -j /usr/jails/$jail $cpfile
done