#!/users/fdc/bin/wermit + # .version = 2.00 # Post-FTP version - requires external wget .verdate = 2022/04/28 # .version = 1.01 # Make FTP verbose so user can see error # .verdate = 2020/09/15 # messages like "Permission denied" # # .version = 1.00 # Original release # .verdate = 2014/01/12 # # Name: getkermitscript # Requires: C-Kermit 8.0.201 or later # # This script simplifies the downloading and installation of scripts from # the Kermit script library. Before using it you have to: # # 1. Save it on your computer in a directory that is in your PATH, # so you can execute it just by typing its name, no matter what # your current directory is; # # 2. Replace the top line of this file with the full C-Kermit PATH # on your computer, with #! as a prefix and " +" as a suffix, # with no spaces on the line except one space before the plus sign. # (Note: you don't actually have to *replace* the top line, you # can also simply put the new one on top.) # # Then, to download any script from the Kermit script library, type the # name of this script ("getkermitscript" unless you changed it) followed # by the name of the script to get, for example: # # getkermitscript jpginfo # # and optionally followed by the name of the directory to store it in: # # getkermitscript jpginfo ~/scripts/ (in your own filespace) # # or: # # getkermitscript jpginfo /usr/local/bin/scripts/ (system-wide) # # The target directory should be in your PATH). If you omit the target # directory name, the script is stored in your current directory. # # After the desired script file is downloaded, an appropriate "kergang" line # is added to it automatically and it is given execute permission, so you # should be able to run the downloaded script immediately just by typing its # name at the shell prompt. # # Frank da Cruz, January 2014 and April 2022. # ############################################################################## # Get command-line arguments. # # Note that all scripts in the Kermit script directory have # lowercase ASCII names, and that they do NOT have a .ksc extension, # because if they did, any attempt to download them to Windows would # result in telling the local Kermit program to execute them. These # points can be confusing because in documentation the script names are # sometimes capitalized and/or shown with .ksc extensions. We allow # for these possibilities in the following statement. .file := \freplace(\flower(\%1),.ksc,) # Name of script file to get if not def \%1 { exit 1 Usage: \fbasename(\%0) filetoget [ targetdirectory ] } .bindir := \%2 # Where to put the script if not def bindir .bindir = . # Default is current directory # Some definitions used below .tmpfile = ./_tmp # Name for temporary file .perms = 775 # Permissions for downloaded script .rpath = kermit/scripts # Remote path for script library cd \m(bindir) # CD to target directory if fail exit 1 "cd \m(bindir) failed" echo \fbasename(\%0) \m(version) xecho "CURRENT DIRECTORY: " pwd # Use full path of current C-Kermit executable to make new Kerbang line. fopen /write \%o ./\m(tmpfile) if fail exit 1 "CAN'T CREATE TMP FILE in \m(bindir)" fwrite /line \%o {#!\v(exedir)\v(name)\32+} if fail exit 1 "CAN'T WRITE TO TMP FILE: \m(bindir)/\m(tmpfile) fclose \%o .useftp = 0 # FTP was banned from the Internet in 2021 if useftp { # Fetch the desired script from the Kermit Project with anonymous FTP... # Note: minus-sign on password suppresses verbiage. if > \v(version) 800205 set ftp display brief # Keep download screen simple set ftp display serial # Display all FTP protocol messages set ftp progress-messages on set ftp verbose-mode on ftp open ftp.kermitproject.org /user:anonymous /password:-getkermitscript if fail exit 1 "Connection to kermitproject.org failed" if not \v(ftp_loggedin) exit 1 "FTP anonymous login failed" ftp cd \m(rpath) if fail exit 1 "FTP CD \m(rpath) failed" ftp get \m(file) if fail stop 1 "GET \m(file) failed" ftp bye } else { # Have to outsource the download to wget... In theory Kermit's built-in # HTTP GET command should work but it raises issues about Kermit's # optional support for various encryption security methods like SSL. # echo Invoking wget... ! which wget > /dev/null 2> /dev/null if fail exit 1 FAILED: 'wget' program required but not found ! wget -nv http://www.kermitproject.org/ftp/kermit/scripts/\m(file) if fail { if exist \m(tmpfile) delete \m(tmpfile) exit 1 DOWNLOAD FAILED } } # Append the downloaded file to the new Kerbang line file copy /append \m(file) \m(tmpfile) rename \m(tmpfile) \m(file) # Rename the result appropriately chmod \m(perms) \m(file) # and give it execute permission if fail stop 1 "CHMOD \m(perms) \m(file) failed" # Show the results... echo "File '\m(file)' downloaded to \v(dir):" dir \m(file)* # Directory listing of file echo Top four lines: type /head:4 \m(file) # First four lines of the file exit 0 "OK" ; Local Variables: ; comment-column:40 ; comment-start:"# " ; End: