Are you a spammer

Please note, that the first 3 posts you make, will need to be approved by a forum Administrator or Moderator before they are publicly viewable.
Each application to join this forum is checked at the Stop Forum Spam website. If the email or IP address appears there when checked, you will not be allowed to join this forum.
If you get past this check and post spam on this forum, your posts will be immediately deleted and your account inactivated.You will then be banned and your IP will be submitted to your ISP, notifying them of your spamming. So your spam links will only be seen for an hour or two at most. In other words, don't waste your time and ours.

This forum is for the use and enjoyment of the members and visitors looking to learn about and share information regarding the topics listed. It is not a free-for-all advertising venue. Your time would be better spent pursuing legitimate avenues of promoting your websites.

Toys under the hood

Source code I have written openly published for your viewing pleasure.


Toys under the hood

Postby TheeMahn » Thu Oct 24, 2013 12:24 am

Code-Cleanup Package
Conky-Builder Package
KeySnatcher Package
Multi-Monitor Package
Nasup Package
Theme Repair tool
Thumbos Package
Tmrename Package
Mp4tomp3 Package
Wallscan Package


Introduction:
I am going to attempt to document programs I have written most are unaware of that are under the hood of virtually all Ultimate Edition operating systems. Software I have released to the internet are licensed under GPL feel free to edit / re-write anything I have released to date as you see fit. This particular page I am going to write about the ultimate-edition-code-cleanup package.

These programs can be accessed from the command-line interface (CLI). The programs from the ultimate-edition-code-cleanup package are written in BASH & Ruby, however I am fluent in many languages. I am unsure if that is the way to word that statment when talking about programming languages ;) The above links will extend as I write pages based on each package I have written for Ultimate Edition. I am sure I have at the very least 10 pages to write similar to this one covering various tools and languages. I do want to start by pointing out one that is visible, however goes totally unnoticed by most people.


Bash-Script-Maker:

gedit plugin.png
Script maker Gedit plugin also a part of ultimate-edition-code-cleanup deb

The above Gedit plugin will generate a bash script skelaton if you will to get you started writing scripts, this suits 2 purposes:

1. To get you started writing your script instantly saving hours of time.
2. Education (a great place for newbs to learn bash scripting)

I have considered extending this to include a wizard like interface injecting commonly used functions. Wow am I lazy when it comes to coding right? No, I try to live by the rule why re-create the wheel. It would also accelerate application development.

CODE CLEANUP:
Back to the CLI. I'm going to start with my personal favorite code-cleanup it is written in Ruby. Why my favorite? No-one is perfect & I am a sloppy programmer. I do not bother indenting etc. This tool not only makes your code look pretty it will point out errors. These errors are displayed as indentions. If you write software in bash this tool is absolutly a must have. I am first going to provide an example of code with errors before and after the tool has ran across it. The below is bogus code, chroot detection should be done from udev and / or checking against inode 2. Beyond the scope of this post.

Before:
#!/bin/bash
#Ultimate Edition Customizations preinst for Ultimate Edition 3.7

set -e

IUSER=${SUDO_USER:-$USER}
IHOME="/home/$IUSER"


case "$1" in
configure)
echo "Checking for chroot environment."
if [ $IUSER != 'root' ]; then
echo "No chroot environment detected, removing."
abort-remove
echo "Done."
else
echo 'Root user / chroot environment detected.'
if test -f /etc/skel/examples.desktop; then
rm -R /etc/skel/examples.desktop
fi

if test -f /root/.bash_history; then
rm -f /root/.bash_history
fi
echo "VERSION Detected: $version"
if [ -n "$version" ] \
&& dpkg --compare-versions "$version" lt "2.7"; then
config_source=$(gconftool-2 --get-default-source)
tmp_dir=$(mktemp -t -d gconf.XXXXXXXXXX)
HOME="$tmp_dir" gconftool-2 --direct \
-config-source="$config_source" \
--recursive-unset \
/apps/panel/default_setup \
>/dev/null
kill -s HUP `pidof gconfd-2` >/dev/null 2>&1 || true
rm -rf "$tmp_dir"

rm /var/crash/* > 2 &1 /dev/null

glib-compile-schemas /usr/share/glib-2.0/schemas/
update-gconf-defaults
fi
;;
esac
exit 0

Code: Select all
theemahn@JackHammer:~/Music/ultimate-edition-customizations-3.7_all/DEBIAN$ code-cleanup postinst
Error: indent/outdent mismatch: 1.
theemahn@JackHammer:~/Music/ultimate-edition-customizations-3.7_all/DEBIAN$

This means a done or fi etc. is missing somewhere in the code where the indention is missing is typically where the error lies let's examine the code. This board does not handle tabs very well lets look at a screenshot.
After:
cc.png
After running code-cleanup


Let's build a manual for it:
Code: Select all
theemahn@JackHammer:~/Videos$ repostorm --fix ultimate-edition-code-cleanup_1.7.2-1_all
Relaxing permissions
Relaxing: ultimate-edition-code-cleanup_1.7.2-1_all
Process complete. Execution Time: 0s.
Scanning for errors / warnings to fix in ultimate-edition-code-cleanup_1.7.2-1_all.
W: ultimate-edition-code-cleanup: binary-without-manpage bin/bashdepends
W: ultimate-edition-code-cleanup: binary-without-manpage bin/code-cleanup
Fixing Error: No Manpage - Writing Generic manpage. please review and change if necessary.
Setting homepage as: http://ultimateedition.info/
Scanning for manpages errors.
Warning: W: ultimate-edition-code-cleanup: binary-without-manpage bin/bashdepends
Processing: bashdepends
Warning: W: ultimate-edition-code-cleanup: binary-without-manpage bin/code-cleanup
Processing: code-cleanup
Manpage issue(s) fixed.
Errors / warnings fixed: 1
theemahn@JackHammer:~/Videos$ theemahn@JackHammer:~/Videos$ repostorm --build ultimate-edition-code-cleanup_1.7.2-1_all
Code for multi-builds to achieve perfection will enter here.

=============================================================
Beginning build of ultimate-edition-code-cleanup_1.7.2-1_all
=============================================================

Relaxing permissions of ultimate-edition-code-cleanup_1.7.2-1_all
Cleaning up any tmp or backup files.
Setting individual file permissions to 644.
Scanning /etc to build conffiles.
Scanning for executables in ultimate-edition-code-cleanup_1.7.2-1_all Stage 1.
ultimate-edition-code-cleanup_1.7.2-1_all/bin/bashdepends
ultimate-edition-code-cleanup_1.7.2-1_all/bin/code-cleanup
ultimate-edition-code-cleanup_1.7.2-1_all/usr/share/gedit/plugins/externaltools/tools/new-bash
Scanning for executables in ultimate-edition-code-cleanup_1.7.2-1_all Stage 2.
Calculating Installed size & inserting into control file if necessary.
ultimate-edition-code-cleanup_1.7.2-1_all is 104. Control file reporting: 88
Size Mismatch, replacing with 104.
Calculating MD5SUMS in ultimate-edition-code-cleanup_1.7.2-1_all
Setting ownership to root in ultimate-edition-code-cleanup_1.7.2-1_all
Setting individual folder permissions to 755.
Setting permissions rights for control etc.
Building of ultimate-edition-code-cleanup_1.7.2-1_all
dpkg-deb: building package `ultimate-edition-code-cleanup' in `ultimate-edition-code-cleanup_1.7.2-1_all.deb'.
Lintian resulting package ultimate-edition-code-cleanup_1.7.2-1_all.deb.
We have built a totally perfect deb.
Recursively removing ultimate-edition-code-cleanup_1.7.2-1_all since we have a perfect deb.
Moving ultimate-edition-code-cleanup_1.7.2-1_all.deb to .debs/
We have had 100% error warning free deb(s) built this session.
theemahn@JackHammer:~/Videos$


Pretty straight forward I guess:
code-cleanup 1.7.2-1, 10/23/2013

GNU code-cleanup home page: <http://www.repostorm.com/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word code-cleanup somewhere in the Subject: field.

usage: code-cleanup [BASH SCRIPT] or "-" for stdin.


This package will eventually be a dependancy in repostorm as well repairtheme. Code-cleanup application was originally written by Paul Lutus under GPL in 2008 for doing the same thing to Ruby scripts. I have re-written it to do the same to bash scripts. Let's get some code out there already:
Code: Select all
#!/usr/bin/ruby -w
# ==============================================================================
# title         :code-cleanup
# description      :Bash code cleanup script
# author      :Glenn Cady <[email protected]>
# date         :10/23/2013
# version      :1.7.2-1
# usage         :code-cleanup --help
# manual      :man code-cleanup
# notes         :See change-log below for further information.
# ==============================================================================
# Change-log:   1.7.1-8: re-wrote all code for cleaning up bash instead of ruby
#      1.7.2-1: Cleaned code and added stamping routine.
# ==============================================================================
# Original code: Copyright (C) 2008, Paul Lutus under GPL

PVERSION = '1.7.2-1'
BUILDDATE = "10/23/2013"
CCAUTHOR = "Glenn Cady <[email protected]>"
AUTHOR= ENV['USER']
WEBSITE = "http://ultimateedition.info/"

module RBeautify

   # user-customizable values

   RBeautify::TabStr = "\t"
   RBeautify::TabSize = 1

   # indent regexp tests

   IndentExp = [
      /^module\b/,
      /^class\b/,
      /^if\b/,
      /(=\s*|^)until\b/,
      /^unless\b/,
      /(=\s*|^)while\b/,
      /(=\s*|^)begin\b/,
      /(^| )case\b/,
      /^rescue\b/,
      /^def\b/,
      /^do\b/,
      /^else\b/,
      /^elsif\b/,
      /^ensure\b/,
      /\bwhen\b/,
      /\{[^\}]*$/,
      /\[[^\]]*$/
   ]

   # outdent regexp tests

   OutdentExp = [
      /^rescue\b/,
      /^ensure\b/,
      /^elsif\b/,
      /^end\b/,
      /^else\b/,
      /^fi\b/,
      /^esac\b/,
      /^done\b/,
      /\bwhen\b/,
      /^[^\{]*\}/,
      /^[^\[]*\]/,
   ]

   def RBeautify.rb_make_tab(tab)
      return (tab < 0)?"":TabStr * TabSize * tab
   end

   def RBeautify.rb_add_line(line,tab)
      line.strip!
      line = rb_make_tab(tab) + line if line.length > 0
      return line
   end

   def RBeautify.beautify_string(source, path = "")
      comment_block = false
      in_here_doc = false
      here_doc_term = ""
      program_end = false
      multiLine_array = []
      multiLine_str = ""
      tab = 0
      output = []
      source.each do |line|
         line.chomp!
         if(!program_end)
            # detect program end mark
            if(line =~ /^__END__$/)
               program_end = true
            else
               # combine continuing lines
               if(!(line =~ /^\s*#/) && line =~ /[^\\]\\\s*$/)
                  multiLine_array.push line
                  multiLine_str += line.sub(/^(.*)\\\s*$/,"\\1")
                  next
               end

               # add final line
               if(multiLine_str.length > 0)
                  multiLine_array.push line
                  multiLine_str += line.sub(/^(.*)\\\s*$/,"\\1")
               end

               tline = ((multiLine_str.length > 0)?multiLine_str:line).strip
               if(tline =~ /^=begin/)
                  comment_block = true
               end
               if(in_here_doc)
                  in_here_doc = false if tline =~ %r{\s*#{here_doc_term}\s*}
               else # not in here_doc
                  if tline =~ %r{=\s*<<}
                     here_doc_term = tline.sub(%r{.*=\s*<<-?\s*([_|\w]+).*},"\\1")
                     in_here_doc = here_doc_term.size > 0
                  end
               end
            end
         end
         if(comment_block || program_end || in_here_doc)
            # add the line unchanged
            output << line
         else
            comment_line = (tline =~ /^#/)
            if(!comment_line)
               # throw out sequences that will
               # only sow confusion
               while tline.gsub!(/\{[^\{]*?\}/,"")
               end
               while tline.gsub!(/\[[^\[]*?\]/,"")
               end
               while tline.gsub!(/'.*?'/,"")
               end
               while tline.gsub!(/".*?"/,"")
               end
               while tline.gsub!(/\`.*?\`/,"")
               end
               while tline.gsub!(/\([^\(]*?\)/,"")
               end
               while tline.gsub!(/\/.*?\//,"")
               end
               while tline.gsub!(/%r(.).*?\1/,"")
               end
               # delete end-of-line comments
               tline.sub!(/#[^\"]+$/,"")
               # convert quotes
               tline.gsub!(/\\\"/,"'")
               OutdentExp.each do |re|
                  if(tline =~ re)
                     tab -= 1
                     break
                  end
               end
            end
            if (multiLine_array.length > 0)
               multiLine_array.each do |ml|
                  output << rb_add_line(ml,tab)
               end
               multiLine_array.clear
               multiLine_str = ""
            else
               output << rb_add_line(line,tab)
            end
            if(!comment_line)
               IndentExp.each do |re|
                  if(tline =~ re && !(tline =~ /\s+end\s*$/))
                     tab += 1
                     break
                  end
               end
            end
         end
         if(tline =~ /^=end/)
            comment_block = false
         end
      end
      error = (tab != 0)
      STDERR.puts "Error: indent/outdent mismatch: #{tab}." if error
      return output.join("\n") + "\n",error
   end # beautify_string

   def RBeautify.beautify_file(path)
      error = false
      if(path == '-') # stdin source
         source = STDIN.read
         dest,error = beautify_string(source,"stdin")
         print dest
      else # named file source
         source = File.read(path)
         dest,error = beautify_string(source,path)
         if(source != dest)
            # make a backup copy
            File.open(path + "~","w") { |f| f.write(source) }
            # overwrite the original
            File.open(path,"w") { |f| f.write(dest) }
            File.open(path, "a") do |f|
    f.write "# ==============================================================================\n# This code was automatically cleaned up using code-cleanup\n# title         :code-cleanup\n# description      :Bash code cleanup script\n# Author      :%s\n# date         :%s\n# version      :%s\n# %s\n# ==============================================================================" % [ AUTHOR, BUILDDATE, PVERSION, WEBSITE ]
end
         end
      end
      return error
   end # beautify_file

   def RBeautify.main
      error = false
      if(!ARGV[0])
         STDERR.puts "\e[1;32mcode-cleanup %s, %s" % [ PVERSION, BUILDDATE ]
    STDERR.puts "\nGNU code-cleanup home page: <http://www.repostorm.com/>.\nE-mail bug reports to: <[email protected]>.\nBe sure to include the word code-cleanup somewhere in the Subject: field.\n\n"
         STDERR.puts "usage: code-cleanup [BASH SCRIPT] or \"-\" for stdin."
         exit 0
      end
      ARGV.each do |path|
         error = (beautify_file(path))?true:error
      end
      error = (error)?1:0
      exit error
   STAMP.main
   end # main
end # module RBeautify

module STAMP

end

# if launched as a standalone program, not loaded as a module
if __FILE__ == $0
   RBeautify.main
   STAMP.main
end

Bash-Depends:
It does not end there, there is also bash-depends in this same package. Bash depends will scan a bash script looking for dependancies in the bash script so you can add the list to your control file for deployment. I guess the main reason I wrote this app beyond wanting to make my debs perfect; I was told it could not be done in bash ;)

Let's run bash-depends against conky-builder(another program I wrote):
theemahn@JackHammer:~$ bashdepends -d conky-builder.sh
bashdepends 1.7.2-1, 10/23/2013
GNU builddeps home page: <http://www.ultimateedition.info/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word builddeps somewhere in the Subject: field.
Please wait this may take a while depending on the size of the script.
Stripping bash builtin commands.
Externally called commands:
cat
cut
dpkg
expr
glxinfo
grep
hddtemp
ls
lsb_release
rm
sed
sensors
uname
wc
xrandr
yes
SCANNING FOR NON-ESSENTIAL / ESSENTIAL PACKAGE(S)...
COMMAND PACKAGE PRIORITY VERSION
________________________________________________________________________________
cat coreutils required 8.13-3ubuntu3.2
cut coreutils required 8.13-3ubuntu3.2
dpkg dpkg required 1.16.1.2ubuntu7.2
expr coreutils required 8.13-3ubuntu3.2
glxinfo mesa-utils optional 8.1.0-0ubuntu1~precise1
grep grep required 2.10-1
hddtemp hddtemp extra 0.3-beta15-51
ls coreutils required 8.13-3ubuntu3.2
lsb_release lsb-release extra 4.0-0ubuntu20.3
rm coreutils required 8.13-3ubuntu3.2
sed sed required 4.2.1-9
sensors lm-sensors extra 1
uname coreutils required 8.13-3ubuntu3.2
wc coreutils required 8.13-3ubuntu3.2
xrandr x11-xserver-utils optional 7.6+3
yes coreutils required 8.13-3ubuntu3.2
Please add all red packages to your control file.
Depends: mesa-utils (>=8.1.0-0ubuntu1~precise1), hddtemp (>=0.3-beta15-51), lsb-release (>=4.0-0ubuntu20.3), lm-sensors (>=1), x11-xserver-utils (>=7.6+3)
theemahn@JackHammer:~$

I guess it's hard to see red from the above, let's drop a screenie again:
Depends.png
Bash depends running it's magic.

Bash Depends Source code:
Code: Select all
#!/bin/bash
# ==============================================================================
# title         :bashdepends
# description      :Build dependancies script for bash
# author      :Glenn Cady <[email protected]>
# date         :10/23/2013
# version      :1.7.2-1
# usage         :builddeps --help
# manual      :man bashdepends
# notes         :See change-log below for further information.
# bash_version      :4.2.8(1)-release
# ==============================================================================
# Change-log:   1.7.1-8:First public Release
#       1.7.2-1:Bump version to comply with release version.
# ==============================================================================
VERSION="1.7.2-1"
BUILDDATE="10/23/2013"
# set colors so errors etc. stand out.

txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White
bakblk='\e[40m'   # Black - Background
bakred='\e[41m'   # Red
badgrn='\e[42m'   # Green
bakylw='\e[43m'   # Yellow
bakblu='\e[44m'   # Blue
bakpur='\e[45m'   # Purple
bakcyn='\e[46m'   # Cyan
bakwht='\e[47m'   # White
txtrst='\e[0m'    # Text Reset

#Folder where executed
CURRENT=$PWD

function Chkdeps (){
   #dump header
   Version
   # verify a parameter was passed
   if [[ $1 == "" ]];then
      echo -e "${bldred}Please specify a file.${txtrst}"
      exit 0
   fi

   # Filename in case user entered /bin/repomaster for example set to repomaster
   filename=${1##*/}

   # set bash file to process copy to temp
   cp $1 /tmp/
   BFTP="/tmp/"$filename

   # test for bash script existance
   test -s $BFTP || exit 0;
   echo -e "${bldgrn}Please wait this may take a while depending on the size of the script.${txtrst}"

   # roll to temp to begin processing.
   cd /tmp/

   # strip tabs
   sed -i 's/^[ \t]*//' $BFTP

   # strip comments
   sed -e 's/#.*$//' -e '/^$/d' $filename > wip.txt

   # strip echo a builtin
   sed -i '/echo .*/d' wip.txt

   # strip functions
   sed -i '/function .*/d' wip.txt
   sed -i '/}.*/d' wip.txt

   # strip Printf
   sed -i '/printf .*/d' wip.txt

   # strip braces
   cat wip.txt | tr -d "[]" > $filename

   # test for existance of temporary words list in case
   # this tool has been ran before.if so remove file.
   test -e /tmp/words.txt && rm /tmp/words.txt

   # grab commands used in bash file
   for word in $(cat "$BFTP")
   do
      [ -f '$word' -o -f /bin/$word ] && echo $word >> /tmp/words.txt &2>/dev/null
      [ -f '$word' -o -f /usr/bin/$word ] && echo $word >> /tmp/words.txt &2>/dev/null
   done

   cat $BFTP | grep '$(' | cut -d'(' -f2 | sed 's/ .*//g' >> /tmp/words.txt
   cat $BFTP | grep '`' | cut -d'`' -f2 | sed 's/ .*//g' >> /tmp/words.txt
   #strip empty lines
   sed -i '/^$/d' /tmp/words.txt
   #cat $filename | cut -d' ' -f1 >> words.txt
   #intiate array
   array_counter=0
   array_value=0

   #Declare array with all bash builtins
   declare -a Builtins=('alias' 'bg' 'bind' 'break' 'builtin' 'cd' 'command' 'compgen' 'complete' 'continue' 'declare' 'dirs' 'disown' 'echo' 'enable' 'eval' 'exec' 'exit' 'export' 'fc' 'fg' 'getopts' 'hash' 'help' 'history' 'jobs' 'kill' 'let' 'local' 'logout' 'popd' 'printf' 'pushd' 'pwd' 'read' 'readonly' 'return' 'set' 'shift' 'shopt' 'source' 'suspend' 'test' 'times' 'trap' 'type' 'typeset' 'ulimit' 'umask' 'unalias' 'unset' 'wait');

   #Strip references to bash builtin commands
   echo -e "${bldgrn}Stripping bash builtin commands.${txtrst}"
   for number in ${Builtins[@]}
   do
      sed -i "s/${Builtins[$array_counter]}//g" /tmp/words.txt
      array_counter=$(($array_counter + 1))
   done

   #scrap open brackets* from list
   sed -i 's/\[.*//g' /tmp/words.txt

   #scrap empty lines and a few builtins
   sed -i '/^$/d' /tmp/words.txt
   sed -i '/for .*/d' /tmp/words.txt
   sed -i '/from.*/d' /tmp/words.txt
   sed -i "/'/d" /tmp/words.txt

   #Start building dependancy list
   cat /tmp/words.txt | tr " " "\n" | sort | uniq >/tmp/depends.txt

   #Strip #'s
   sed -i '/sh/d' /tmp/depends.txt

   #Strip empty lines
   sed -i '/^$/d' /tmp/depends.txt

   #Initiate header & display results to end user
   echo -e "${bldgrn}Externally called commands:${txtrst}"

   # Check list existance no list no dependancies
   if test -s /tmp/depends.txt
      then
      cat /tmp/depends.txt
   else
      echo -e "${bldred}$1 has no external dependancies.${txtrst}"
      CleanUP
      exit 0
   fi

   #Initate header to display progress in scanning. Make it pretty ;)
   echo -e "${bldgrn}SCANNING FOR NON-ESSENTIAL / ESSENTIAL PACKAGE(S)..."
   printf '%-15s %-30s %-10s %s\n' \
   "COMMAND" "PACKAGE" "PRIORITY" "VERSION"

   #Punch out package database to reference later
   echo -e "${bldwht}________________________________________________________________________________${txtrst}"
   dpkg-query -Wf '${Package}:${Priority}:${Version}\n' | sort -b -k2,2 -k1,1 >/tmp/packages.txt
   test -e /tmp/list.txt && rm /tmp/list.txt

   #Set header for Control file
   cat /tmp/depends.txt | while read FILE
   do
      BINARY=$(which $FILE)
      if [[ $BINARY != "" ]]; then
         POSSIBLE=$(dpkg -S `which $BINARY` | cut -d":" -f1)
         PACKAGEPRIORITY=$(dpkg-query -s $POSSIBLE | grep "Priority:" | cut -d: -f2 | sed 's/ //g')
         PVERSION=$(dpkg-query -s $POSSIBLE | grep "Version:" | cut -d: -f2 | sed 's/ //g')
      else
         exit 0
      fi
      # I have not seen an unknown ever come up please report if you
      # see one and the package involved.
      case $PACKAGEPRIORITY in
         "standard")
         echo -e -n "${bldgrn}";
         printf '%-15s %-30s %-10s %s\n' \
         "$FILE" "$POSSIBLE" "$PACKAGEPRIORITY" "$PVERSION";;
         "required")
         echo -e -n "${bldgrn}";
         printf '%-15s %-30s %-10s %s\n' \
         "$FILE" "$POSSIBLE" "$PACKAGEPRIORITY" "$PVERSION";;
         "important")
         echo -e -n "${bldgrn}";
         printf '%-15s %-30s %-10s %s\n' \
         "$FILE" "$POSSIBLE" "$PACKAGEPRIORITY" "$PVERSION";;
         "optional")
         echo -e -n "${bldred}";
         printf '%-15s %-30s %-10s %s\n' \
         "$FILE" "$POSSIBLE" "$PACKAGEPRIORITY" "$PVERSION";
         echo "$POSSIBLE:$PVERSION" >> list.txt;;
         "extra")
         echo -e -n "${bldred}";
         printf '%-15s %-30s %-10s %s\n' \
         "$FILE" "$POSSIBLE" "$PACKAGEPRIORITY" "$PVERSION";
         echo "$POSSIBLE:$PVERSION" >> list.txt;;
         *)
         echo -e -n "${bldblu}";
         printf '%-15s %-30s %-10s %s\n' \
         "$FILE" "$POSSIBLE" "UNKNOWN" "$PVERSION";;
      esac
   done
   echo -e "${bldwht}Please add all red packages to your control file.${txtrst}"
   GenerateList
}

function GenerateList {
   if test -s list.txt
   then
      echo -n "Depends: "
   else
      echo -e "${bldgrn}No external dependancies.${txtrst}"
      CleanUP
      exit 0
   fi
   NDEPENDS=$(cat list.txt | wc -l)
   cat /tmp/list.txt | while read FILE
   do
      PROCESS=$(($PROCESS + 1))
      DEPEND=$(echo $FILE | cut -d: -f1)
      DVERSION=$(echo $FILE | cut -d: -f2)
      # make sure if is not entered twice on the list for example the
      # commands "ar" and "as" are both part of binutils. We only want
      # it referenced once.
      if test -s fulllist.txt
      then
         ISTHERE=$(cat fulllist.txt | grep $DEPEND)
         if [[ $ISTHERE == "" ]]; then
            if [[ $NDEPENDS != $PROCESS ]]; then
               OUT=$OUT$DEPEND" (>="$DVERSION"), "
            else
               OUT=$OUT$DEPEND" (>="$DVERSION")"
            fi
         fi
      else
         if [[ $NDEPENDS != $PROCESS ]]; then
            OUT=$OUT$DEPEND" (>="$DVERSION"), "
         else
            OUT=$OUT$DEPEND" (>="$DVERSION")"
         fi
      fi
      # push list out to file bash gets dumb when it leaves a do done
      # loop and I do not feel like writing it to run in a sub shell.
      echo $OUT > fulllist.txt
   done
   cat fulllist.txt
   CleanUP
}

function CleanUP {
   # self explanatory
   test -e /tmp/list.txt && rm /tmp/list.txt
   test -e /tmp/fulllist.txt && rm /tmp/fulllist.txt
   test -e /tmp/words.txt && rm /tmp/words.txt
   test -e /tmp/packages.txt && rm /tmp/packages.txt
   test -e /tmp/wip.txt && rm /tmp/wip.txt
   test -e /tmp/depends.txt && rm /tmp/depends.txt
   test -e $BFTP && rm $BFTP
}

function Version {
# dump version number and exit
echo -e "${undwht}bashdepends $VERSION, $BUILDDATE${txtrst}
GNU builddeps home page: <http://www.ultimateedition.info/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word builddeps somewhere in the Subject: field."
}

function Help() {
# Help system simple and functional.
   if [[ $1 == "" ]];
      then
      PRAM="ALL"
   else
      PRAM=$1
   fi

echo -e "${undwht}bashdepends $VERSION, $BUILDDATE${txtrst}"

   case $PRAM in
      ALL)
   echo -e "${txtgrn}GNU bashdepends home page: <http://www.ultimateedition.info/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word bashdepends somewhere in the Subject: field.${txtrst}";
echo "
bashdepends is a part of the tm-tools package. Many of the tools are heavy and
are not intended to be ran by the common user. The tools are geared for the
admininstrator. Please see man tmtools for more info.";
echo -e "
${bldgrn}Usage: bashdepends -[-COMMAND] <BASHSCRIPT>${txtrst}
Mandatory arguments to long options are identical for short options.
possible commands...

   -d   --depends   find dependencies for <BASHSCRIPT>
   -h   --help      this help message
   -v   --version   dump version info

${bldgrn}Example: bashdepends mybashscript.sh
${bldgrn}bashdepends --help [COMMAND] for further information.${txtrst}";;
   ALL|d|depends)
   echo -e "
   ${bldwht}Usage depends;${txtrst}
   ${txtgrn}bashdepends -d <BASHSCRIPT>${txtrst}
   Displays external dependencies on <BASHSCRIPT>.";;
   ALL|v|version)
   echo -e "
   ${bldwht}Usage version;${txtrst}
   ${txtgrn}bashdepends -v${txtrst}
   Displays bashdepends version number and exits.";;
   ALL|h|help|\?)
   echo -e "
   ${bldwht}Useage Help [COMMAND];${txtrst}
   ${txtgrn}bashdepends -h [COMMAND]${txtrst}
   Displays this message. For futher information bashdepends help [COMMAND]
   or refer to the manpages.
   man bashdepends"
   echo -e "${txtgrn}"
   echo -e "Example: bashdepends mybashscript.sh"
   echo -e "${txtwht}Will find the build dependancies for mybashscript.sh${txtrst}"
   esac
exit 0
}

#Command switch preprocessor
case "$1" in
   -h|--help|-\?) Help $2; exit 0;;
   -v|--version) Version; exit 0;;
   -d|--depends) Chkdeps $2; exit 0;;
   *) Help; exit 0;;
esac

I will not rob you of the bash autocompletion scripts.
Bash Depends (/etc/bash_completion.d/):
Code: Select all
# Debian bashdepends(8) completion.

have bashdepends &&
_bashdepends()
{
   dashify()
   {
      local i

      for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
         if [ ${#COMPREPLY[i]} -le 2 ]; then
            COMPREPLY[i]=-${COMPREPLY[i]}
         else
            COMPREPLY[i]=--${COMPREPLY[i]}
         fi
      done
   }

   local cur cur_nodash prev

   COMPREPLY=()
   cur=${COMP_WORDS[COMP_CWORD]}
   cur_nodash=${cur#-}
   prev=${COMP_WORDS[COMP_CWORD-1][COMP_CWORD-2]}

   if [ $COMP_CWORD = 1 ]; then
      # first parameter on line
      case "$cur" in
      -d*)
         COMPREPLY=( $( compgen -W 'depends' \
                   $cur_nodash ) )
         dashify
         return 0
         ;;
      -*)
         COMPREPLY=( $( compgen -W 'depends version help' ${cur_nodash#-} ) )
         dashify;
         return 0
         ;;
      --*)
         COMPREPLY=( $( compgen -W 'depends version help' ${cur_nodash#-} ) )
         dashify;
         return 0
         ;;
      *)
         COMPREPLY=( $( compgen -f $cur ) )
         return 0
         ;;
      esac
   fi

   if [ $COMP_CWORD = 2 ]; then
      case "${COMP_WORDS[1]}" in
      --d*)
         # standard filename completion
         COMPREPLY=( $( compgen -f $cur ) )
         return 0
         ;;
      -d)
         # standard filename completion
         COMPREPLY=( $( compgen -f $cur ) )
         return 0
         ;;
      --h*)
         # complete on list of relevant options
         COMPREPLY=( $( compgen -W 'depends version' ${cur_nodash#-} ) )
         #dashify;
         return 0
         ;;
      -h)
         # complete on list of relevant options
         COMPREPLY=( $( compgen -W 'depends version' ${cur_nodash#-} ) )
         #dashify;
         return 0
         ;;
      esac
   fi
}
complete -F _bashdepends bashdepends

Code-Cleanup (/etc/bash_completion.d/):
Code: Select all
# Debian code-cleanup(8) completion.

have code-cleanup &&
_code-cleanup()
{
   dashify()
   {
      local i

      for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
         if [ ${#COMPREPLY[i]} -le 2 ]; then
            COMPREPLY[i]=-${COMPREPLY[i]}
         else
            COMPREPLY[i]=--${COMPREPLY[i]}
         fi
      done
   }

   local cur cur_nodash prev

   COMPREPLY=()
   cur=${COMP_WORDS[COMP_CWORD]}
   cur_nodash=${cur#-}
   prev=${COMP_WORDS[COMP_CWORD-1][COMP_CWORD-2]}

   if [ $COMP_CWORD = 1 ]; then
      # first parameter on line
      case "$cur" in
      -*)
         COMPREPLY=( $( compgen -W 'help' \
                   $cur_nodash ) )
         dashify
         return 0
         ;;
      --*)
         COMPREPLY=( $( compgen -W 'help' ${cur_nodash#-} ) )
         dashify;
         return 0
         ;;
      *)
         COMPREPLY=( $( compgen -f $cur ) )
         # complete on deb files
         return 0
         ;;
      esac
   fi
}
complete -F _code-cleanup code-cleanup


This is simply amazing all of this weighs in at 10.5kb in size. I now remember why Bash is my favorite language ;) I am not only an Operating System Architect, but a programmer with over 30 years experience. I hope by sharing this code to make you a programmer or a better programmer. I know it has assisted me.
Back to Contents:
Attachments
ultimate-edition-code-cleanup_1.7.2-1_all.deb
Ultimate Edition Code Clean up deb
(10.49 KiB) Downloaded 843 times
Home of Ultimate Edition. Got a question? Please review the F.A.Q. Browse the How to section.

Main O/S: Builder of O/S Guess.
Mainboard: ASUS Hero VI (AM4)
CPU: AMD 1700X water cooled (Deepcool Captain Genome Cooling tower)
Ram: 16 GB GSkill Trident RGB Series Dual Channel DDR4 3200
Video: MSI RX470 8GB Gaming card.
Hard Disks: MASSIVE on the network.(10 Gigabit, 48 port, multiple servers)
Monitors: Dual 4K 43" LG, 4K Samsung 28"
750 Watt modular PSU (Rosswell)
1100 Watt Amp & 4 X 600 Watt speakers

Servers in the basement.
User avatar
TheeMahn
Site Admin
 
Posts: 4201
Joined: Fri Oct 12, 2007 10:02 am
Location: U.S.A.
Age: 53
Operating System: Ultimate Edition Developer



Re: Code Cleanup Package

Postby pam » Thu Oct 24, 2013 3:46 am

The screenies clearly show it does more than you intended to!
It also shows you the source packages and can be used for rapid pseudo debugging.

I see this as a very useful utility. :D

Another great from the Mahn.
<BREW>
DONOTSPAMORTROLL:
http://forumubuntusoftware.info/viewtopic.php?f=9&t=11
Download Ultimate Edition and Oz Unity 3.0 from copy:-
https://www.copy.com/s/oBnDBsDOvxF8jW1EuLKM/Public
Download Ultimate Edition from sourceforge:-
http://sourceforge.net/projects/ultimat ... rce=navbar
Download Oz Unity 3.0 from sourceforge:-
http://sourceforge.net/projects/ueoz/files/UEOz/
Download Ultimate Edition torrents from linuxtracker:-
http://linuxtracker.org/index.php?page= ... 0&active=1
Download Oz Unity 3.0 torrents from linuxtracker:-
http://linuxtracker.org/index.php?page= ... 0&active=1
Image Image
Visit:http://www.ultimateeditionoz.com
User avatar
pam
Site Admin
 
Posts: 1087
Joined: Wed May 25, 2011 5:56 am
Location: India
Age: 38
Operating System: Ultimate Edition 3.5 64 BIT



Re: Code Cleanup Package

Postby pam » Thu Oct 24, 2013 4:41 am

If you dont mind Theemahn, i got it running on arch linux/manjaro.
2013-10-24-083928_1920x1080_scrot.png

ultimate-edition-code-cleanup_1.7.2-1_all.tar.gz
code-cleanup & bash-depends for arch linux
(9.57 KiB) Downloaded 1126 times
DONOTSPAMORTROLL:
http://forumubuntusoftware.info/viewtopic.php?f=9&t=11
Download Ultimate Edition and Oz Unity 3.0 from copy:-
https://www.copy.com/s/oBnDBsDOvxF8jW1EuLKM/Public
Download Ultimate Edition from sourceforge:-
http://sourceforge.net/projects/ultimat ... rce=navbar
Download Oz Unity 3.0 from sourceforge:-
http://sourceforge.net/projects/ueoz/files/UEOz/
Download Ultimate Edition torrents from linuxtracker:-
http://linuxtracker.org/index.php?page= ... 0&active=1
Download Oz Unity 3.0 torrents from linuxtracker:-
http://linuxtracker.org/index.php?page= ... 0&active=1
Image Image
Visit:http://www.ultimateeditionoz.com
User avatar
pam
Site Admin
 
Posts: 1087
Joined: Wed May 25, 2011 5:56 am
Location: India
Age: 38
Operating System: Ultimate Edition 3.5 64 BIT



Re: Code Cleanup Package

Postby TheeMahn » Thu Oct 24, 2013 6:46 am

pam wrote:If you dont mind Theemahn, i got it running on arch linux/manjaro.
2013-10-24-083928_1920x1080_scrot.png

ultimate-edition-code-cleanup_1.7.2-1_all.tar.gz


Nope, I don't care at all. Yours to do with as your wish. Maybe someone else running Arch will heed the benefit of you doing so.
Home of Ultimate Edition. Got a question? Please review the F.A.Q. Browse the How to section.

Main O/S: Builder of O/S Guess.
Mainboard: ASUS Hero VI (AM4)
CPU: AMD 1700X water cooled (Deepcool Captain Genome Cooling tower)
Ram: 16 GB GSkill Trident RGB Series Dual Channel DDR4 3200
Video: MSI RX470 8GB Gaming card.
Hard Disks: MASSIVE on the network.(10 Gigabit, 48 port, multiple servers)
Monitors: Dual 4K 43" LG, 4K Samsung 28"
750 Watt modular PSU (Rosswell)
1100 Watt Amp & 4 X 600 Watt speakers

Servers in the basement.
User avatar
TheeMahn
Site Admin
 
Posts: 4201
Joined: Fri Oct 12, 2007 10:02 am
Location: U.S.A.
Age: 53
Operating System: Ultimate Edition Developer



Re: Toys under the hood

Postby Behemoth » Fri Nov 14, 2014 4:18 am

Hi geeks--ama newbie--this is not installing,i extract it,,, it disappears in the system under of usr ---how do i install it---bear with my ignorance.
Behemoth
U.E. Newbie
U.E. Newbie
 
Posts: 2
Joined: Sun May 18, 2014 11:07 pm
Operating System: Ultimate Edition 3.2 64 BIT



Re: Toys under the hood

Postby Snyper » Fri Nov 14, 2014 11:27 am

Behemoth wrote:Hi geeks--ama newbie--this is not installing,i extract it,,, it disappears in the system under of usr ---how do i install it---bear with my ignorance.

What, exactly, are you trying to install? If it's one of the deb packages, you should be trying
Code: Select all
sudo dpkg -i [packagename].deb
followed with
Code: Select all
sudo apt-get install -f

Keep in mind that the versions of these packages in this post are very out-of-date--the up-to-date versions are here: Ultimate Edition repository

If you are trying to install the .tar.gz package pam created, I would recommend that you didn't. It's not built for U. E. but rather for Arch Linux and derivatives like Manjaro.
Main rig: Sledgehammer
ASUS Sabertooth x99 TUF * Intel Core i7-5820K * EVGA Nvidia GTX 970 SSC * G.Skill Ripjaws DDR4-2133 16GB

Second rig: Toyhammer
Foxconn AMD A75M * AMD A8 3870K * AMD Radeon HD 6550D * G.SKILL RipjawsX DDR3-1866 8GB

Seagate Barracuda 1TB 7500 rpm, SATA 6GBps - Various O/S
Western Digital Green 2TB 7500 rpm, 6GBps - Various O/S
User avatar
Snyper
U.E. Newbie
U.E. Newbie
 
Posts: 11
Joined: Fri Nov 07, 2014 10:22 pm
Location: U.S.A.
Age: 26
Operating System: Other Linux


Return to Programming

Who is online

Users browsing this forum: No registered users and 5 guests