/usr/sbin/ltsp-config is in ltsp-server 5.5.7-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | #!/bin/sh
# Copyright (c) 2012, Alkis Georgopoulos <alkisg@gmail.com>
# Copyright (c) 2012, Vagrant Cascadian <vagrant@freegeek.org>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
usage() {
cat <<EOF
Usage: $0 TOOL [OPTION]
Generates or updates configuration files for certain parts of an LTSP server,
like lts.conf, the DHCP server, nbd-server etc.
Options:
-d, --directory[=DIR] A directory to search for configuration templates,
in addition to /usr/share/doc/ltsp-server/examples.
-h, --help Displays the ltsp-config help message.
-l, --language[=LANG] Preferred language for configuration files.
Support varies by distribution.
-o, --overwrite Overwrite existing configuration files.
--version Output version information and exit.
-q, --quiet Do not issue overwrite warnings
Tools:
dnsmasq Configure dnsmasq.
--no-proxy-dhcp Don't enable proxyDHCP mode for detected subnets.
isc-dhcp-server Configure isc-dhcp-server.
lts.conf Create a sample lts.conf.
nbd-server Configure nbd-server.
nfs Configure nfs exports.
EOF
}
# Replace a line matching a regex in a file with other line(s),
# or append them at the end of file if no match is found.
# Both $match and $replace must be valid sed expressions.
replace_line() {
local match replace file
match=$1
replace=$2
file=$3
test -f "$file" || die "File not found: $file"
if grep -q "$match" "$file"; then
sed "s%$match%$replace%" -i "$file"
else
printf "$replace\n" >> "$file"
fi
}
# Replace the "i386" in the example files with the default chroot name.
replace_arch() {
local conf default
conf=$1
if [ -f "$conf" ]; then
default=$(default_chroot)
if [ "$default" != "i386" ]; then
sed "s/i386/$default/" -i "$conf"
fi
else
warn "File $conf not found."
fi
}
# Check if a file exists and return error if --overwrite is not specified
check_overwrite() {
if [ "$OVERWRITE" != "true" ] && [ -f "$1" ]; then
if [ "$QUIET" != "true" ]; then
warn "File $1 exists but --overwrite was not specified."
fi
return 1
fi
return 0
}
# Copy a file from /usr/share/doc/ltsp-server/examples/$1 to $2,
# uncompressing it if necessary.
install_example() {
local src dst dstdir language sname sext dir
src=$1
dst=$2
if ! check_overwrite $dst; then
die "Aborting"
fi
dstdir=${dst%/*}
if [ ! -d "$dstdir" ]; then
die "Directory $dstdir doesn't exist, maybe the tool you want to configure isn't installed?"
fi
# Prefer localized examples, if they exist.
sname=${src%%.*}
if [ "$sname" != "$src" ]; then
sext=".${src#*.}"
fi
LANGUAGE=${LANGUAGE:-$LANG}
for dir in "$DIRECTORY" /usr/share/doc/ltsp-server/examples; do
test -d "$dir" || continue
for language in "${LANGUAGE%%:*}" "${LANGUAGE%%.*}" "${LANGUAGE%%_*}" ""; do
language=${language:+"-$language"}
if [ -f "$dir/$sname$language$sext" ]; then
cp "$dir/$sname$language$sext" "$dst"
elif [ -f "$dir/$sname$language$sext.gz" ]; then
zcat "$dir/$sname$language$sext.gz" > "$dst"
else
continue
fi
replace_arch "$dst"
echo "Created $dst"
return 0
done
done
die "Example file $src not found."
}
proxy_subnets() {
local line subnet separator
ip route show | while read line; do
subnet=${line%%/*}
case "$subnet" in
127.0.0.1|169.254.0.0|192.168.67.0|*[!0-9.]*)
# do nothing on these networks
;;
*)
# echo in dash translates "\n", use printf to keep it
printf "%s" "${separator}dhcp-range=$subnet,proxy"
# Insert a separator only after the first line
separator="\n"
;;
esac
done
}
config_dnsmasq() {
local conf
conf="/etc/dnsmasq.d/ltsp-server-dnsmasq.conf"
install_example "ltsp-server-dnsmasq.conf" "$conf"
if [ "$NO_PROXY_DHCP" != "true" ]; then
proxy_lines=$(proxy_subnets)
if [ -n "$proxy_lines" ]; then
replace_line "^#dhcp-range=.*,proxy" "$proxy_lines" "$conf"
fi
fi
service dnsmasq restart
}
config_isc_dhcp_server() {
local conf
conf="/etc/ltsp/dhcpd.conf"
install_example "dhcpd.conf" "$conf"
service isc-dhcp-server restart
}
config_lts_conf() {
local default tftpdir
default=$(default_chroot)
for tftpdir in $TFTP_DIRS ; do
if [ -d "$tftpdir/$TFTP_BOOT_DIR" ]; then
mkdir -p "$tftpdir/$TFTP_BOOT_DIR/$default"
install_example "lts.conf" "$tftpdir/$TFTP_BOOT_DIR/$default/lts.conf"
fi
done
}
config_nbd_server() {
local restart_nbd image name conf
mkdir -p "/etc/nbd-server/conf.d"
conf="/etc/nbd-server/conf.d/swap.conf"
if check_overwrite $conf; then
cat > "$conf" <<EOF
[swap]
exportname = /tmp/nbd-swap/%s
prerun = nbdswapd %s
postrun = rm -f %s
authfile = /etc/ltsp/nbd-server.allow
EOF
echo "Created $conf"
restart_nbd=true
fi
for image in $(find -L "$BASE/images/" -type f -name '*.img'); do
name=${image##*/}
name=${name%.*}
# Configuration file upgrade, remove it e.g. in 2015.
conf="/etc/nbd-server/conf.d/ltsp_$name.conf"
if [ -f "$conf" ]; then
if [ "$(sed -n '1s/\[ltsp_\(.*\)\]/\1/p' "$conf")" = "$name" ]; then
echo "Removing old configuration file $conf in order to upgrade it"
rm -f "$conf"
fi
fi
if check_overwrite $conf; then
cat >"$conf" <<EOF
[$BASE/$name]
exportname = $image
readonly = true
authfile = /etc/ltsp/nbd-server.allow
EOF
echo "Created $conf"
restart_nbd=true
fi
done
if [ "$restart_nbd" = true ]; then
# If nbd-server is already running, warn the user, else start it.
if pgrep nbd-server >/dev/null; then
warn "For nbd-server to re-read its configuration, you need to manually run:
service nbd-server restart
THIS WILL DISCONNECT ALL RUNNING CLIENTS (they'll need to be rebooted)."
elif ! { service nbd-server stop && service nbd-server start;}; then
warn "Failed to start nbd-server."
fi
fi
}
config_nfs() {
local nfs_exports nfs_line
for cfg in /etc/exports /etc/exports.d/*.exports ; do
if [ -f "${cfg}" ] && grep -q "^${BASE}" "${cfg}" ; then
# Already configured, do nothing
return 0
fi
done
nfs_exports=/etc/exports
nfs_line="${BASE} *(ro,no_root_squash,async,no_subtree_check)"
replace_line "^{BASE}.*" "${nfs_line}" "${nfs_exports}"
service nfs-kernel-server restart
}
# distro specific functions
# Keeping this separate function to clearly show it can be distro specific.
service() {
/usr/sbin/service "$@"
}
# Set an optional MODULES_BASE, so help2man can be called from build env
MODULES_BASE=${MODULES_BASE:-/usr/share/ltsp}
# This also sources vendor functions and .conf file settings
. ${MODULES_BASE}/ltsp-server-functions
if ! args=$(getopt -n "$0" -o "d:hl:oq" \
-l directory,help,language,overwrite,no-proxy-dhcp,version,quiet -- "$@")
then
exit 1
fi
eval "set -- $args"
while true ; do
case "$1" in
-d|--directory) shift; DIRECTORY=$1 ;;
-h|--help) usage; exit 0 ;;
# If we ever localize ltsp-config, LANGUAGE will also be used in
# the messages it displays, but we assume it's OK since the user
# specified it.
-l|--language) shift; LANGUAGE=$1 ;;
-o|--overwrite) OVERWRITE=true ;;
--version) ltsp_version; exit 0 ;;
--no-proxy-dhcp) NO_PROXY_DHCP=true ;;
-q|--quiet) QUIET=true ;;
--) shift ; break ;;
*) die "$0: Internal error!" ;;
esac
shift
done
case "$1" in
dnsmasq|isc-dhcp-server|lts.conf|nbd-server|nfs)
config_function=$(echo "config_$1" | tr -c "[[:alpha:]\n]" "_")
;;
*) die "$(usage)" ;;
esac
require_root
$config_function
|