<commit_before>#!/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
# <NAME>, <EMAIL>, 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##*:}
          [[ "${REPO##*/}" != ${PROD} ]] && echo -e "${ORANGE}./`basename $0`:${NC} ${REPO} does not end with /${PROD}" && exit 0
          [[ "${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
      # remove temporary files from failed run
      rm -rf .~files
      if [[ "$1" == *"-release"* ]]; then
        if [[ "$1" == *":"* ]] && [[ "$1" != *"latest"* ]]; then
          RRELEASE=${1##*:}
        else
          RRELEASE=`curl -s -L https://github.com/webmin/webmin/blob/master/version  | sed -n '/id="LC1"/s/.*">\([^<]*\).*/\1/p'`
        fi
        echo -e "${BLUE}Pulling in latest release of${NC} ${GREY}${PROD^}${NC} $RRELEASE ($HOST/$REPO)..."<commit_msg>fix REPO for sanity check<commit_after>#!/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
# <NAME>, <EMAIL>, 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##*:}
          [[ "${REPO##*/}" != ${PROD} ]] && echo -e "${ORANGE}./`basename $0`:${NC} ${REPO} does not end with /${PROD}" && exit 0
          [[ "${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
      # remove temporary files from failed run
      rm -rf .~files
      if [[ "$1" == *"-release"* ]]; then
        if [[ "$1" == *":"* ]] && [[ "$1" != *"latest"* ]]; then
          RRELEASE=${1##*:}
        else
          RRELEASE=`curl -s -L https://github.com/${REPO}/blob/master/version  | sed -n '/id="LC1"/s/.*">\([^<]*\).*/\1/p'`
        fi
        echo -e "${BLUE}Pulling in latest release of${NC} ${GREY}${PROD^}${NC} $RRELEASE ($HOST/$REPO)..."
{'fraction_non_alphanumeric': 0.28204353083434097, 'fraction_numerical': 0.02539298669891173, 'mean_word_length': 3.236235595390525, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2055166', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2363, 'n_words': 617}