BBOSAK2143 wrote:I just have to brag about this gem again! I have been viewing complaints of all the other Thumb drive creators as I try to find a solution for my problem. Now will once again state, Unetbootin struggles to create Thumb drives but sure does work but time wise is terrible. You would think with a gui would be good! NOT SO! If you have a CD/DVD in your computer forget it will not work! The other startup disk creator pretends to work and nothing happens! Now ThumbOS created by TheeMahn does the trick in about 15minutes. A nice easy trick I used for it was just copy/pasted the command to text file and just put it into terminal and baboom that ThumbOS takes off like a rocket with one question. Do you want to make it? This program needs to be in repos to knock out those other junk programs as is now the only program I would ever think of using! Will also be awesome to see those complaints of those junk programs wiped out for good!!!! To wipe the Thumb drive clean takes longer but is much more efficient! TheeMahn, can never thank you enough for taking the hassle of making a thumb drive and turning it into a total pleasure!!! Absolutely love it!!! As have said over and over will say it again. You're the best developer out here!!! Total genius!!!
This tool somewhat saved my rear yesterday. I was writing a program called keysnatcher, should I say revising the app and adding new features on my girlfriends machine. It started getting really sluggish, mouse skipping across the screen. I at first thought it was the 30 or so tabs I had open in Firefox. Couldnt even close it it just sit there when I tried to click the X, so I hit ctrl + alt+ f3 dropped to a terminal logged in and sudo killall firefox it croaked it, ctrl + alt +f7 back to the still jittery desktop. Saved my work and logged out. When I logged back in what seemed like 1000 Caja's opened up it would open 4 or 5 to me closing just one. ctrl + alt + f3 sudo killall caja was in vein it just kept opening them. sudo killall Xorg and re-logging in greeted me with the same situation.
Surely a reboot would rectify the situation, nope. O.K. kill Xorg and scrap .config and login, nope still screwed. lynx
http://www.google.com from the terminal and a search of
multiple caja and attempt to fix all said issues yeilded nil results. What am I going to do now? This is my girlfiends computer when she wakes up she is going to have a stroke....
Luckily I have my Copy account tied and synced to her PC close to 1/2 a TB of data on it including unreleased Operating Systems. From the terminal I mind you, cd /media/3TB/Copy/Ultimate\ Edition/Public/Operating\ Systems/ cp ultimate-edition-3.8-x64.iso ~ cd ~ Inserted a thumbdrive thumbos --load ultimate-edition-3.8-x64.iso sdd had it reinstalled her bookmarks imported, restricted drivers, dual monitors set up, all upgrades installed before she got up. Did she notice, yes. When she went to login to facebook it did not remember her password, now comes the explaining
I do have a newer version of this tool currently unreleased, I have alot of applications being worked at the same time I hope to bring all together. The keysnatcher is being re-written for tmosb it fixes core operating system issues. These issues reside in every Ubuntu based Operating System. A fix here goes a long way.
- Code: Select all
KeySnatcher 1.0.2, 02/12/2014
GNU KeySnatcher home page: <http://ultimateedition.info/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word KeySnatcher somewhere in the Subject: field.
Usage: KeySnatcher -<-COMMAND>
Mandatory arguments to long options are identical for short options.
possible commands...
-e --errors fix 404 errors with repositories
-f --fetch fetch missing keys
-h --help this help message
-r --rescan rescan servers to determine which is fastest
-t --timeout fix IPV6 timeout issues
-v --version dump version info
KeySnatcher --help [COMMAND] for further information.
#SAMPLE FIX FOR A MISSING KEY:
#KEY SERVER AVG PING
#keyserver.ubuntu.com 100
#pool.sks-keyservers.net 47
#subkeys.pgp.net DOWN
#pgp.mit.edu DOWN
#keys.nayr.net 64
#keys.gnupg.net 32
#Setting default keyserver as fastest server: keys.gnupg.net | 32
#Scanning for missing keys.
#Hit
http://us.archive.ubuntu.com raring Release.gpg
#...
#Fetched 316 B in 40s (7 B/s)
#Processing key: 2E183FA1E260F5B0
#gpg: requesting key E260F5B0 from hkp server keys.gnupg.net
#gpg: /home/tonie/.gnupg/trustdb.gpg: trustdb created
#gpg: key E260F5B0: public key "Launchpad PPA for Ubuntu Tweak Testing Team" imported
#gpg: Total number processed: 1
#gpg: imported: 1 (RSA: 1)
#In the above example the software has determined keys.gnupg.net is the
#fastest server, this operation is only preformed once to accelerate any future
#grabbing of missing keys. The sofware then scans for missing keys and retrieves
# any missing key from that server.
the --timeout switch will insert a 2 second timeout for repositories, IPV6 based servers will hang for like 3 minutes why it attempts to resolve them:
#Fix for the following:
#[Connecting to mirror1.mate-desktop.org (2a01:4f8:100:7003::10)]
#(2a01:4f8:100:7003::10) is IPV6 and causes great delays in retriving package lists
#The work around is to set a 2 second timeout in apt conf
Setting deliberation failures:
The app will fix the top error w/o a doubt, the rest I am working on...
- It's just a matter of time...
I hate debugging sed
sed is an awesome tool, however very finicky. Requires perfect expressions. The tool is so heavy there are pdfs written about it over 500 pages long.
all I have to do is get sed to add a # to the begining of each offending line, in this case those ppa's do not have a saucy release.
This is a thumbos thread, sorry for getting off the beaten path:
- Code: Select all
#!/bin/bash
# ==============================================================================
# title :thumbos
# description :Loads disk images to thumbdrive from the CLI.
# author :theemahn <[email protected]>
# date :01/14/2014
# version :1.0.4
# usage :thumbos --help
# manual :man thumbos
# notes :See change-log below for further information.
# ==============================================================================
# Change-log: 1.0.1: Initial Internal Beta release
#
# 1.0.2: Bug fixes
# Erase feature added.
# Test feature added.
# Display ISO and Image info
#
# 1.03 Minor bugfix see comment in code.
#
# Supress errors if end user does not possess a thumbdrive,
# exit graciously.
#
# 1.04 Edited erase routine, NTFS set as default.
#
# Added partition detection function in case user has
# multiple partitions on the thumbdrive.
#
# Added initial ©Microsft Windows support & detection
# routine.
# ==============================================================================
PROGNAME="Thumbos"
BUILDDATE="01/14/2014"
VERSION="1.0.4"
#Initiate a few arrays and vars
declare -a USBDRIVE=();
declare -a ISOINFO=('System id' 'System id' 'Volume id' 'Publisher id' 'Data preparer' 'Volume size');
((blockSize = 4 * 1024 * 1024))
sp="/-\|"
sc=0
#Not required, but optional
QEMUINSTALLED=$(which qemu)
# 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
#Prerequisite check - mkntfs
MKNTFS=$(which mkntfs)
if ! [ $MKNTFS ]; then
MKNTFS=$(which mkfs.ntfs)
fi
if ! [ $MKNTFS ]; then
echo -e "${bldred}Error: mkntfs or mkfs.ntfs program not found!${txtrst}" >&2
exit 1
fi
function CommandLineIntrepreter(){
echo -e "${bldgrn}Number of switches passed: $#"
for var in "$@"
do
array_counter=$(($array_counter + 1))
echo "Switch $array_counter: $var"
done
}
function DiskImageInfo {
# Set needed varibles, we do not need to check for existance of $1 we
# would not be here if it does not exist
EXTENSION="${1##*.}"
FILENAME="${1%.*}"
BOOTABLE=$(file $1 | grep -m1 "bootable")
#Don't put full trust in utility "file" for ISO's use the right tool
#for the right job if file failed.
if [[ $EXTENSION == 'iso' && $BOOTABLE == '' ]]; then
BOOTABLE=$(isoinfo -f -d $1 | grep -m1 "bootable")
fi
# Set Boot Flag
if [[ ${BOOTABLE} ]]; then
BOOTABLE='Yes'
else
BOOTABLE='No'
fi
#Come here my pretty ;)
echo -e -n "${txtwht}\n================================================================================${txtrst}\n"
#ISO Image? Dump info defined in Array. Makes it simple to add remove info.
printf '%-15s %s\n' \
"Image File:" "$1"
array_counter=1
for number in ${ISOINFO[@]}
do
TITLEINFO=${ISOINFO[$array_counter]}
GREPINFO=${ISOINFO[$array_counter]}
DISPLAYINFO=$(isoinfo -d -i $1 | grep -m1 "$GREPINFO" | cut -d: -f2 | sed -e 's/^[ \t]*//')
if [[ $DISPLAYINFO && $TITLEINFO ]]; then
printf '%-15s %s\n' \
"$TITLEINFO:" "$DISPLAYINFO"
fi
array_counter=$(($array_counter + 1))
done
# Dump info on boot info as detected, we may need some work here,
# lots of different types of iso's and image files
printf '%-15s %s\n' \
"Bootable:" "$BOOTABLE"
# Thusly inform end user.
if ! [[ $BOOTABLE ]]; then
echo -e "${txtred}Note: This image most likely will not boot. Proceeding.${txtrst}"
fi
WINISO=$(isoinfo -d -i $1 | grep -i "win\|microsoft")
LINUX=$(isoinfo -d -i $1 | grep -i "LINUX")
APPLE=$(isoinfo -d -i $1 | grep -i "APPLE")
echo -e -n "${txtwht}================================================================================${txtrst}\n"
# Drop additional info if acclible
if [[ $BOOTABLE && $WINISO ]]; then
echo -e "${bldgrn}This is a ©Microsoft Windows bootable ISO and will be treated as such.${txtrst}"
fi
if [[ $BOOTABLE && $LINUX ]]; then
echo -e "${bldgrn}This is a bootable Linux based operating system and will be treated as such.${txtrst}"
fi
if [[ $BOOTABLE && $APPLE ]]; then
echo -e "${bldgrn}This is a bootable Apple/ MAC based operating system and will be treated as such.${txtrst}"
fi
}
# Some eyecandy?
function spin() {
printf "\b${sp:sc++:1}"
((sc==${#sp})) && sc=0
}
function endspin() {
printf "\r%s\n" "$@"
}
function DumpArray {
#Yank on Devkit to retrieve availible USBDrives, we will process the data later
#1.0.3 fix for 0 thumbdrives dump to /dev/null to avoid output of errors.
#Open a subshell parse values.
NUSBDRIVES=$((ls -l /dev/disk/by-id/*usb* | sed 's/^.*\///g' | sed 's/[0-9]*//g' | uniq | wc -l) 2>/dev/null)
USBDRIVE=$((ls -l /dev/disk/by-id/*usb* | sed 's/^.*\///g' | sed 's/[0-9]*//g' | uniq) 2>/dev/null)
#if user has at least one USB drive dump array to screen.
if [[ $NUSBDRIVES ]]; then
echo -e "${undwht}Number of USB drives detected${txtrst}: $NUSBDRIVES"
printf '%-1s %-1s %-15s %-25s %-10s %s\n' \
"#" "DEV" "VENDOR" "LABEL" "TYPE" "SIZE"
echo -e "${txtwht}================================================================================${txtrst}"
echo -e -n "${bldgrn}${txtrst}"
array_counter=1
#Stack out a database if you will of detected USB Drives, we will strip out
#Non, hackers as we roll. No, I do not want my 1TB external showing up as
#as a thumbdrive.
for number in ${USBDRIVE[@]}
do
TESTVALUE=${USBDRIVE[$array_counter]}
REMOVABLE='2'
REMOVABLE=$(lsblk | grep -m1 $number | cut -d ':' -f2 | cut -d" " -f3)
# Removable is for debugging at this stage of development.
#Bust out udisks we need raw data on the device(s) in question.
VENDOR=$(udisks --show-info /dev/$number | grep 'vendor' | cut -d":" -f2 | sed 's/ //g')
MODEL=$(udisks --show-info /dev/$number | grep 'model' | cut -d":" -f2 | sed 's/ //g')
if [[ $VENDOR == "" ]]; then
VENDOR=$MODEL
fi
#Still no Vendor?
if ! [[ $VENDOR ]]; then
VENDOR='UNKNOWN'
fi
BYTES=$(udisks --show-info /dev/$number 2>&1 | grep -m1 'size:' | cut -d":" -f2 | sed 's/ //g')
LABEL=$(udisks --show-info /dev/$number | grep 'label:' | cut -d ":" -f2 | sed -e 's/^[ \t]*//')
if [[ $LABEL == "" ]]; then
LABEL=$(ls -l /dev/disk/by-label/ | grep $number | cut -d ":" -f2 | cut -d " " -f2 | sed 's/\\x20/ /g' 2> /dev/null)
fi
if ! [[ $LABEL ]]; then
LABEL="UNKNOWN"
fi
TYPE=$(udisks --show-info /dev/$number | grep 'type:' | cut -d ":" -f2 | sed -e 's/^[ \t]*//' | sed 's/ //g')
if [[ $TYPE == "" ]]; then
TYPE=$(blkid /dev/$number'1' | cut -d " " -f4 | cut -d'"' -f2)
if [[ $TYPE == "" ]]; then
TYPE=$(udevadm info --query=all --name=$number | grep 'ID_PART_TABLE_TYPE' | cut -d '=' -f2)
fi
fi
if ! [[ $TYPE ]]; then
TYPE="UNKNOWN"
fi
SIZE=$(echo "scale=2;${BYTES%/*}/1000/1000/1000"|bc)
#print discovered date in nice columns
printf '%-1s %-1s %-15s %-25s %-10s %-6s %s\n' \
"$array_counter" "$number" "$VENDOR" "$LABEL" "$TYPE" "$SIZE" "GB"
array_counter=$(($array_counter + 1))
done
echo -e "${txtwht}================================================================================${txtrst}"
else
echo -e "${bldred}Error: No thumbdrive(s) detected. Exiting...${txtrst}"
exit 0;
fi
}
function copyFile(){
# uncomment below for debugging.
# echo "copyFile RECIEVED 1:$1 2:$2 3:$3 4:$4"
inFile="$1"
outFile="$2"
wholeCurrentSize="$3"
# Size in blocks
size=$(stat --format=%s "$inFile")
((stepNb = size / blockSize + 1))
# Prior existance Remove file.
if [ -f "$outFile" ]; then
rm "$outFile"
fi
# Initiate Copying
i=0
while [ "$i" -lt "$stepNb" ]; do
dd if="$inFile" bs="$blockSize" skip="$i" seek="$i" of="$outFile" count=1 2> /dev/null
((i = i + 1))
# output current copied size
local copiedSize=$(stat --format=%s "$outFile")
((totalCopiedSize = copiedSize + wholeCurrentSize)) || true
((percent = (totalCopiedSize * 100) / totalSize)) || true
echo -en "$percent%\r"
done
return 0
}
function progressCp(){
# uncomment below for debugging.
# echo "progressCp Switches RECEIVED 1:$1 2:$2 3:$3 4:$4"
totalSize=$(du -s "$1" --bytes | awk '{print $1}')
currentSize=0
targetDir="$2"
mkdir -p "$targetDir"
targetDir=$(readlink -f "$targetDir")
cd "$1"
fileList=$(find .)
INDICATOR='='
while read inFile; do
if [ "$inFile" != '.' ]; then
outFile="$targetDir/$inFile"
fileSize=$(stat --format=%s "$inFile")
if [ -d "$inFile" ]; then
mkdir -p "$outFile"
elif [ -f "$inFile" ]; then
if [ "$fileSize" -lt "$blockSize" ]; then
cp "$inFile" "$outFile"
else
copyFile "$inFile" "$outFile" "$currentSize"
fi
else
echo "Error: Unknown type of '$inFile' !" >&2
exit 1
fi
# Mode
#chmod "$(stat --format=%a "$inFile")" "$outFile"
# Progress spinner and precentage
i=1
sp="/-\|"
echo -n ' '
((currentSize = currentSize + fileSize)) || true
((percent = (currentSize * 100) / totalSize)) || true
echo -en "$percent%\r"
fi
done < <(echo "$fileList")
}
function UnmountIso(){
RETURN="$?"
set +o errexit # We need to clean up everything we can
trap - HUP QUIT KILL SEGV PIPE INT TERM EXIT
echo "Syncing..."
cd /
sync
wait 2> /dev/null
sleep 1
echo -e "${bldgrn}Umounting and removing '$1'...${txtrst}"
umount "$1" && rm -rf "$1" || true
echo -e "${bldgrn}Umounting and removing '$2'...${txtrst}"
umount "$2" && rm -rf "$2" || true
}
function STARTTIMER {
# Start the counter, we are off to the races.
STARTM=`date -u "+%s"`
}
function STOPTIMER {
STOPM=`date -u "+%s"`
RUNTIMEM=`expr $STOPM - $STARTM`
if (($RUNTIMEM>59)); then
TTIMEM=`printf "%dm%ds\n" $((RUNTIMEM/60%60)) $((RUNTIMEM%60))`
else
TTIMEM=`printf "%ds\n" $((RUNTIMEM))`
fi
echo "Execution Time: $TTIMEM"
}
function QuickWipeFat() {
#Display initial header
VersionDump
#Verify the switch interpreter, if not provide short help message example.
if [[ $1 == "" ]]; then
DumpArray $1
echo -e "\n${bldred}ERROR: Please specify a device to wipe.${txtrst}"
echo -e "${bldwht}Example: thumbos --erase /dev/sdb${txtrst}"
echo -e "${bldylw}Note: the partition number is unecessary as it will erase the entire drive.${txtrst}"
exit 0;
fi
#Begin scanning for USB Devices.
echo -e "${bldgrn}\nSCANNING FOR USB DRIVE(S)..."
DETECTED=$(ls -l /dev/disk/by-id/*usb* 2> /dev/null)
#None found?
if ! [[ $DETECTED ]]; then
echo -e "${bldred}No USB drives detected. Exiting.${txtrst}"
exit 0;
fi
if [[ -b /dev/$1 ]]; then
DumpArray $1
else
echo -e "${bldred}Error: Device /dev/$1 is not vaild block device."
echo -e "${bldgrn}Example usage: thumbos --erase sdk full${txtrst}"
exit 0;
fi
NUMERALS=$(echo $2 |grep -o '[0-9]*')
if [[ $NUMERALS ]]; then
echo -e "${bldred}Error: Please provide drive letters only no numerals.${txtrst}"
exit 0;
fi
#Final check. Did the user specify a valid device?
array_counter=1
for number in ${USBDRIVE[@]}
do
REMOVABLE='2'
REMOVABLE=$(lsblk | grep -m1 $number | cut -d ':' -f2 | cut -d" " -f3)
#Debugging - future implementation?
#if [[ $REMOVABLE == 1 ]]; then
if [[ $number == $1 ]]; then
VALIDITY='YES'
fi
#fi
done
if [[ $VALIDITY ]]; then
if [[ $2 == "full" ]]; then
ETYPE='Full'
elif [[ $2 == 'secure' ]]; then
ETYPE='Secure'
else
ETYPE='Quick'
fi
#Verify write premissions to drive
THUMBDRIVE="/dev/"$1
echo -e -n "${txtwht}Verifying write permission of thumbdrive: /dev/$1: ${txtrst}"
if [[ -w ${THUMBDRIVE} ]]; then
echo -e "${bldgrn}Granted.${txtrst}"
else
echo -e "${bldred}Denied."
echo -e "Please run the command sudo thumbos --erase $@"
echo -e "${txtwht}Exiting.${txtrst}"
exit 0
fi
#User has provided valid switches / permission. Drop information and final warning in bold red to standout.
echo -e "${bldgrn}$ETYPE Erase: /dev/$1 thumbdrive?${txtwht}"
while true; do
echo -e "================================================================================${bldred}"
read -p "WARNING: this will erase all content on device /dev/$1. (Y/N)? " yn
case $yn in
[Nn]* ) echo -e "${txtrst}"; exit 0;;
[Yy]* ) echo -e "${txtgrn}"
echo "Erasing $1 thumbdrive...";
break;;
* ) echo "Please answer y or n.";;
esac
done
else
echo -e "${bldred}ERROR: $1 is not a valid device.${txtrst}"
exit 0;
fi
UNMOUNT=$(umount /dev/$1 2>/dev/null)
case "$ETYPE" in
Full) echo -e "${txtwht}Full wiping drive: $1"; dcfldd if=/dev/zero of=/dev/$1;;
Secure) echo -e "${txtwht}Securely wiping drive: $1"; dcfldd if=/dev/urandom of=/dev/$1 bs=1M;;
*) echo -e "${txtwht}Quickly wiping drive: $1"; QUICK=$(mkfs.msdos -I -n 'Blank' -F 32 /dev/$1);;
esac
echo -e "${txtwht}Syncing..."
sync
echo -e "${txtwht}Refreshing partition ..."
sudo partprobe /dev/$1 2> /dev/null
echo -e "${bldgrn}All operations completed successfully.${txtrst}"
}
function Clear() {
# Wipe Thumbdrive
# Debugging switches... Uncomment to see output.
# echo "1:$1 2:$2 3:$3 4:$4"
# exit 0;
# FORCE is an internally called switch to format drive in preparation
# for loading out M$ Windows.
if [[ $2 != "FORCE" ]]; then
#Display initial header
VersionDump
#Verify the switch interpreter, if not provide short help message example.
if [[ $1 == "" ]]; then
DumpArray $1
echo -e "\n${bldred}ERROR: Please specify a device to wipe.${txtrst}"
echo -e "${bldwht}Example: thumbos --erase /dev/sdb${txtrst}"
echo -e "${bldylw}Note: the partition number is unecessary as it will erase the entire drive.${txtrst}"
exit 0;
fi
#Begin scanning for USB Devices.
echo -e "${bldgrn}\nSCANNING FOR USB DRIVE(S)..."
DETECTED=$(ls -l /dev/disk/by-id/*usb* 2> /dev/null)
#None found?
if ! [[ $DETECTED ]]; then
echo -e "${bldred}No USB drives detected. Exiting.${txtrst}"
exit 0;
fi
if [[ -b /dev/$1 ]]; then
DumpArray $1
else
DumpArray $1
echo -e "${bldred}Error: Device /dev/$1 is not vaild block device."
echo -e "${bldgrn}Example usage: thumbos --erase sdk full${txtrst}"
exit 0;
fi
NUMERALS=$(echo $2 |grep -o '[0-9]*')
if [[ $NUMERALS ]]; then
echo -e "${bldred}Error: Please provide drive letters only no numerals.${txtrst}"
exit 0;
fi
#Final check. Did the user specify a valid device?
array_counter=1
for number in ${USBDRIVE[@]}
do
REMOVABLE='2'
REMOVABLE=$(lsblk | grep -m1 $number | cut -d ':' -f2 | cut -d" " -f3)
#Debugging - future implementation?
#if [[ $REMOVABLE == 1 ]]; then
if [[ $number == $1 ]]; then
VALIDITY='YES'
fi
#fi
done
if [[ $VALIDITY ]]; then
if [[ $2 == "full" ]]; then
ETYPE='Full'
elif [[ $2 == 'secure' ]]; then
ETYPE='Secure'
else
ETYPE='Quick'
fi
#Verify write premissions to drive
THUMBDRIVE="/dev/"$1
echo -e -n "${txtwht}Verifying write permission of thumbdrive: /dev/$1: ${txtrst}"
if [[ -w ${THUMBDRIVE} ]]; then
echo -e "${bldgrn}Granted.${txtrst}"
else
echo -e "${bldred}Denied."
echo -e "Please run the command sudo thumbos --erase $@"
echo -e "${txtwht}Exiting.${txtrst}"
exit 0
fi
#User has provided valid switches / permission. Drop information and final warning in bold red to standout.
echo -e "${bldgrn}$ETYPE Erase: /dev/$1 thumbdrive?${txtwht}"
while true; do
echo -e "================================================================================${bldred}"
read -p "WARNING: this will erase all content on device /dev/$1. (Y/N)? " yn
case $yn in
[Nn]* ) echo -e "${txtrst}Exiting..."; exit 0;;
[Yy]* ) echo -en "${txtgrn}"
echo "Erasing $1 thumbdrive...";
break;;
* ) echo "Please answer y or n.";;
esac
done
else
echo -e "${bldred}ERROR: $1 is not a valid device.${txtrst}"
exit 0;
fi
fi
STARTTIMER
# Detect number of partitions currently on thumbdrive.
TOTALPARTS=0
TOTALPARTS=$(parted -s "/dev/$1" print | tail --lines 2 | grep '^\s[0-9]\+\s\+.*$' | awk '{print $1}'| bc)
DISKSIZE=$( sudo parted -s /dev/$1 unit B print | grep "^Disk /dev/$1:" | cut -f 3 -d " " | tr -d B )
# Information overkill, the end user probably does not care
# echo "Disk size detected: $DISKSIZE"
# Unmount Volume(s) - Suppress errors for non-existant volumes
I=0;
if [[ $TOTALPARTS -gt 0 ]]; then
echo -e "${txtwht}$TOTALPARTS existing partitions detected.${txtrst}"
while [ $I -lt $TOTALPARTS ]; do
I=$(($I + 1))
TRUEDEV='/dev/'$1$I
UNMOUNT=$(umount $TRUEDEV 2>/dev/null)
done
else
echo -e "${txtylw}No existing partitions detected.${txtrst}"
fi
#Unmount Success?
if ! [[ $UNMOUNT ]]; then
echo -e "${bldgrn}Device $1 successfully unmounted the $TOTALPARTS partition(s).${txtrst}"
else
echo -e "${bldred}ERROR: $1 can not be unmounted. Are you root?${txtrst}"
exit 0;
fi
I=0;
#DUMP ALL PARTITIONS - Do not assume the enduser is in the United States.
if [[ $TOTALPARTS -gt 0 ]]; then
while [ $I -lt $TOTALPARTS ]; do
I=$(($I + 1))
TRUEDEV='/dev/'$1$I
echo -e "${txtwht}Deleting partition: $TRUEDEV${txtrst}"
sudo parted -s "/dev/$1" rm "$I"
done
else
echo -e "${txtylw}No partitions to delete.${txtrst}"
fi
#Check for non-existant partition table
ERRORCHECK=$(sudo parted -s "/dev/$1" print| grep 'unrecognised disk label')
if [[ $ERRORCHECK ]]; then
echo -e "${bldred}ERROR: No partition table exists at all, attempting to rectify.${txtrst}"
sfdisk /dev/$1 << EOF
;
EOF
sudo dd if=/dev/zero of=/dev/$1 bs=512 count=1
sudo sfdisk -A1 /dev/$1 > /dev/null 2>&1
fi
TRUEDEV='/dev/'$11
#Ensure empty table is reflected to the kernel before proceeding.
echo -e "${bldgrn}Creating a single partition 100% in size."
#Suppress standard output, we don't need to update the fstab for a thumbdrive.
sudo parted -a opt /dev/$1 unit MB mkpart primary 0% 100% > /dev/null 2>&1
sudo sync > /dev/null 2>&1
sudo partprobe $TRUEDEV > /dev/null 2>&1
#Create a single default partition
I=1
TRUEDEV='/dev/'$1$I
#Set default as NTFS
sudo sfdisk -c --change-id /dev/$1 1 07 > /dev/null 2>&1
case "$ETYPE" in
Full) echo -e "${txtwht}Full wiping drive: $1"; dcfldd if=/dev/zero of=/dev/$1;;
Secure) echo -e "${txtwht}Securely wiping drive: $1"; dcfldd if=/dev/urandom of=/dev/$1 bs=1M;;
*) echo -e "${txtwht}Quick formating drive in NTFS Format: $1"; QUICK=$(mkfs.ntfs -Q -L 'ThumbOS' "$TRUEDEV");;
esac
if [[ $QUICK ]]; then
echo -e "${txtwht}Drive $1 successfully formatted.${txtrst}"
fi
echo -e "${txtwht}Syncing...${txtrst}"
sudo sync
echo -e "${txtwht}Setting $TRUEDEV as bootable.${txtrst}"
sudo sfdisk -A1 /dev/$1 > /dev/null 2>&1
echo -e "${txtwht}Refreshing partition ...${txtrst}"
sudo partprobe /dev/$1 2> /dev/null
echo -e "${bldgrn}All partition and format operations completed successfully.${txtrst}"
STOPTIMER
}
function WindowsISO {
echo -e "${bldgrn}©Microsoft Windows ISO detected.${txtrst}"
#Debugging Switches
# echo "SENT 1:$1 2:$2 3:$3 4:$4"
#Exclusive internally called switch to force a wipe, we
#already know we have a valid device.
Clear $2 FORCE
#Create temporary mount points we will clean up later
isoMountPath="/media/thumbos_iso_$(date +%s)_$$"
partitionMountPath="/media/thumbos_target_$(date +%s)_$$"
STARTTIMER
# Mounting
REALDEV="/dev/$2"1
echo "Mounting $1 ISO..."
mkdir -p "$isoMountPath"
if [ -f "$1" ]; then # ISO
mount -o loop "$1" "$isoMountPath"
else # Real DVD drive (block)
mount "$1" "$isoMountPath"
fi
mkdir -p "$partitionMountPath"
mount "$REALDEV" "$partitionMountPath"
# Calculate needed space
freeSpace=$(df --block-size 1 "$partitionMountPath" | grep "$REALDEV" | awk '{print $4}')
neededSpace=$(du -s "$isoMountPath" --bytes | awk '{print $1}')
neededSpace=$((neededSpace + 1000 * 1000 * 30))
if [ "$neededSpace" -gt "$freeSpace" ]; then
echo -e "${bldred}Error: Not enough free space on '$REALDEV'!${txtrst}" >&2
exit 1
fi
# Copy data
echo "Copying ISO data..."
progressCp "$isoMountPath" "$partitionMountPath"
# boot dir should be lower case
if [ -d "$partitionMountPath/BOOT" ]; then mv "$partitionMountPath/BOOT" "$partitionMountPath/boot"; fi
if [ -d "$partitionMountPath/Boot" ]; then mv "$partitionMountPath/Boot" "$partitionMountPath/boot"; fi
# Install Grub
echo "Installing grub, please wait ..."
grub-install --root-directory="$partitionMountPath" "$REALDEV" > /dev/null 2>&1
uuid=$(blkid -o value -s UUID "$REALDEV")
# grub.cfg
echo "Installing grub.cfg..."
cfgFilename="$partitionMountPath/boot/grub/grub.cfg"
mkdir -p "$(dirname "$cfgFilename")"
echo -n "" > "$cfgFilename"
echo "echo '------------------------------------'" >> "$cfgFilename"
echo "echo '| ThumbOS - Loading... |'" >> "$cfgFilename"
echo "echo '------------------------------------'" >> "$cfgFilename"
echo "insmod ntfs" >> "$cfgFilename"
echo "search --no-floppy --fs-uuid $uuid --set root" >> "$cfgFilename"
echo "chainloader +1" >> "$cfgFilename"
echo "boot" >> "$cfgFilename"
# Cleanup and exit
echo -e "${bldgrn}Cleaning up.${txtrst}"
UnmountIso "$isoMountPath" "$partitionMountPath" 'Cleanup'
STOPTIMER
#Prompt for testing?
if [[ $QEMUINSTALLED ]]; then
while true; do
echo -e "================================================================================"
read -p "Would you like to test the drive now in a virtual machine?. (Y/N)? " yn
case $yn in
[Nn]* ) echo -e "${txtrst}"; exit 0;;
[Yy]* ) echo -e "${txtgrn}"
echo "Booting $2...";
break;;
* ) echo "Please answer y or n.";;
esac
done
qemu-system-x86_64 -enable-kvm -m 256 --boot menu=on -usb $REALDEV
fi
exit 0
}
function Loadit() {
#Display initial header
VersionDump
#Verify the switch interpreter, if not provide short help message example & exit.
if [[ $1 == "" ]]; then
echo -e "\n${bldred}ERROR: Please specify an ISO to load to thumbdrive.${txtrst}"
echo -e "${bldwht}Example: thumbos --load ultimate-edition-4.0-x64.iso sdc${txtrst}"
echo -e "${bldylw}Note: the partition number is unecessary as it will replace the entire drive.${txtrst}"
exit 0;
fi
#display information about selected iso:
if [[ -e $1 ]]; then
DiskImageInfo $1
else
echo -e "${bldred}$1 does not exist. Please specify an ISO to load.${txtrst}"
exit 0;
fi
#Begin scanning for USB Devices.
echo -e "${bldgrn}\nSCANNING FOR USB DRIVE(S)..."
DETECTED=$(ls -l /dev/disk/by-id/*usb* 2> /dev/null)
#None found?
if [[ $DETECTED == "" ]]; then
echo -e "${bldred}No USB drives detected. Exiting.${txtrst}"
exit 0;
fi
#proper switches provided?
if [[ -e $1 && $2 != "" ]]; then
DumpArray $1
else
DumpArray $1
if [[ -e "$1" ]]; then
if [[ ${USBDRIVE[@]} && $2 == "" ]]; then
echo -e "${bldred}Please provide one of the destinations above.${txtrst}"
echo -e "${bldwht}Example: thumbos --load ultimate-edition-4.0-x64.iso sdc${txtrst}"
echo -e "${bldylw}Note: the partition number is unecessary as it will replace the entire drive.${txtrst}"
exit 0;
fi
else
echo -e "${bldred}$1 does not exist. Please specify an ISO.${txtrst}"
exit 0;
fi
fi
#Scan for partition numbers a no, no.
NUMERALS=$(echo $2 |grep -o '[0-9]*')
if [[ $NUMERALS ]]; then
echo -e "${bldred}Error: Please provide drive letters only no numerals.${txtrst}"
exit 0;
fi
#Final check. Did the user specify a valid device?
array_counter=1
for number in ${USBDRIVE[@]}
do
REMOVABLE='2'
REMOVABLE=$(lsblk | grep -m1 $number | cut -d ':' -f2 | cut -d" " -f3)
#Debugging - future implementation?
#if [[ $REMOVABLE == 1 ]]; then
if [[ $number == $2 ]]; then
VALIDITY='YES'
THUMBDRIVE='/dev/'$2
fi
#fi
done
if [[ $VALIDITY ]]; then
#Verify write premissions to drive
echo -e -n "${txtwht}Verifying write premissions to thumbdrive ${THUMBDRIVE}: ${txtrst}"
if [[ -w ${THUMBDRIVE} ]]; then
echo -e "${bldgrn}Granted.${txtrst}"
else
echo -e "${bldred}Denied."
echo -e "Please run the command sudo thumbos --load $@"
echo -e "${txtwht}Exiting.${txtrst}"
exit 0
fi
#User has provided valid switches. Drop information and warning.
echo -e "${bldgrn}Load: $1 to: $2 thumbdrive?${txtwht}"
while true; do
echo -e "================================================================================${bldred}"
read -p "WARNING: this will erase all content on device $2. (Y/N)? " yn
case $yn in
[Nn]* ) echo -e "${txtrst}Exiting ..."; exit 0;;
[Yy]* ) echo -en "${bldgrn}"
echo -e "Dumping $1 to thumbdrive $2...${txtrst}";
break;;
* ) echo "Please answer y or n.";;
esac
done
#Whack the thumbdrive and load it as requested.
#Is drive mounted? If so unmount drive. Suppress errors if not
#mounted.
#Windows Bootable ISO?
if [[ $BOOTABLE && $WINISO ]]; then
WindowsISO $1 $2 $3 $4
fi
#Click the timer, we are starting.
STARTTIMER
DUMPIT=$(umount /dev/$2 2>/dev/null)
#convert image to hybrid bootable image.
isohybrid $1
#Use dcfldd - forensic based version of dd aka "Disk Destroyer"
#we like nice toys.
dcfldd sizeprobe=if statusinterval=10 bs=4M if=$1 of=/dev/$2
#Ensure all data even buffered is written to the disk.
sync
#Set drive active
echo -e "${bldgrn}Setting $2 device as bootable.${txtrst}"
SUPPRESS=$(sfdisk -A /dev/$2 2>/dev/null)
else
echo -e "${bldred}$2 is not a vaild device. Please refer to the table above.${txtrst}"
# Correction in #1.0.3, no sence in syncing or refreshing the
# Partition table if an invaild device was specified. Exit.
exit 0;
fi
echo -e "${txtwht}Syncing..."
sync
echo -e "${txtwht}Refreshing partition ..."
sudo partprobe /dev/$2 2> /dev/null
echo -e "${bldgrn}All operations completed successfully.${txtrst}"
STOPTIMER
#Prompt for testing?
if [[ $QEMUINSTALLED ]]; then
while true; do
echo -e "================================================================================"
read -p "Would you like to test the drive now in a virtual machine?. (Y/N)? " yn
case $yn in
[Nn]* ) echo -e "${txtrst}"; exit 0;;
[Yy]* ) echo -e "${txtgrn}"
echo "Booting $2...";
break;;
* ) echo "Please answer y or n.";;
esac
done
qemu-system-x86_64 -enable-kvm -m 256 --boot menu=on -usb /dev/$2
fi
}
function Help() {
VersionDump
if [[ $1 == "" ]];
then
PRAM="ALL"
else
PRAM=$1
fi
case $PRAM in
ALL)
echo -e "
${bldgrn}Usage: $PROGNAME -<-COMMAND> [option]${txtrst}
Mandatory arguments to long options are identical for short options.
possible commands...
-e --erase erases the entire thumbdrive
-l --load load ISO image to thumbdrive
-h --help this help message
-s --scan scans / reports thumbdrive(s) and exits
-t --test test boot device and exit
-v --version dump version info
${bldgrn}$PROGNAME --help [COMMAND] for further information.${txtrst}";;
ALL|e|erase)
echo -e "
${bldwht}Usage erase;${txtrst}
${txtgrn}$PROGNAME -e <DEVICE> [quick|secure|full]${txtrst}
Quickly erases the contents of <DEVICE> thumbdrive.
Example: ${bldgrn}$PROGNAME --erase sdi secure${txtrst}
If the [full] or [secure] option is used it will wipe the entire drive. This
is a slow process and the information is non-recoverable. Specifing no option
is the same as using the default [Quick] option.
${bldred}Warning: The contents of the device will be entirely wiped and
unrecoverable using the secure or full option.${txtrst}
${txtylw}Note: The partition number is not necessary as the entire drive will be wiped.${txtrst}";;
ALL|s|scan)
echo -e "
${bldwht}Usage scan;${txtrst}
${txtgrn}$PROGNAME -s${txtrst}
Scans and reports availible thumbdrive(s).";;
ALL|t|test)
echo -e "
${bldwht}Usage test;${txtrst}
${txtgrn}$PROGNAME -t [DEVICE]${txtrst}
Invokes a virtual machine to boot [DEVICE].";;
ALL|l|load)
echo -e "
${bldwht}Usage load;${txtrst}
${txtgrn}$PROGNAME -l <ISONAME> <DEVICE>${txtrst}
Loads selected ISO to selected thumbdrive. Optionally will launch kvm for
testing.
Example: ${bldgrn}thumbos --load utimate-edition-4.0-x64.iso sdi
${bldred}Warning: The contents of the device will be entirely wiped.${txtrst}
${bldylw}Note: the partition number is unecessary as it will replace the entire drive.${txtrst}";;
ALL|v|version)
echo -e "
${bldwht}Usage version;${txtrst}
${txtgrn}$PROGNAME -v${txtrst}
Displays $PROGNAMEs version number and exits.";;
ALL|h|help|\?)
echo -e "
${bldwht}Useage Help [COMMAND];${txtrst}
${txtgrn}$PROGNAME -h [COMMAND]${txtrst}
Displays this message. For futher information $PROGNAME help [COMMAND]
or refer to the manpages.
man $PROGNAME"
echo -e "${txtgrn}"
echo -e "Example: $PROGNAME -h version"
echo -e "${txtwht}Will display help about the command version${txtrst}"
esac
exit 0
}
function VersionDump {
echo -e "${undwht}$PROGNAME $VERSION, $BUILDDATE${txtrst}
GNU $PROGNAME home page: <http://ultimateedition.info/>.
E-mail bug reports to: <[email protected]>.
Be sure to include the word $PROGNAME somewhere in the Subject: field."
}
# Command line pre-processor
CommandLineIntrepreter $@
function Virtual {
if [ -e "$1" ]; then
echo -e "${bldgrn}Testing ISO: $1 in a virtual machine.${txtrst}"
qemu-system-x86_64 -enable-kvm -m 256 --boot d menu=on cdrom=$1
else
echo -e "${bldgrn}Testing thumbdrive $1 in a virtual machine.${txtrst}"
qemu-system-x86_64 -enable-kvm -m 256 --boot menu=on -usb /dev/$1
fi
}
case "$1" in
-s|--scan) VersionDump; DumpArray; exit 0;;
-t|--test) VersionDump; Virtual $2; exit 0;;
-e|--erase) Clear $2 $3 $4; exit 0;;
-l|--load) Loadit $2 $3 $4; exit 0;;
-h|--help|-\?) Help $2; exit 0;;
-v|--version) VersionDump; exit 0;;
*) Help; exit 0;;
esac
Substantially larger. I can no longer say currently unreleased
Feel free to report bugs / errors.
I am looking into building a new PC, not for me but as a server to build operating systems. A
nasty machine that is the tip of the iceburg in cost. Drop 2 16 core AMD Operons on it SSD the whole ball of wax. I will probably have to buy it one part at a time, unless I hit the lottery lol They do get
heavier 64 cores, can you imagine the raw speed?