From d220823080509aebb68963a594c5832142632c38 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 19 May 2017 14:45:57 +0200 Subject: [PATCH 1/9] Update webmin/usermin in place from github.com repo --- update-from-repo.sh | 194 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100755 update-from-repo.sh diff --git a/update-from-repo.sh b/update-from-repo.sh new file mode 100755 index 000000000..de26028cd --- /dev/null +++ b/update-from-repo.sh @@ -0,0 +1,194 @@ +#!/usr/bin/env bash +############################################################################# +# Update webmin/usermin to the latest develop version from GitHub repo +# inspired by authentic-theme/theme-update.sh script, thanks qooob +# +# Version 1.0, 2017-05-19 +# Kay Marquardt, kay@rrr.de, https://github.com/gandelwartz +############################################################################# + +# Get webmin/usermin dir based on script's location +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROD=${DIR##*/} # => usermin or webmin +# where to get source +HOST="https://github.com" +REPO="webmin/$PROD" + +ASK="YES" + +# temporary locations for git clone +WTEMP="${DIR}/.~files/webadmin" +UTEMP="${DIR}/.~files/useradmin" +TEMP=$WTEMP +[[ "$PROD" == "usermin" ]] && TEMP=$UTEMP + +# predefined colors for echo -e +RED='\e[49;0;31;82m' +BLUE='\e[49;1;34;182m' +GREEN='\e[49;32;5;82m' +ORANGE='\e[49;0;33;82m' +PURPLE='\e[49;1;35;82m' +LGREY='\e[49;1;37;182m' +GREY='\e[1;30m' +NC='\e[0m' + + +# help requested output usage +if [[ "$1" == "-h" || "$1" == "--help" ]] ; then + echo -e "${NC}${ORANGE}${PROD^}${NC} update script" + echo "Usage: ./`basename $0` { [-lang] } { [-repo:yourname/xxxmin] } { [-release] | [-release:number] }" + exit 0 +fi + +# dont ask -y given +if [[ "$1" == "-y" || "$1" == "-yes" ]] ; then + ASK="NO" + shift +fi + +# update onyl lang files +if [[ "$1" == "-l" || "$1" == "-lang" ]] ; then + LANG="YES" + shift +fi + +################ +# lets start +# Clear screen for better readability +[[ "${ASK}" == "YES" ]] && clear + +# alternative repo given +if [[ "$1" == *"-repo"* ]]; then + if [[ "$1" == *":"* ]] ; then + REPO=${1##*:} + [[ "${ASK}" == "YES" ]] && echo -e "${RED}Warning:${NC} ${ORANGE}using alternate repository${NC} $HOST/$REPO ${ORANGE}may break your installation!${NC}" + shift + else + echo -e "${ORANGE}./`basename $0`:${NC} found -repo without parameter" + exit 0 + fi +fi + +# warn about possible side effects because webmins makedist.pl try cd to /usr/local/webmin (and more) +[[ -d "/usr/local/webadmin" ]] && echo -e "${RED}Warning:${NC} /usr/local/webadmin ${ORANGE}exist, update may fail!${NC}" + +################ +# really update? +REPLY="y" +[ "${ASK}" == "YES" ] && read -p "Would you like to update "${PROD^}" from ${HOST}/${REPO} [y/N] " -n 1 -r && echo + +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + # something different the y entered + echo -e "${PURPLE}Operation aborted.${NC}" + exit +fi + +################ +# here we go +# need to be root and git installed +if [[ $EUID -eq 0 ]]; then + if type git >/dev/null 2>&1 + then + + ################# + # pull source from github + if [[ "$1" == *"-release"* ]]; then + if [[ "$1" == *":"* ]] && [[ "$1" != *"latest"* ]]; then + RRELEASE=${1##*:} + else + RRELEASE=`curl -s -L https://raw.githubusercontent.com/$REPO/master/version` + fi + echo -e "${BLUE}Pulling in latest release of${NC} ${GREY}${PROD^}${NC} $RRELEASE ($HOST/$REPO)..." + RS="$(git clone --depth 1 --branch $RRELEASE -q $HOST/$REPO.git "${TEMP}" 2>&1)" + if [[ "$RS" == *"ould not find remote branch"* ]]; then + ERROR="Release ${RRELEASE} doesn't exist. " + fi + else + echo -e "${BLUE}Pulling in latest changes for${NC} ${GREY}${PROD^}${NC} $RRELEASE ($HOST/$REPO) ..." + git clone --depth 1 --quiet $HOST/$REPO.git "${TEMP}" + fi + # on usermin!! pull also webmin to resolve symlinks later! + WEBMREPO=`echo ${REPO} | sed "s/\/usermin$/\/webmin/"` + if [[ "${REPO}" != "${WEBMREPO}" ]]; then + echo -e "${BLUE}Pulling in latest changes for${NC} ${GREY}Webmin${NC} ($HOST/$WEBMREPO) ..." + git clone --depth 1 --quiet $HOST/$WEBMREPO.git "${WTEMP}" + fi + + # Check for possible errors + if [ $? -eq 0 ] && [ -f "${TEMP}/version" ]; then + + #################### + # start processing pulled source + version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%Y%m%d.%H%M%S'`" >>${TEMP}/version + if [[ "${LANG}" != "YES" ]]; then + ############### + # FULL update + echo -e "${GREEN}start FULL update for${NC} $PROD ..." + # create dir,resolve links and some other processing + mkdir ${TEMP}/tarballs + ( cd ${TEMP}; perl makedist.pl ${version} ) 2>/dev/null + + #prepeare unattended upgrade + config_dir=/etc/${PROD} + atboot="NO" + makeboot="NO" + nouninstall="YES" + nostart="YES" + export config_dir atboot nouninstall makeboot nostart + ${TEMP}/tarballs/${PROD}-${version}/setup.sh ${DIR} | grep -v -e "^$" -e "done$" + + else + ################ + # LANG only update + IGNORE="authentic-theme" + echo -e "${GREEN}start updating LANG files for${NC} ${RPOD} ... ${LGREY}.=dir s=symlink S=dir symlink${NC}" + + # list all lang singe-files, lang dirs and linked modules here + for FILE in `ls -d */lang */ulang */config.info.* */module.info filemin 2>/dev/null` + do + MODUL=`dirname $FILE`; SKIP=`echo $MODUL | sed "s/$IGNORE/SKIP/"` + if [ "$SKIP" == "SKIP" ]; then + echo -e "${LGREY}skipping $MODUL ...${NC}" + else + # real files and dirs + [ -f "${TEMP}/${FILE}" ] && [ -f "$DIR/$FILE" ] && cp "${TEMP}/${FILE}" "$DIR/$FILE" && continue + [ -d "${TEMP}/${FILE}" ] && [ -d "$DIR/$FILE" ] && cp -r "${TEMP}/${FILE}" "$DIR/$MODUL" && \ + echo -n "." && continue + # to webmin symlinked files and dirs + if [ -h "${TEMP}/${FILE}" ]; then + # get real symlink source + SOURCE=`readlink .~files/$FILE | sed 's/.*web.*min\///'` + [ -f "$DIR/$FILE" ] && cp "${WTEMP}/"$DIR/$FILE"${FILE}" "$DIR/$SOURCE" && echo -n "s" && continue + [ -d "$DIR/$FILE" ] && cp -r "${WTEMP}/$SOURCE" "$DIR/$MODUL" && echo -n "S" + fi + fi + done + # write version to file + echo "${version}-LANG" > version + fi + + echo -e "\n${GREEN}Updating ${PROD^} to Version `cat version`, done.${NC}" + + # update authentic, put dummy clear in PATH + echo -e "#!/bin/sh\necho" > ${TEMP}/clear; chmod +x ${TEMP}/clear + export PATH="${TEMP}:${PATH}" + [[ -x authentic-theme/theme-update.sh ]] && authentic-theme/theme-update.sh + + else + # something went wrong + echo -e "${RED}${ERROR}Updating files, failed.${NC}" + fi + ########### + # we are at the end + # remove temporary files + rm -rf .~files + # fix permissions, should be done by makedist.pl? + chmod -R -x+X ${DIR} + find ${DIR} \( -iname "*.pl" -o -iname "*.cgi" -o -iname "*.pm" -o -iname "*.sh" \) -a ! -iname "config*info" | \ + xargs chmod +x + else + echo -e "${RED}Error: Command \`git\` is not installed or not in the \`PATH\`.${NC}"; + fi +else + echo -e "${RED}Error: This command has to be run under the root user.${NC}" +fi From 0c25d52a6d9b919d76a33d11378406943b473c0c Mon Sep 17 00:00:00 2001 From: Kay Marquardt Date: Fri, 19 May 2017 15:05:09 +0200 Subject: [PATCH 2/9] shorten version nuber created from last commit date --- update-from-repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-from-repo.sh b/update-from-repo.sh index de26028cd..764db0db2 100755 --- a/update-from-repo.sh +++ b/update-from-repo.sh @@ -119,7 +119,7 @@ if [[ $EUID -eq 0 ]]; then #################### # start processing pulled source - version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%Y%m%d.%H%M%S'`" >>${TEMP}/version + version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%m%d.%H%M'`" >>${TEMP}/version if [[ "${LANG}" != "YES" ]]; then ############### # FULL update From 5e5a7b9cc3508c0035f152fdd81c94e9aa56cf15 Mon Sep 17 00:00:00 2001 From: Kay Marquardt Date: Fri, 19 May 2017 16:05:15 +0200 Subject: [PATCH 3/9] forgot lang and ulang when updateing lang files only --- update-from-repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-from-repo.sh b/update-from-repo.sh index 764db0db2..fc1bc2567 100755 --- a/update-from-repo.sh +++ b/update-from-repo.sh @@ -144,7 +144,7 @@ if [[ $EUID -eq 0 ]]; then echo -e "${GREEN}start updating LANG files for${NC} ${RPOD} ... ${LGREY}.=dir s=symlink S=dir symlink${NC}" # list all lang singe-files, lang dirs and linked modules here - for FILE in `ls -d */lang */ulang */config.info.* */module.info filemin 2>/dev/null` + for FILE in `ls -d lang */lang ulang */ulang */config.info.* */module.info filemin 2>/dev/null` do MODUL=`dirname $FILE`; SKIP=`echo $MODUL | sed "s/$IGNORE/SKIP/"` if [ "$SKIP" == "SKIP" ]; then From 01165959d3294e77e4952bb355552301dac6f20d Mon Sep 17 00:00:00 2001 From: Kay Marquardt Date: Fri, 19 May 2017 17:12:19 +0200 Subject: [PATCH 4/9] remove obsolete redirect to file --- update-from-repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-from-repo.sh b/update-from-repo.sh index fc1bc2567..60befb286 100755 --- a/update-from-repo.sh +++ b/update-from-repo.sh @@ -119,7 +119,7 @@ if [[ $EUID -eq 0 ]]; then #################### # start processing pulled source - version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%m%d.%H%M'`" >>${TEMP}/version + version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%m%d.%H%M'`" if [[ "${LANG}" != "YES" ]]; then ############### # FULL update From b047220417e9cd13aae587ef1a9425cdb72fd74f Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 20 May 2017 10:26:43 +0200 Subject: [PATCH 5/9] check for additional standard modules eg majordomo --- update-from-repo.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/update-from-repo.sh b/update-from-repo.sh index 60befb286..69b0f2ebc 100755 --- a/update-from-repo.sh +++ b/update-from-repo.sh @@ -119,7 +119,7 @@ if [[ $EUID -eq 0 ]]; then #################### # start processing pulled source - version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%m%d.%H%M'`" + version="`head -c -1 ${TEMP}/version`.`cd ${TEMP}; git log -1 --format=%cd --date=format:'%m%d.%H%M'`" if [[ "${LANG}" != "YES" ]]; then ############### # FULL update @@ -128,6 +128,16 @@ if [[ $EUID -eq 0 ]]; then mkdir ${TEMP}/tarballs ( cd ${TEMP}; perl makedist.pl ${version} ) 2>/dev/null + # check for additional standard modules + # fixed list better than guessing? + for module in `ls */module.info` + do + if [[ -f ${TEMP}/${module} && ! -f "${TEMP}/tarballs/${PROD}-${version}/$module" ]]; then + module=`dirname $module` + echo "Adding module $module" && cp -r -L ${TEMP}/$module ${TEMP}/tarballs/${PROD}-${version}/ + fi + done + #prepeare unattended upgrade config_dir=/etc/${PROD} atboot="NO" @@ -144,7 +154,7 @@ if [[ $EUID -eq 0 ]]; then echo -e "${GREEN}start updating LANG files for${NC} ${RPOD} ... ${LGREY}.=dir s=symlink S=dir symlink${NC}" # list all lang singe-files, lang dirs and linked modules here - for FILE in `ls -d lang */lang ulang */ulang */config.info.* */module.info filemin 2>/dev/null` + for FILE in `ls -d */lang */ulang */config.info.* */module.info filemin 2>/dev/null` do MODUL=`dirname $FILE`; SKIP=`echo $MODUL | sed "s/$IGNORE/SKIP/"` if [ "$SKIP" == "SKIP" ]; then From 594a874a4b519a20e03e1e82186868722c534820 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 20 May 2017 17:58:58 +0200 Subject: [PATCH 6/9] on iso-8859 try a second guess --- filemin/edit_file.cgi | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/filemin/edit_file.cgi b/filemin/edit_file.cgi index 8ec81bee2..caaa3c4d5 100755 --- a/filemin/edit_file.cgi +++ b/filemin/edit_file.cgi @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl require './filemin-lib.pl'; &ReadParse(); @@ -10,9 +10,18 @@ my $file = &simplify_path($cwd.'/'.$in{'file'}); my $data = &read_file_contents($file); my $encoding_name; +use Encode::Guess; eval "use Encode::Detect::Detector;"; if (!$@) { $encoding_name = Encode::Detect::Detector::detect($data); + if ( $encoding_name =~ /iso-8859/i ) { + # try a second guess + my $dec = guess_encoding($data, qw/iso-8859-1 iso-8859-2 iso-8859-3 iso-8859-3 iso-8859-4 iso-8859-5 iso-8859-6 iso-8859-7 iso-8859-8 iso-8859-9/); + if (!ref $dec) { + # can be more than one iso-encoding, fallback to iso-8859-1 + $encoding_name = "iso-8859-1"; + } + } } if ( lc( get_charset() ) eq "utf-8" && ( $encoding_name && lc($encoding_name) ne "utf-8" ) ) { use Encode qw( encode decode ); From 7e9905ce3c20a74c42fe43494f77fa149ceaf963 Mon Sep 17 00:00:00 2001 From: Kay Marquardt Date: Sat, 20 May 2017 18:04:23 +0200 Subject: [PATCH 7/9] revert edit-file.cgi wrong repo --- filemin/edit_file.cgi | 9 --------- 1 file changed, 9 deletions(-) diff --git a/filemin/edit_file.cgi b/filemin/edit_file.cgi index caaa3c4d5..8635c0e86 100755 --- a/filemin/edit_file.cgi +++ b/filemin/edit_file.cgi @@ -10,18 +10,9 @@ my $file = &simplify_path($cwd.'/'.$in{'file'}); my $data = &read_file_contents($file); my $encoding_name; -use Encode::Guess; eval "use Encode::Detect::Detector;"; if (!$@) { $encoding_name = Encode::Detect::Detector::detect($data); - if ( $encoding_name =~ /iso-8859/i ) { - # try a second guess - my $dec = guess_encoding($data, qw/iso-8859-1 iso-8859-2 iso-8859-3 iso-8859-3 iso-8859-4 iso-8859-5 iso-8859-6 iso-8859-7 iso-8859-8 iso-8859-9/); - if (!ref $dec) { - # can be more than one iso-encoding, fallback to iso-8859-1 - $encoding_name = "iso-8859-1"; - } - } } if ( lc( get_charset() ) eq "utf-8" && ( $encoding_name && lc($encoding_name) ne "utf-8" ) ) { use Encode qw( encode decode ); From 7df549f91d96fc153c381360d347b48750fae16a Mon Sep 17 00:00:00 2001 From: Kay Marquardt Date: Sat, 20 May 2017 18:04:45 +0200 Subject: [PATCH 8/9] Update edit_file.cgi --- filemin/edit_file.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filemin/edit_file.cgi b/filemin/edit_file.cgi index 8635c0e86..0480b46c4 100755 --- a/filemin/edit_file.cgi +++ b/filemin/edit_file.cgi @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/loacl/bin/perl require './filemin-lib.pl'; &ReadParse(); From e4738380e1945440a3172474aca9f5677a14532d Mon Sep 17 00:00:00 2001 From: Kay Marquardt Date: Sat, 20 May 2017 18:05:06 +0200 Subject: [PATCH 9/9] Update edit_file.cgi --- filemin/edit_file.cgi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filemin/edit_file.cgi b/filemin/edit_file.cgi index 0480b46c4..8ec81bee2 100755 --- a/filemin/edit_file.cgi +++ b/filemin/edit_file.cgi @@ -1,4 +1,4 @@ -#!/usr/loacl/bin/perl +#!/usr/local/bin/perl require './filemin-lib.pl'; &ReadParse();