From 96ca7643e8e651604bab6dd948b7f3ab68280d05 Mon Sep 17 00:00:00 2001 From: whitone Date: Sun, 3 Feb 2008 21:50:36 +0000 Subject: [PATCH] Added "easy-update". --- easy-update | 763 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 763 insertions(+) create mode 100644 easy-update diff --git a/easy-update b/easy-update new file mode 100644 index 0000000..74f43bb --- /dev/null +++ b/easy-update @@ -0,0 +1,763 @@ +#!/bin/bash + +# easy-update - Copyright 2008 Stefano Cotta Ramusino. +# ==================================================== +# Written by Stefano Cotta Ramusino, January 2008. +# Modified by Stefano Cotta Ramusino, February 2008. +# +# 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, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function show_copyright() +{ + + echo "This program is free software; you can redistribute it and/or modify it" 2> /dev/null + echo "under the terms of the GNU General Public License version 2 as published" 2> /dev/null + echo "by the Free Software Foundation. There is NO warranty; not even for" 2> /dev/null + echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 2> /dev/null + +} + +function show_version() +{ + + echo "$myself $cygeasy_version" 2> /dev/null + echo "Copyright (C) 2008 Stefano Cotta Ramusino " 2> /dev/null + +} + +function show_help() +{ + + show_version 2> /dev/null + echo 2> /dev/null + echo "Automatically update Cygwin Easy and let install Cygwin packages." 2> /dev/null + echo 2> /dev/null + echo "Usage:" 2> /dev/null + echo "$myself [--freeze]" 2> /dev/null + echo 2> /dev/null + echo "where the above options mean:" 2> /dev/null + echo " --freeze Congelate current state of Cygwin Easy to let copy it in a" 2> /dev/null + echo " read-only disk" 2> /dev/null + echo 2> /dev/null + echo "Report bugs to ." 2> /dev/null + +} + +function update_conf() +{ + + cat > /etc/$myself.conf << EOF +# easy-update configuration file + +self_update=$self_update +self_dir="$self_dir" +self_files=(${self_files[@]}) + +setup_update=$setup_update +setup_version="$setup_version" +setup_url="$setup_url" +setup_download_url="$setup_download_url" +setup_default_url="$setup_default_url" + +console_update=$console_update +console_dir="$console_dir" +console_version="$console_version" +console_url="$console_url" +console_download_url="$console_download_url" + +cygeasy_update=$cygeasy_update +cygeasy_version="$cygeasy_version" +cygeasy_files=(${cygeasy_files[@]}) +cygeasy_download_url="$cygeasy_download_url" +cygeasy_custom=$cygeasy_custom + +readme_update=$readme_update +readme_files=(${readme_files[@]}) +pkglist_update=$pkglist_update +autoplay_update=$autoplay_update +EOF + +} + +function freeze_now() +{ + + [ ! -e /etc/postinstall/cygwin-easy.sh.done ] && [ ! -e /etc/postinstall/cygwin-easy.sh ] && + { echo -e "Postinstall script of 'cygwin-easy' package is missing.\nPlease reinstall the package." >&2; exit 1; } + + echo -en "\nFreeze process can take few minutes. Please wait ... " 2> /dev/null + + retval=1 + + if [ -e /etc/postinstall/cygwin-easy.sh.done ] + then + chmod +x /etc/postinstall/cygwin-easy.sh.done &> /dev/null + /etc/postinstall/cygwin-easy.sh.done --force + retval=$? + else + if [ -e /etc/postinstall/cygwin-easy.sh ] + then + chmod +x /etc/postinstall/cygwin-easy.sh &> /dev/null + /etc/postinstall/cygwin-easy.sh + retval=$? + fi + fi + + if [ "$retval" == "0" ] + then + echo -e "\n'Cygwin Easy $cygeasy_version' is now ready to be copied in a read-only disk." 2> /dev/null + else + echo -e "\nSome errors occurred." >&2 + fi + +} + +function auto_update() +{ + + echo "New version of '$myself' downloaded. Automatic restart of '$myself'." 2> /dev/null + echo "mv -f $self_dir/$myself $(which $myself)" > "$self_dir/autoupdate" 2> /dev/null + echo "exec $(which $myself)" >> "$self_dir/autoupdate" 2> /dev/null + chmod +x $self_dir/autoupdate &> /dev/null + echo 2> /dev/null + exec $self_dir/autoupdate $@ + +} + +function update_myself() +{ + + echo -n "Searching for a new version of '$myself' ... " 2> /dev/null + curl -L -f -z "$(which $myself 2> /dev/null)" -o "$self_dir/$myself" \ + "$cygeasy_download_url/$myself" &> /dev/null + let "retval = $?" + if [ -e "$self_dir/$myself" ] + then + case "$retval" in + 0) echo "found!" 2> /dev/null + auto_update + echo "Automatic update of '$myself' failed" >&2 ;; + 7) echo "failed to connect to host" >&2 ;; + *) echo "curl error (exit code: $retval)" >&2 ;; + esac + else + echo "not found." 2> /dev/null + fi + +} + +function differ() +{ + + retcode=$(du -b "$1" "$2" 2> /dev/null | \ + cut -f1 2> /dev/null | uniq 2> /dev/null | wc -l 2> /dev/null) + case "$retcode" in + 1) return 0 ;; + 2) return 1 ;; + *) return -1 ;; + esac + return -1 + +} + +function update_cygeasy() +{ + + local file latest_file new_version + + [ ! -e "$self_dir/cache" ] && mkdir -p "$self_dir/cache" &> /dev/null + + pushd "$cygeasy_dir" &> /dev/null + for file in ${cygeasy_files[*]} + do + rm -f $self_dir/cache/$file &> /dev/null + if [[ ! -e "$file" || "$ask_all" ]] + then + answer= + echo -ne "\nDo you want to download '$file' in '$cygeasy_dir' [Y/n]? " 2> /dev/null + read -n1 answer &> /dev/null + echo 2> /dev/null + [[ "$answer" == "n" || "$answer" == "N" ]] && continue + fi + echo -n "Searching for a new version of '$file' ... " 2> /dev/null + curl -L -f -z $file -o $self_dir/cache/$file \ + $cygeasy_download_url/$file &> /dev/null + let "retval = $?" + if [ -e "$self_dir/cache/$file" ] + then + case "$retval" in + 0) echo "found!" 2> /dev/null + mv -f "$self_dir/cache/$file" "$file" &> /dev/null + let "retval2 = $?" + if [ "$retval2" == "0" ] + then + echo "File '$file' updated." 2> /dev/null + rm -f "$self_dir/cache/$file" &> /dev/null + else + echo "Error updating file '$file': mv error (exit code: $retval2)" >&2 + fi ;; + 7) echo "failed to connect to host" >&2 ;; + *) echo "curl error (exit code: $retval)" >&2 ;; + esac + else + echo "not found." 2> /dev/null + fi + if [ "$file" == "autorun.bat" || "$file" == "changelog.txt" ] + then + [ "$new_version" ] || new_version=$(date '+%s' -r $file 2> /dev/null) + [ "$latest_file" ] || latest_file=$file + if [ $new_version -lt $(date '+%s' -r $file 2> /dev/null) ] + then + new_version=$(date '+%s' -r $file 2> /dev/null) + latest_file=$file + fi + fi + done + popd &> /dev/null + + unset file &> /dev/null + + pushd "$self_dir" &> /dev/null + for file in ${self_files[*]} + do + echo -n "Searching for a new version of '$file' ... " 2> /dev/null + curl -L -f -z $file -o cache/$file \ + $cygeasy_download_url/cygwin-easy/usr/share/cygwin-easy/$file &> /dev/null + let "retval = $?" + if [ -e "cache/$file" ] + then + case "$retval" in + 0) echo "found!" 2> /dev/null + mv -f "cache/$file" "$file" &> /dev/null + let "retval2 = $?" + if [ "$retval2" == "0" ] + then + echo "File '$file' updated." 2> /dev/null + rm -f "cache/$file" &> /dev/null + else + echo "Error updating file '$file': mv error (exit code: $retval2)" >&2 + fi ;; + 7) echo "failed to connect to host" >&2 ;; + *) echo "curl error (exit code: $retval)" >&2 ;; + esac + else + echo "not found." 2> /dev/null + fi + if [ $new_version -lt $(date '+%s' -r $file 2> /dev/null) ] + then + new_version=$(date '+%s' -r $file 2> /dev/null) + latest_file=$file + fi + done + [ -e "cache" ] && rm -fr "cache" &> /dev/null + popd &> /dev/null + + [[ $new_version -lt $(date '+%s' -r $(which $myself 2> /dev/null)) ]] && + latest_file=$(which $myself 2> /dev/null) + + if [ -e "$cygeasy_dir/$latest_file" ] + then + new_version="$(date '+%Y.%m.%d' -r $cygeasy_dir/$latest_file)" + else + if [ -e "$self_dir/$latest_file" ] + then + new_version="$(date '+%Y.%m.%d' -r $self_dir/$latest_file)" + else + new_version="$(date '+%Y.%m.%d' -r $latest_file)" + fi + fi + + unset file latest_file + if [ "$cygeasy_version" != "$new_version" ] + then + cygeasy_version="$new_version" + update_conf + fi + +} + +function install_console() +{ + + unzip -ujoqq $self_dir/console.zip -d $console_full_dir &> /dev/null + let "retval = $?" + if [ $retval -eq 0 ] + then + console_version=$last_version + update_conf + for file in "$console_full_dir/*" + do + mv -f $file $(echo $file 2> /dev/null | tr A-Z a-z 2> /dev/null) &> /dev/null + done + [ "$1" == "1" ] && echo "Latest Console already downloaded." 2> /dev/null + [ "$1" == "" ] && echo "Console updated." 2> /dev/null + rm -fr $self_dir/$(basename $console_full_dir 2> /dev/null) &> /dev/null + rm -f $self_dir/console.zip &> /dev/null + echo -n "Customizing 'Console' preferences file for Cygwin Easy ... " 2> /dev/null + cygwin_dir=$(mount 2> /dev/null | grep ' / ' 2> /dev/null | cut -f1 -d' ' 2> /dev/null | \ + cut -f2 -d: 2> /dev/null | sed "s,\\\,\\\\\\\\,g" 2> /dev/null) + awk ' + BEGIN { code=112 } + /window title/ { + gsub("Console","Cygwin Easy") + gsub("icon=\"\"","icon=\"$cygwin_dir\\usr\\share\\icons\\cygwin.ico\"") + } + /command="exit"/ { $0=$1 " ctrl=\"1\" shift=\"0\" alt=\"0\" extended=\"0\" code=\"8\" " $7 } + /command="switchtab/ { $0=$1 " ctrl=\"0\" shift=\"0\" alt=\"1\" extended=\"0\" code=\"" code++ "\" " $7 } + /tab title/ { gsub("Console2\"","Cygwin Easy\" icon=\"$cygwin_dir\\usr\\share\\icons\\cygwin.ico\"") } + /console shell/ { $0=" $console_full_dir/console.xml.cygwin-easy 2> /dev/null + let "retval = $?" + if [[ "$retval" == "0" && -e "$console_full_dir/console.xml.cygwin-easy" ]] + then + mv -f "$console_full_dir/console.xml.cygwin-easy" "$console_full_dir/console.xml" &> /dev/null + u2d "$console_full_dir/console.xml" &> /dev/null + echo "done!" 2> /dev/null + else + echo "an error occurred (exit code: $retval)" >&2 + fi + rm -f "$console_full_dir/console.xml.cygwin-easy" &> /dev/null + else + echo "unzip error (exit code: $retval)" >&2 + fi + return $retval + +} + +function update_tools() +{ + + local last_version + + [ "$setup_update" ] || setup_update=1 + + if [[ "$setup_update" == "1" || ! -e $self_dir/setup.exe ]] + then + + echo -n "Searching for a new version of Cygwin setup utility ... " 2> /dev/null + + [ "$setup_url" ] || + setup_url="http://cygwin.com/setup/snapshots/?C=M;O=D" + + last_version=$(curl -s -L "$setup_url" 2> /dev/null | \ + grep -im1 'href="setup-[0-9\.]*\.exe"' 2> /dev/null | \ + sed "s,.*setup-\([0-9\.]*\)\.exe.*,\1,i" 2> /dev/null) + + [ "$last_version" ] || echo "not found." + + [ "$last_version" ] && + if [[ ! -e $self_dir/setup.exe || "$last_version" != "$setup_version" ]] + then + echo "found!" 2> /dev/null + [ "$setup_download_url" ] || + setup_download_url="http://cygwin.com/setup/snapshots" + [ -e $self_dir/setup.exe ] && setup_exist=1 + cp -f $self_dir/setup.exe $self_dir/setup.exe.backup &> /dev/null + echo "Download version $last_version" 2> /dev/null + curl -L -f -# -o $self_dir/setup.exe \ + $setup_download_url/setup-$last_version.exe > /dev/null + let "retval = $?" + case "$retval" in + 0) setup_version=$last_version + update_conf + echo "Cygwin setup utility updated." 2> /dev/null + rm -f $self_dir/setup.exe.backup &> /dev/null ;; + 18) if [ "$setup_exist" ] + then + setup_version=$last_version + update_conf + echo "Latest Cygwin setup utility already downloaded." 2> /dev/null + rm -f $self_dir/setup.exe.backup &> /dev/null + fi ;; + esac + cp -f $self_dir/setup.exe.backup $self_dir/setup.exe &> /dev/null + else + echo "not found." 2> /dev/null + fi + + fi + + [ "$console_update" ] || console_update=1 + + if [ "$console_update" == "1" ] + then + + [ $(type -f unzip &> /dev/null; echo $?) -eq 0 ] || return + + unset last_version &> /dev/null + + [ "$console_dir" ] || console_dir=console + console_full_dir="$cygeasy_dir/$console_dir" + + if [ ! -e "$console_full_dir" ] + then + answer= + echo -e "\nConsole directory not found in '$cygeasy_dir'." 2> /dev/null + echo -ne "\nDo you want to install Console in '$console_full_dir' [Y/n]? " 2> /dev/null + read -n1 answer &> /dev/null + echo 2> /dev/null + if [[ "$answer" == "n" || "$answer" == "N" ]] + then + answer= + echo -ne "\nDo you want to download and install Console next time [Y/n]? " 2> /dev/null + read -n1 answer &> /dev/null + echo 2> /dev/null + [[ "$answer" != "n" && "$answer" != "N" ]] && return + console_update=0 + return + fi + fi + + echo -n "Searching for a new version of Console ... " 2> /dev/null + + [ "$console_url" ] || + console_url="http://sourceforge.net/export/rss2_projfiles.php?group_id=43764" + + last_version=$(curl -s -L "$console_url" 2> /dev/null | \ + grep -i -m1 "Includes files: Console-" 2> /dev/null | \ + sed -n "s,.*Includes files: Console-\([^ ]*\)\.zip .*,\1,pi" 2> /dev/null) + + [ "$last_version" ] || echo "not found." 2> /dev/null + + if [ "$last_version" ] + then + if [[ ! -e $console_full_dir/console.exe || "$last_version" != "$console_version" ]] + then + echo "found!" + [ "$console_download_url" ] || + console_download_url="http://downloads.sourceforge.net/console" + [ -e $self_dir/console.zip ] && console_exist=1 + cp -fa $console_full_dir $self_dir &> /dev/null + echo "Download version $last_version" 2> /dev/null + curl -f -L -# -C - -o $self_dir/console.zip \ + $console_download_url/Console-$last_version.zip > /dev/null + let "retval = $?" + case "$retval" in + 0) install_console ;; + 18) if [ "$console_exist" ] + then + install_console 1 + fi ;; + esac + cp -f $self_dir/$(basename $console_full_dir) $console_full_dir &> /dev/null + else + echo "not found." 2> /dev/null + fi + fi + + fi + +} + +function setup_missing() +{ + + echo "Cygwin setup utility not found." >&2 + echo "Please download it from '$setup_full_url'" >&2 + echo "and put it in '$(cygpath -w $self_dir 2> /dev/null)' directory." >&2 + exit 1 + +} + +myself=${0##*/} + +[ "$cygeasy_version" ] || + cygeasy_version="$(date '+%Y.%m.%d' -r $(which $myself) 2> /dev/null)" + +[ "$1" == "--help" ] && { show_help 2> /dev/null; exit $?; } +[ "$1" == "--version" ] && { show_version 2> /dev/null; echo 2> /dev/null; show_copyright 2> /dev/null; exit $?; } + +[ $(cygcheck -l cygwin-easy 2> /dev/null | wc -l 2> /dev/null) -eq 0 ] && + { echo "Package 'cygwin-easy' not found. Please use 'mkeasy.sh' script" >&2; \ + echo "to install latest version available." >&2; exit 1; } + +[ ! -e /etc/profile.cygwin-easy ] && ask_all=1 + +[ $(mount 2> /dev/null | grep /etc 2> /dev/null; echo $?) -eq 0 ] && + { echo "Read only mode detected. Please run in writable mode or your" >&2; \ + echo "changes will be lost." >&2; exit 1; } + +[ -r /etc/$myself.conf ] && + . /etc/$myself.conf &> /dev/null + +[ "$self_dir" ] || + self_dir=/usr/share/cygwin-easy +[ "$self_files" ] || + self_files=("autorun.sh" "profile.patch") +[ "$readme_files" ] || + readme_files=("leggimi.txt" "readme.txt") +[ "$cygeasy_files" ] || + cygeasy_files=("autorun.bat" "autorun.inf" "changelog.txt" "license.txt" ${readme_files[*]}) +[ "$cygeasy_download_url" ] || + cygeasy_download_url="http://cygwin-easy.googlecode.com/svn/trunk" + +cygeasy_dir=$(mount 2> /dev/null | grep ' / ' 2> /dev/null | cut -f1 -d'\' 2> /dev/null) + +[ ! -e "$self_dir" ] && + mkdir -p "$self_dir" &> /dev/null + +[ -e "$self_dir/autoupdate" ] && rm -f "$self_dir/autoupdate" &> /dev/null + +nocurl=$(type -f curl &>/dev/null; echo $?) +online=$(curl -s -o /dev/null http://www.cygwineasy.tk &> /dev/null; echo $?) + +if [[ $nocurl -eq 0 && $online -eq 0 ]] +then + [ "$self_update" ] || self_update=1 + [ "$self_update" == "1" ] && update_myself $@ + [ "$cygeasy_update" ] || cygeasy_update=1 + [ "$cygeasy_update" == "1" ] && update_cygeasy + update_tools +fi + +if [ ! -e $self_dir/setup.exe ] +then + if [ "$setup_version" ] + then + [ "$setup_download_url" ] || + setup_download_url="http://cygwin.com/setup/snapshots" + setup_full_url="$setup_download_url/setup-$setup_version.exe" + else + [ "$setup_default_url" ] || + setup_default_url="http://www.cygwin.com/setup.exe" + setup_full_url="$setup_default_url" + fi + if [[ $online -eq 0 || $nocurl -ne 0 ]] + then + echo "Cygwin setup utility is missing and I can't download it" 2> /dev/null + echo "automatically. Please follow this step by step tutorial to" 2> /dev/null + echo "get this file." 2> /dev/null + echo -ne "\nHave you already a version of 'setup.exe' [y/N]? " 2> /dev/null + read -n1 answer &> /dev/null + echo 2> /dev/null + if [[ "$answer" == "y" || "$answer" == "Y" ]] + then + answer= + echo -e "\nVery well. Now you have to copy this file in:" 2> /dev/null + echo 2> /dev/null + cygpath -w "$self_dir" 2> /dev/null + echo -ne "\nDo you want to open this directory for you [Y/n]? " 2> /dev/null + read -n1 answer &> /dev/null + echo 2> /dev/null + [[ "$answer" != "n" && "$answer" != "N" ]] && + cygstart "$self_dir" + else + answer= + echo -e "\nNo problem. You can download this file from:" 2> /dev/null + echo 2> /dev/null + echo "$setup_full_url" 2> /dev/null + echo 2> /dev/null + echo "and put it in this directory:" 2> /dev/null + echo 2> /dev/null + cygpath -w "$self_dir" 2> /dev/null + echo 2> /dev/null + echo "Do you want to download it with your default browser" 2> /dev/null + echo -n "(destination directory path will be in your clipboard) [Y/n]? " 2> /dev/null + read -n1 answer &> /dev/null + echo 2> /dev/null + [[ "$answer" != "n" && "$answer" != "N" ]] && + { cygpath -w "$self_dir" 2> /dev/null | putclip &> /dev/null; \ + cygstart -d "$self_dir" "$setup_full_url"; } + fi + echo -ne "\nWhen you have terminated press ENTER" 2> /dev/null + read -n1 &> /dev/null + echo 2> /dev/null + [[ "$setup_version" && -e "$self_dir/setup-$setup_version.exe" ]] && + mv -f "$self_dir/setup-$setup_version.exe" "$self_dir/setup.exe" &> /dev/null + [ ! -e "$self_dir/setup.exe" ] && setup_missing > /dev/null + else + setup_missing > /dev/null + fi +fi + +[ "$readme_update" ] || readme_update=1 + +if [ "$readme_update" == "1" ] +then + + for readme in ${readme_files[*]} + do + if [ -e "$cygeasy_dir/$readme" ] + then + readme_version=$(sed -n "s,Cygwin Easy \(.*\),\1,ip" "$cygeasy_dir/$readme" 2> /dev/null | head -1 2> /dev/null) + if [ "$readme_version" != "$cygeasy_version" ] + then + echo -n "Updating '$readme' ... " 2> /dev/null + mv -f "$cygeasy_dir/$readme" \ + "$self_dir/$readme" &> /dev/null + echo -e "Cygwin Easy $cygeasy_version\r" > "$cygeasy_dir/$readme" 2> /dev/null + echo -e "----------------------\r" >> "$cygeasy_dir/$readme" 2> /dev/null + tail +3 "$self_dir/$readme" >> "$cygeasy_dir/$readme" 2> /dev/null + if [ -e "$cygeasy_dir/$readme" ] + then + echo "done!" + rm -f "$self_dir/$readme" &> /dev/null + else + mv -f "$self_dir/$readme" \ + "$cygeasy_dir/$readme" &> /dev/null + echo "some error occurred" >&2 + fi + fi + fi + done + +fi + +[ "$pkglist_update" ] || pkglist_update=1 + +if [[ "$pkglist_update" == "1" && -e "$cygeasy_dir/packages.txt" ]] +then + + [ "$cygeasy_custom" ] || cygeasy_custom=0 + + echo -n "Updating packages list ... " 2> /dev/null + mv -f "$cygeasy_dir/packages.txt" \ + "$self_dir/packages.txt" &> /dev/null + cygcheck -c -d | sed -e \ + "s,\(Package Info.*\),Easy $cygeasy_version \1\n------------------------------------------\n,i; + s,\(Version\),\1\n,i" > "$cygeasy_dir/packages.txt" 2> /dev/null + if [ -e "$cygeasy_dir/packages.txt" ] + then + u2d "$cygeasy_dir/packages.txt" &> /dev/null + if [ "$cygeasy_custom" == "0" ] + then + tail +6 "$self_dir/packages.txt" > "$self_dir/pkg1.txt" 2> /dev/null + tail +6 "$cygeasy_dir/packages.txt" > "$self_dir/pkg2.txt" 2> /dev/null + differ $self_dir/pkg1.txt $self_dir/pkg2.txt &> /dev/null + if [ $? -eq 1 ] + then + cygeasy_custom=1 + update_conf + fi + rm -f "$self_dir/pkg1.txt" "$self_dir/pkg2.txt" &> /dev/null + fi + if [ "$cygeasy_custom" == "1" ] + then + sed -i "s,\([0-9] \)\(Package Info.*\),\1\(custom\) \2,i; + s,--$,-----------,i" "$cygeasy_dir/packages.txt" &> /dev/null + u2d "$cygeasy_dir/packages.txt" &> /dev/null + fi + echo "done!" 2> /dev/null + rm -f "$self_dir/packages.txt" &> /dev/null + else + mv -f "$self_dir/packages.txt" \ + "$cygeasy_dir/packages.txt" &> /dev/null + echo "some error occurred" >&2 + fi +fi + +[ "$autoplay_update" ] || autoplay_update=1 + +if [[ "$autoplay_update" == "1" && -e "$cygeasy_dir/autorun.inf" ]] +then + + unset retval retval2 + cp -f "$cygeasy_dir/autorun.inf" "$self_dir/autorun.inf" &> /dev/null + retval=$? + echo -n "Updating autoplay configuration file ... " 2> /dev/null + if [ "$cygeasy_custom" == "1" ] + then + [ "$(grep custom $self_dir/autorun.inf &> /dev/null; echo $? 2> /dev/null)" != "0" ] && + sed -i "s,\(Cygwin Easy\),\1 (custom),i" "$self_dir/autorun.inf" &> /dev/null + fi + cygwin_dir=$(mount 2> /dev/null | grep ' / ' 2> /dev/null | cut -f1 -d' ' 2> /dev/null | \ + cut -f2 -d'\' 2> /dev/null | sed "s,\\\,\\\\\\\\,g" 2> /dev/null) + sed -i "s,\(icon=\).*,\1$cygwin_dir\\\usr\\\share\\\icons\\\cygwin.ico,i" "$self_dir/autorun.inf" &> /dev/null + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + + xwin_in=$(grep -i xwin "$self_dir/autorun.inf" &> /dev/null; echo $? 2> /dev/null) + + if [[ "$xwin_in" == "0" && ! -e "/usr/X11R6/bin/startxwin.sh" ]] + then + sed -i "s,.*xwin.*,,i" "$self_dir/autorun.inf" &> /dev/null + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + fi + + if [[ "$xwin_in" != "0" && -e "/usr/X11R6/bin/startxwin.sh" ]] + then + cat >> "$self_dir/autorun.inf" << EOF +shell\xwin=X Windows +shell\xwin\command=autorun.bat x +EOF + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + fi + + [ "$console_dir" ] || console_dir=console + wcons_dir=$(cygpath -w $console_dir 2> /dev/null) + + console_in=$(grep -i console "$self_dir/autorun.inf" &> /dev/null; echo $? 2> /dev/null) + + if [ "$console_in" == "0" ] + then + + if [ ! -e "$cygeasy_dir/$console_dir/console.exe" ] + then + sed -i "s,.*console.*,,i" "$self_dir/autorun.inf" &> /dev/null + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + fi + + if [ -e "$cygeasy_dir/$console_dir/console.exe" ] + then + sed -i "s,\(command=\).*\(\\\console\.exe\),\1$wcons_dir\2,i" "$self_dir/autorun.inf" &> /dev/null + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + fi + + fi + + if [[ "$console_in" != "0" && -e "$cygeasy_dir/$console_dir/console.exe" ]] + then + cat >> "$self_dir/autorun.inf" << EOF +shell\console=Console +shell\console\command=$wcons_dir\console.exe +EOF + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + fi + + unset retval2 + + grep '^[a-z\[].*' "$self_dir/autorun.inf" > "$self_dir/autorun.inf.new" + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + mv -f "$self_dir/autorun.inf.new" "$self_dir/autorun.inf" &> /dev/null + u2d "$self_dir/autorun.inf" &> /dev/null + retval2=$? + [ "$retval" == "0" ] && retval=$retval2 + + if [ "$retval" == "0" ] + then + mv -f "$self_dir/autorun.inf" "$cygeasy_dir/autorun.inf" &> /dev/null + echo "done!" 2> /dev/null + else + rm -f "$self_dir/autorun.inf" &> /dev/null + echo "some errors occurred" + fi + +fi + +[ -e /etc/$myself.conf ] || update_conf + +[ "$1" == "--freeze" ] && { freeze_now; exit $?; } + +echo "Launch Cygwin setup utility" +cygstart $self_dir/setup.exe + +exit $? \ No newline at end of file