#!/bin/sh
#] 
#] *********************
#] $ bash  "$d_bin""appimage [,un]mount.sh"  "[un]mount"  "[electrum, myCrypto, jaxx]"  
# www.BillHowell.ca 14Dec2020 initial

# myCrypto Debian doesn't work?  I can [,un]mount it, but it doesn't run 

# from https://superuser.com/questions/1301583/how-can-i-extract-files-from-an-appimage
# Kurt Pfeifle, edited May 19 '19 at 11:14, answered Jan 1 '19 at 16:59
# https://github.com/AppImage/AppImageKit/releases


appImage_mount()  
{  
d_appimage="/media/bill/appimage"  	# notice - no trailing `/, this is added below as needed
p_AppRun="$d_appimage""AppRun"  

if		[ "mount" == "$1" ]; then 
	if  [ -d "$d_appimage" ]; then 
		echo '"$d_appimage" directory already exists (has been mounted)'  
	else
		echo 'making $d_appimage'
		sudo mkdir  "$d_appimage"
	fi
	if  [ -f "$p_AppRun" ]; then 
		echo '$p_AppRun already exists (AppRun is ready to run)'  
	else
		echo 'mounting "$p_AppRun"'  
			my_offset=$( "$p_App" --appimage-offset ) 
		#	my_offset="$p_App"" --appimage-offset"  
		#	my_offset="$p_App"  
		echo 'mount offset for "$p_App" = '"$my_offset"
		sudo mount "$p_App"  "$d_appimage"/  -o offset="$my_offset"
		# 05Mar2021 how do I run p_AppRun?			
			# 19Feb2021 jUST CLICK ON AppRun icon in file manager
	fi
elif	[ "unmount" == "$1" ]; then 
	sudo umount "$d_appimage"
else
	echo '"$d_bin""appimage [,un]mount.sh" :  unrecognized argument "'"$1"'"'  
fi
}  


# you can inspect the contents
# "$d_appimage""/AppRun" --appimage-help
# 123456   This is just an example my_offset output

# Do not forget the umount step!
# If you do forget it, your system may exhibit unwanted behavior.

# code error?
# 		sudo mount "$p_App"  "$d_appimage"/ -o offset="$my_offset"
#p_appimage="$d_bin""runtime-x86_64"

# olde code
#	if  [ -f "$p_AppRun" ]; then 
#		echo '$p_AppRun already exists (AppRun is ready to run'  
#	else
#		echo 'mounting AppImage with : "$p_AppRun"'  
#		my_offset=$( "$p_App" --appimage-offset ) 
#		#my_offset="$p_App"" --appimage-offset"  
#		echo 'mount offset for "$p_App" = '"$my_offset"
#		sudo mount "$p_App"  "$d_appimage" -o offset="$my_offset"
#	fi


# 20Feb2021 NOT using Exodus : 
exodus_run()
{  
	bash -c "cd \`dirname %k\` && ./Exodus %u"
}  


wallet_select() 
{  
if 	[ "electrum"   == "$2" ]; then 
	p_App="$d_Midas""Investments/cryptos/electrum-4.0.7-x86_64.AppImage"  
	appImage_mount "$1" 
elif	[ "myCrypto"   == "$2" ]; then 
	p_App="$d_Midas""Investments/cryptos/linux-x86-64_1.7.13_MyCrypto.AppImage"  
	appImage_mount "$1" 
elif	[ "jaxx"   == "$2" ]; then 
	p_App="$d_Midas""Investments/cryptos/Jaxx.Liberty-2.5.0.AppImage"  
	appImage_mount "$1" 
else
	echo '"$d_bin""appimage [,un]mount.sh" :  unrecognized wallet "'"$2"'"'  
fi
}  


# bash  -c  "cd  /media/bill/Midas/Investments/cryptos/Exodus-linux-x64  && ./Exodus %u"   

#	https://tldp.org/LDP/abs/html/special-chars.html
#	Chapter 3. Special Characters
#	`	command substitution. 
#		The `command` construct makes available the output of command for assignment to a variable. 
#		This is also known as backquotes or backticks.
#	
#	% modulo. Modulo (remainder of a division) arithmetic operation.
#	    let "z = 5 % 3"
#	    echo $z  # 2
#	  In a different context, the % is a pattern matching operator.

wallet_select  "$1"  "$2"  



# enddoc
