Webmin and the Standard Module Choice
Have you ever woken up and wondered why people that are so smart can make such incredibly stupid choices?
Scenario
Webmin installed on OpenWRT with no "Standard module" choice from the Webmin Modules Form. Apparently that 'feature' / choice was removed a while ago with no consideration for "Generic Linux" installs. Cool. NOT!
Solution
And the code that'll do everything automatically;
WEBMIN_CONF="/etc/webmin"
WEBMIN_ROOT="$(awk -F= '$1=="root"{print $2;exit}' "$WEBMIN_CONF/miniserv.conf")"
TAG="2.020"
cd /tmp || exit 1
tar -czf "/tmp/webmin-module-backup-$(date +%Y%m%d-%H%M%S).tgz" \
-C "$WEBMIN_ROOT/webmin" \
edit_mods.cgi install_mod.cgi standard_chooser.cgi || exit 1
rm -rf "/tmp/webmin-$TAG" "/tmp/webmin-$TAG.tgz"
wget -O "/tmp/webmin-$TAG.tgz" "https://github.com/webmin/webmin/archive/refs/tags/$TAG.tar.gz" || exit 1
gzip -dc "/tmp/webmin-$TAG.tgz" | tar -xf - \
"webmin-$TAG/webmin/edit_mods.cgi" \
"webmin-$TAG/webmin/install_mod.cgi" \
"webmin-$TAG/webmin/standard_chooser.cgi" || exit 1
cp "/tmp/webmin-$TAG/webmin/edit_mods.cgi" "$WEBMIN_ROOT/webmin/edit_mods.cgi" || exit 1
cp "/tmp/webmin-$TAG/webmin/install_mod.cgi" "$WEBMIN_ROOT/webmin/install_mod.cgi" || exit 1
cp "/tmp/webmin-$TAG/webmin/standard_chooser.cgi" "$WEBMIN_ROOT/webmin/standard_chooser.cgi" || exit 1
chmod 755 \
"$WEBMIN_ROOT/webmin/edit_mods.cgi" \
"$WEBMIN_ROOT/webmin/install_mod.cgi" \
"$WEBMIN_ROOT/webmin/standard_chooser.cgi"
mkdir -p "$WEBMIN_CONF/webmin"
touch "$WEBMIN_CONF/webmin/config"
wget -O - "http://download.webmin.com/download/modules/" 2>/dev/null | \
sed -n 's/.*href="\([^"]*\.wbm\.gz\)".*/\1/p' | \
while read F; do
M="${F%.wbm.gz}"
printf "%s\t0\thttp://download.webmin.com/download/modules/%s\t*-linux\t%s\n" "$M" "$F" "$M"
done > /www/webmin-standard.txt
if grep -q '^standard_url=' "$WEBMIN_CONF/webmin/config"; then
sed -i 's|^standard_url=.*|standard_url=http://127.0.0.1/webmin-standard.txt|' "$WEBMIN_CONF/webmin/config"
else
echo 'standard_url=http://127.0.0.1/webmin-standard.txt' >> "$WEBMIN_CONF/webmin/config"
fi
/etc/init.d/webmin restart 2>/dev/null || "$WEBMIN_ROOT/restart"
grep -q '^mods_standard2=' /usr/local/webmin/webmin/lang/en && \
sed -i 's/^mods_standard2=.*/mods_standard2=Standard module/' /usr/local/webmin/webmin/lang/en || \
echo 'mods_standard2=Standard module' >> /usr/local/webmin/webmin/lang/en