Jump to content

Local Ducky Script Manager - Mac & Linux


burnsoft
 Share

Recommended Posts

I created a shell script to help manage my ducky scripts and to copy what i wanted to use to the root of the drive.  After creating it, i wanted to post it just incase anyone else might find it useful and came across this thread.  I made this shell script on a mac, and also tested it out on another linux based box and didn’t have any problems.  The only thing I had to do on the mac was download the “dialog” command via brew.

 

Currently my SD card contains the following directory structure: 

 

dirStructure.png

 

As you can see, some of these scripts are from the repository.  The Directories are the same name as the script, each directory has the script and the compiled version of the script ready for the duck.

 

When i put in the SD card, i run the menu.sh to bring up the “script manager”

what is does is just read the contents of the directory structure and puts it in a menu.

 

menu.png

 

I find the one i want and hit enter

 

menu1.png

 

and it will copy it to the root drive

 

file_copied.png

 

and the script exits.

 

if the inject.bin does not exist where the script is located at, then it will compile it.

A lot of the top vars can be changed if you need to.  I mostly created it based on how i run and manage the scripts.

 

GitHub for DuckMenu

 

Source:

 

#!/bin/bash
#ducky_menu.sh
#Version: 1.0.5
#by JM
MainFile="inject.bin";  #the compiled file for the rubber ducky
CurrentPath=$PWD;		#The path of were the menu.sh was ran, this can be hardcoded if needed
ScriptsPath="$CurrentPath/scripts";	 #path of where the scripts are at, usually a sub folder of the current
EncoderPath="$CurrentPath/Encoder/encoder.jar"; #location of the encoder
MakeDirMoveFiles=true;	#if you have the code in the scripts director and what it to be in it's own directory
ScriptExt="txt";		#the extenstion of the script
PathName="";			#global var, leave blank
choices="";				#global var, leave blank

MakeDirFromFiles()
{
	cd $ScriptsPath
	for file in *.$ScriptExt; 
		do 
			mkdir -- "${file%.$ScriptExt}"; mv -- "$file" "${file%.$ScriptExt}"; 
		done
	cd $CurrentPath
}
DoCopy()
{
	cpFrom="$ScriptsPath/${PathName[@]}/$MainFile"
	cpTo="$CurrentPath/$MainFile"
	cp "$cpFrom" "$cpTo"
	dialog --title 'File Copied' --msgbox "$cpFrom was copied to $enTo" 6 60
}
RunEncoder()
{
	enFrom="$ScriptsPath/${PathName[@]}/${PathName[@]}.$ScriptExt"
	enTo="$CurrentPath/$MainFile"
	java -jar $EncoderPath -i "$enFrom" -o $enTo
	dialog --title 'File Compiled' --msgbox "$cpFrom was comiled to $enTo" 8 60
}
DoMenu()
{
	i=0
	x=1
	while read line
	do
		array[ $i ]="$line" 
		if [[ -n "$options" ]]; then
			options=("${options[@]}" "$x" "\"$line\"" "off")
		else
			options=("$x" "\"$line\"" "off")
		fi
		(( i++ ))
		(( x++ ))
	done < <(ls $ScriptsPath)
	cmd=(dialog --separate-output --checklist "Select options:" 22 76 16)
	choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
	if [ -z "$choices"] ; then
		choices=0
	fi
	if (($choices > 0)) ; then
		arrayID=`expr $choices - 1`
		PathName="${array[$arrayID]}"
		if [ -f "$ScriptsPath/$PathName/$MainFile" ]; then
			DoCopy $PathName
		else
			RunEncoder $PathName
		fi
		clear
		echo "Good Bye Happy Ducking!"
	else
		clear
		echo "No Options selected..Good Bye!"
	fi
}
if $MakeDirMoveFiles ; then
	MakeDirFromFiles;
fi
DoMenu;

 

Edited by burnsoft
code cleanup
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...