Bash:
#!/bin/sh
host=$(hostname -f)
pkgdir=~/test1 # where .txt files are
pkgfile=${pkgdir}/pkg_list_${host}.txt
if [ ! -s ${pkgfile} ] ; then
echo "No packages list file (${pkgfile}) for host '${host}'"
pkgfile=
while [ -z "${pkgfile}" ] ; do
echo "Which list file to use?"
n=0
for fn in ${pkgdir}/*.txt; do
n=$((n+1))
printf " %2d. %s\n" ${n} ${fn#${pkgdir}/}
done
sel=
while :; do
printf "Enter file number to use: "
read sel
[ "${sel}" -eq "${sel}" 2>/dev/null ] || continue
[ ${sel} -gt 0 -a ${sel} -le ${n} ] || continue
break
done
n=0
for fn in ${pkgdir}/*.txt; do
n=$((n+1))
if [ ${n} -eq ${sel} ] ; then
pkgfile=${fn}
break
fi
done
done
fi
echo "Using ${pkgfile}"
Thank You so much!
What about last “C” option for changing hostname, apply settings and start script from scratch ?
C. Correct hostname (freebsd.local.net) of this server to install appropriate packages.
But have you considered using role-based packages lists? Also using interactive install scripts kind-of defeats the purpose
Normally whole script intended for running manually (or with help of Ansible), it just find appropriate pkg list file, run all installs, save log file (and Ansible pull it back together with sys log). Done.
Useful for admins who have no ZFS snapshots, whole drive backups, Ansible, and just have usb memstick with fresh FreeBSD install image and up to 100 FreeBSD boxes (colleges, campus, etc...)
This additional code needed in case
- server have default FreeBSD hostname (operator mistake during bare metal setup from memstick, for example);
- server have the name that not recognized as part of infrastructure;
Script waiting 20sec, after that if no entry, write “[ERROR] Appropriate pkg list not found for $(hostname -f)” to log file, write same to syslog, and exit with code “1”.
Of course, for bulk installing may be some pkg list file that named according default FreeBSD hostname. Like template...
So it would have fully automated behavior.
Could You be so please to correct code (adding “C” option + exit after 20s no entry) when having coffee break?
At the end of the week we all receive a nice script for making package list file and automatic installation. To not installing manually from scratch...
Each one of users here care about 3+ FreeBSD boxes (home, work, friends, etc), so script may be usable...
P.S. After You done, I would adding “S” option to selection and “-s” parameter to “making packages list and exit”.
S. Make list of packages that installed on this server.