5 # Name : generate_aliases
6 # Author : Chris Koeritz
7 # Rights : Copyright (C) 1996-$now by Author
11 # This script generates YETI alias files. Alias files contain a list of
12 # definitions for command aliases that are written in the specified shell
13 # dialect (such as bash or perl) and which are additionally tailored for the
14 # operating system to be used.
17 # This program is free software; you can redistribute it and/or modify it
18 # under the terms of the GNU General Public License as published by the Free
19 # Software Foundation; either version 2 of the License or (at your option)
20 # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a
21 # version of the License. Please send any updates to "fred@gruntose.com".
24 require "importenv.pl";
26 # given a possible aliasable filename, this will decide whether to create a perl
27 # or bash alias for it. it needs the filename of the possible alias and the
28 # directory where that file resides.
30 local($file, $dir) = @_;
31 if ($file =~ /\.[pP][lL]$/) {
32 local($aliasname) = $file; $aliasname =~ s/\.[Pp][lL]$//;
33 &make_perl_alias($aliasname, "$dir");
34 } elsif ($file =~ /\.[sS][hH]$/) {
35 local($aliasname) = $file; $aliasname =~ s/\.[Ss][Hh]$//;
36 &make_bash_alias($aliasname, "$dir");
40 # makes an alias for a bash script given the alias name.
42 local($aliasname) = shift(@_);
43 local($full_alias) = $aliasname;
44 $aliasname =~ s/^.*\/([^\/]*)/\1/;
45 #print "alias became $aliasname\n";
46 local($source_dir) = shift(@_);
47 #print "bash alias is $aliasname, dir is $source_dir\n";
48 print she "alias $aliasname=\"bash $source_dir/$full_alias.sh\"\n";
51 # makes an alias for a perl script given the alias name.
53 local($aliasname) = shift(@_);
54 local($full_alias) = $aliasname;
55 $aliasname =~ s/^.*\/([^\/]*)/\1/;
56 #print "alias became $aliasname\n";
57 local($source_dir) = shift(@_);
58 #print "perl alias is $aliasname, dir is $source_dir\n";
59 print she "alias $aliasname=\"perl $source_dir/$full_alias.pl\"\n";
62 # given a directory, this returns an array of all the filenames found therein.
64 local($path) = shift(@_);
65 opendir(that_dir, $path);
66 local(@those_files) = sort(readdir(that_dir));
72 # make sure we know where to store the files we're creating.
73 if ( ! length("$FEISTY_MEOW_GENERATED") ) {
75 The FEISTY_MEOW_GENERATED variable is not defined. This must point to the location where\n\
76 the generated scripts are stored. Perhaps you still need to run\n\
77 bootstrap_shells.sh and set up some environment variables. Please see\n\
78 http://yeticode.org for more details.\n";
80 #really need to use better exit codes.
83 $FEISTY_MEOW_GENERATED =~ s/\\/\//g;
84 $FEISTY_MEOW_SCRIPTS =~ s/\\/\//g;
85 $FEISTY_MEOW_DIR =~ s/\\/\//g;
87 # create our generated shells directory if it's not already there.
88 if (! -d $FEISTY_MEOW_GENERATED) {
89 mkdir $FEISTY_MEOW_GENERATED;
94 # set the executable bit for yeti binaries for just this current user.
96 system("chmod -R u+x \"$BINDIR\"/*");
101 system("bash \"$FEISTY_MEOW_SCRIPTS\"/core/unter_alia.sh");
102 # generate the first set of alias files that are defined in the core
103 # and custom scripts directories.
105 # trash the old versions.
106 unlink("$FEISTY_MEOW_GENERATED/fmc_aliases_for_scripts.sh");
108 printf "writing $FEISTY_MEOW_GENERATED/fmc_aliases_for_scripts.sh...\n";
110 # open the alias files to be created.
111 open(she, ">> $FEISTY_MEOW_GENERATED/fmc_aliases_for_scripts.sh");
113 #print "os is $OS\n";
115 # find the list of files in the scripts directory.
116 #opendir(scripts, "$FEISTY_MEOW_SCRIPTS");
117 #@shell_files = sort(readdir(scripts));
118 #print "yeti scripts: @shell_files\n";
120 @shell_files = &load_file_names("$FEISTY_MEOW_SCRIPTS");
122 # construct aliases for items in the scripts directory.
123 foreach $file (@shell_files) {
124 # test to see what type of item we got.
130 || $file =~ /\/\.\.$/
131 || $file =~ /\/\.svn$/
132 || $file =~ /\/\.git$/
134 # just skip this item; it's a special directory.
135 } elsif (-d "$FEISTY_MEOW_SCRIPTS/$file") {
136 # if we see a subdirectory in the scripts folder, we add all the
137 # scripts in it as aliases. we recurse only one level.
138 opendir(subdir, "$FEISTY_MEOW_SCRIPTS/$file");
139 @subdir_files = sort(readdir(subdir));
140 foreach $subfile (@subdir_files) {
141 push(@shell_files, "$file/$subfile");
144 # if it's a regular file, we'll try to make an alias for it. the function
145 # will only fire if the ending is appropriate for the script languages we use.
146 &make_alias($file, "$FEISTY_MEOW_SCRIPTS");
150 # open the source repository's script directory to find scripts in there.
151 local($build_shell_path) = "$BUILD_TOP/scripts/generator";
152 @build_shells = &load_file_names("$build_shell_path");
153 #opendir(build_shells_dir, $build_shell_path);
154 #@build_shell_files = sort(readdir(build_shells_dir));
155 #if (scalar(@build_shell_files) > 0) {
156 # print "build shell folders: @build_shell_files\n";
158 foreach $file (@build_shells) {
159 &make_alias($file, "$build_shell_path");