#!/bin/sh
args=`getopt u: $*`
if [ $? -ne 0 ]; then
echo 'Usage: ...'
exit 2
fi
set -- $args
while :; do
case "$1" in
-u)
user=$2
shift; shift
;;
--)
shift; break
;;
esac
done
if [ -n "${user}" ]; then
HOST="${user}@$1"
else
HOST="$1"
fi
KEY=`cat ~/.ssh/id_rsa.pub`
ssh -t $HOST <<SSH
mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys ~/.hushlogin
grep -q "${KEY}" ~/.ssh/authorized_keys || echo "${KEY}" >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
cd /tmp
cat > /tmp/
setup.sh <<__EOF__
if [ -L /home ]; then
rm /home && zfs set mountpoint=/home zroot/usr/home
fi
pw usermod \${USER} -w no
pw usermod root -w none
if [ ! -f /usr/local/etc/pkg/repos/ivs.conf ]; then
mkdir -p /usr/local/etc/pkg/repos
cat > /usr/local/etc/pkg/repos/ivs.conf <<EOF
всякое
EOF
fi
if [ ! -f /etc/resolv.conf ]; then
cat > /etc/resolv.conf <<EOF
options edns0
nameserver
127.0.0.1EOF
fi
ASSUME_ALWAYS_YES=yes SIGNATURE_TYPE=none pkg install mtr-nox11 perl5 python37 screen smartmontools sudo
grep -q '^%wheel ALL=(ALL) NOPASSWD: ALL' /usr/local/etc/sudoers || echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /usr/local/etc/sudoers
__EOF__
chmod +x /tmp/
setup.shsu - root -c /tmp/
setup.shSSH