Skip to content

Commit 0315e4c

Browse files
committed
Add ability to migrate Webmin monolithic to modular, while keeping enabled modules
1 parent dcf36dd commit 0315e4c

File tree

1 file changed

+121
-4
lines changed

1 file changed

+121
-4
lines changed

virtualmin-install.sh

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ VER=8.1.1
1414
vm_version=8
1515

1616
# Server
17+
download_old_virtualmin_host="software.virtualmin.com"
1718
download_virtualmin_host="${download_virtualmin_host:-download.virtualmin.com}"
1819
download_virtualmin_host_lib="$download_virtualmin_host"
1920
download_virtualmin_host_dev="${download_virtualmin_host_dev:-download.virtualmin.dev}"
@@ -650,6 +651,26 @@ pre_check_http_client() {
650651
fi
651652
}
652653

654+
# Function to download content using available HTTP client
655+
download_content() {
656+
url="$1"
657+
658+
if command -v curl >/dev/null 2>&1; then
659+
curl -fsSL "$url" 2>/dev/null && return 0
660+
fi
661+
662+
if command -v wget >/dev/null 2>&1; then
663+
wget -qO- "$url" 2>/dev/null && return 0
664+
fi
665+
666+
if command -v fetch >/dev/null 2>&1; then
667+
fetch -qo - "$url" 2>/dev/null && return 0
668+
fi
669+
670+
return 1
671+
}
672+
673+
# Download slib.sh utility library
653674
download_slib() {
654675
# If slib.sh is available locally in the same directory use it
655676
if [ -f "$pwd/slib.sh" ]; then
@@ -746,6 +767,32 @@ write_virtualmin_branch() {
746767
printf '%s\n' "$vm_version" >>"$branch_file" 2>/dev/null || :
747768
}
748769

770+
# Check for old Virtualmin repo presence
771+
is_old_virtualmin_repo() {
772+
773+
# Check for old Virtualmin repo presence by looking for known host in existing
774+
# repo configs
775+
host="$download_old_virtualmin_host"
776+
777+
# Check dnf repos
778+
for d in /etc/yum.repos.d /etc/dnf/repos.d; do
779+
[ -d "$d" ] || continue
780+
if grep -RqsE "(^|[[:space:]])(baseurl|mirrorlist)=.*${host}" "$d"; then
781+
return 0
782+
fi
783+
done
784+
785+
# Check apt sources
786+
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
787+
[ -f "$f" ] || continue
788+
if grep -qsE "^[[:space:]]*deb[[:space:]].*${host}" "$f"; then
789+
return 0
790+
fi
791+
done
792+
793+
return 1
794+
}
795+
749796
# Configure Virtualmin repositories (stable, prerelease, or unstable) and keep
750797
# matching Webmin repositories in sync.
751798
manage_virtualmin_branch_repos() {
@@ -1825,11 +1872,81 @@ preconfigure_virtualmin_release() {
18251872
# Setup repos only
18261873
if [ -n "$setup_only" ]; then
18271874
if preconfigure_virtualmin_release; then
1828-
manage_virtualmin_branch_repos
1829-
log_success "Virtualmin repository is configured successfully."
1875+
1876+
# If old Virtualmin repo found, fetch Webmin migrate modular script and
1877+
# capture currently used modules before making any changes
1878+
migrate_script="" mods_file=""
1879+
if is_old_virtualmin_repo; then
1880+
# If migrate-modular.sh is available locally in the same directory use it
1881+
if [ -f "$pwd/migrate-modular.sh" ]; then
1882+
migrate_script="$pwd/migrate-modular.sh"
1883+
# Otherwise download it
1884+
else
1885+
migrate_url="https://$download_virtualmin_host/migrate"
1886+
case "$branch" in
1887+
unstable)
1888+
migrate_url="https://$download_virtualmin_host_dev/migrate"
1889+
;;
1890+
prerelease)
1891+
migrate_url="https://$download_virtualmin_host_rc/migrate"
1892+
;;
1893+
esac
1894+
1895+
migrate_script=$(mktemp)
1896+
download_content "$migrate_url" > "$migrate_script" 2>/dev/null
1897+
if [ ! -s "$migrate_script" ]; then
1898+
rm -f "$migrate_script"
1899+
migrate_script=""
1900+
fi
1901+
fi
1902+
1903+
# Source and capture modules
1904+
if [ -n "$migrate_script" ] && [ -s "$migrate_script" ]; then
1905+
# shellcheck disable=SC1090
1906+
. "$migrate_script"
1907+
mods_file=$(pre_migration_capture "$download_old_virtualmin_host")
1908+
if [ -n "$mods_file" ] && [ -s "$mods_file" ]; then
1909+
mods_list=$(tr '\n' ' ' < "$mods_file" | sed 's/ $//')
1910+
log_debug "Captured Webmin modules to file: $mods_file ($mods_list)"
1911+
fi
1912+
fi
1913+
fi
1914+
1915+
# Setup repos for the selected branch
1916+
if manage_virtualmin_branch_repos; then
1917+
log_success "Virtualmin repository is configured successfully."
1918+
else
1919+
log_error "Error occurred during setup of Virtualmin repository."
1920+
log_error "You may find more information in ${RUN_LOG}."
1921+
exit 1
1922+
fi
1923+
1924+
# Apply Webmin package migration if the old repo is installed
1925+
if [ -n "$migrate_script" ] && [ -n "$mods_file" ] && \
1926+
[ -s "$mods_file" ]; then
1927+
migrate_host="$download_virtualmin_host"
1928+
case "$branch" in
1929+
prerelease) migrate_host="$download_virtualmin_host_rc" ;;
1930+
unstable) migrate_host="$download_virtualmin_host_dev" ;;
1931+
esac
1932+
msg="Migrating Webmin to modular packages and restoring enabled modules"
1933+
if run_ok "post_migration_apply '$mods_file' '$migrate_host'" "$msg"; then
1934+
log_success "Webmin migration completed successfully."
1935+
else
1936+
log_warning "Webmin migration failed. You may need to migrate manually."
1937+
fi
1938+
1939+
# Only remove if downloaded, not local
1940+
[ "$migrate_script" != "$pwd/migrate-modular.sh" ] && \
1941+
rm -f "$migrate_script"
1942+
# Remove if downloaded but failed to capture modules
1943+
elif [ -n "$migrate_script" ] && \
1944+
[ "$migrate_script" != "$pwd/migrate-modular.sh" ]; then
1945+
rm -f "$migrate_script"
1946+
fi
18301947
else
1831-
log_error "Errors occurred during setup of Virtualmin software repositories. You may find more"
1832-
log_error "information in ${RUN_LOG}."
1948+
log_error "Error occurred during setup of Virtualmin repository."
1949+
log_error "You may find more information in ${RUN_LOG}."
18331950
fi
18341951
exit $?
18351952
fi

0 commit comments

Comments
 (0)