#! /bin/sh #---------------------------------------------------------------------------- # change-url - change download url # # Creation: 2001-11-04 fm # Last Update: $Id$ # # Copyright (c) 2001-2007 the eisfair team, team(at)eisfair(dot)org # # 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. # # Bookmark support by: Michell Schimanski #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # standard_url: standard eisfair URL standard_url='http://download.eisfair.org/packages/eis-list.txt' # current url file current_url_file='/var/install/url' # url history file url_history_file='/var/install/url-history' # url bookmark file url_bookmark_file='/var/install/url-bookmarks' # max_his: maximum number of elements in history max_his=10 # # handle_bookmarks # ================ # # Ask for changes to url bookmark file # handle_bookmarks() { mecho "Available bookmarks:" i=0 while [ $i -lt $n_bm ] do i=`expr $i + 1` eval dummy='$url_bm_'$i mecho "$i: $dummy" done mecho /var/install/bin/ask "Change" "" "^$=no change" "a=add" "d=delete" "s=select URL from bookmarks"> /tmp/ask.$$ rc=$? in2=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi case "$in2" in "") mecho "Bookmarks not changed" new_url=$old_url change=0 ;; a) mecho /var/install/bin/ask "New bookmark" "" "^$=cancel" "c=Current URL" "s=select from history" "n=new URL" > /tmp/ask.$$ rc=$? in3=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi input_url='' case "$in3" in "") ;; "c") input_url=$old_url ;; s) ask_history ;; n) ask_url ;; esac if [ "$input_url" != '' ]; then if ! grep "^$input_url$" $url_bookmark_file >/dev/null 2>&1 then echo $input_url >> $url_bookmark_file mecho "Added bookmark: $input_url" else mecho -warn "URL already contained in bookmark file" fi fi mecho "URL not Changed" new_url=$old_url change=0 ;; d) mecho /var/install/bin/ask "Choose number from bookmarklist:" "" "^$=cancel" "1-$n_bm" > /tmp/ask.$$ rc=$? in3=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi if [ "$in3" != '' ] then eval dummy='$url_bm_'$in3 if [ "$dummy" = "$standard_url" ]; then mecho -warn "Deletion of standard eisfair URL is not allowed" else rm -f $url_bookmark_file eval url_bm_$in3="" i=0 while [ $i -lt $n_bm ] do i=`expr $i + 1` eval dummy='$url_bm_'$i if [ "$dummy" != "" ] then echo -e "$dummy" >> $url_bookmark_file fi done mecho "Deleted bookmark: $in3" fi fi mecho "URL not Changed" new_url=$old_url change=0 ;; s) /var/install/bin/ask "Choose number from bookmarklist:" "" "^$=cancel" "1-$n_bm" > /tmp/ask.$$ rc=$? in2=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi if [ "$in2" = '' ] then new_url=$old_url else eval new_url='$url_bm_'$in2 [ "$new_url" != "$old_url" ] && mecho "New URL is: $new_url" || mecho "URL not changed" fi ;; esac } # # ask_url # ======= # # Ask for new URL # Validate URL # ask_url() { valid=0 while [ "$valid" = 0 ] do /var/install/bin/ask "URL:" "" "*" > /tmp/ask.$$ rc=$? input_url=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi if [ "$input_url" = '' ] then input_url=$old_url return fi valid=1 if ! echo "$input_url" | grep -q -E '^http:\/\/.+' then if ! echo "$input_url" | grep -q -E '^https:\/\/.+' then if ! echo "$input_url" | grep -q -E '^ftp:\/\/.+' then if ! echo "$input_url" | grep -q -E '^file:\/\/.+' then valid=0 fi fi fi fi if [ "$valid" = 0 ]; then mecho -error "Wrong URL! Press ENTER to exit loop" fi done } # # ask_history # =========== # # Ask for number from history # ask_history() { /var/install/bin/ask "Choose number from history:" "" "^$=cancel" "1-$n_his" > /tmp/ask.$$ rc=$? in1=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi # question cancelled if [ "$in1" = '' ] then input_url=$old_url else eval input_url='$url_his_'$in1 fi } # # update_url_history # ================== # # Update url history file # update_url_history() { if ! grep "^$new_url$" $url_history_file >/dev/null 2>&1 then if [ $change = 1 ] then ( echo $new_url i=1 if [ $n_his -ge $max_his ] then n_his=`expr $max_his - 1` fi while [ $i -le $n_his ] do eval a='$url_his_'$i echo $a i=`expr $i + 1` done ) > $url_history_file fi fi } # # read_and_display_url_history # ============================ # # Read url history file into variables url_his_# # Set n_his # Display history # read_and_display_url_history() { n_his=0 i=0 if [ -f $url_history_file ] then while read line do i=`expr $i + 1` eval url_his_$i='"$line"' if [ $i = 1 ] then mecho "History $i: $line" else if [ $i -gt 9 ] then mecho " $i: $line" else mecho " $i: $line" fi fi done < $url_history_file n_his=$i fi } # # read_bookmark_file # ================== # # Read bookmark file into variables url_bm_# # Set n_bm # read_bookmark_file() { i=0 n_bm=0 if [ -f $url_bookmark_file ] then while read line do i=`expr $i + 1` eval url_bm_$i='"$line"' done < $url_bookmark_file fi n_bm=$i } cd /tmp clrhome mecho -info "Change URL for download" mecho mecho old_url=`cat $current_url_file 2>/dev/null` if [ "$old_url" = '' ] then mecho -n "Current URL: " mecho -error "-- Error: URL is not set --" else mecho "Current URL: $old_url" fi mecho mecho read_and_display_url_history read_bookmark_file mecho asktype='' if [ $n_his -gt 0 ] then history="h=from history" asktype='h' fi if [ $n_bm -gt 0 ] then bookmarks="b=from bookmarks" asktype="${asktype}b" fi case $asktype in h) /var/install/bin/ask "URL" "" "^$=no change" "$history" "s=standard" "n=new" > /tmp/ask.$$ ;; b) /var/install/bin/ask "URL" "" "^$=no change" "$bookmarks" "s=standard" "n=new" > /tmp/ask.$$ ;; hb) /var/install/bin/ask "URL" "" "^$=no change" "$history" "$bookmarks" "s=standard" "n=new" > /tmp/ask.$$ ;; *) /var/install/bin/ask "URL" "" "^$=no change" "s=standard" "n=new" > /tmp/ask.$$ ;; esac rc=$? in1=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then exit 1 fi change=1 case "$in1" in "") [ "$old_url" != '' ] && mecho "URL not changed" new_url=$old_url change=0 ;; b) handle_bookmarks ;; h) ask_history new_url=$input_url [ "$new_url" != "$old_url" ] && mecho "New URL is: $new_url" || mecho "URL not changed" ;; s|S) new_url="$standard_url" [ "$new_url" != "$old_url" ] && mecho "New URL is: $new_url" || mecho "URL not changed" ;; n) ask_url new_url=$input_url [ "$new_url" != "$old_url" ] && mecho "New URL is: $new_url" || mecho "URL not changed" ;; esac if [ "$new_url" = '' ];then mecho -warn "Replacing empty URL with eisfair standard URL" new_url="$standard_url" mecho "New URL is: $new_url" fi echo $new_url > $current_url_file update_url_history mecho /var/install/bin/anykey exit 0