Bash script - Automatically enter user input (password of keystore)

51,751

You could use expect utility to automate your passphrase input. Create launcher script auto-jar.sh:

#! /usr/bin/expect

# Wait for finish forever after send password
set timeout -1
# Put your jarsigner command here
spawn jarsigner ...
expect "Enter Passphrase for keystore: "
send "your jar password\r"
# Wait for jarsigner command finish
expect eof
# Return relevant exit code of jarsigner command
# , useful if you want continue next command only after signed successfully with `&&`
foreach {pid spawnid os_error_flag exit_code} [wait] break
exit "$exit_code"

Then chmod +x auto-jar.sh to make it executable and run with ./auto-jar.sh. Or run as expect auto-jar.sh.

Share:
51,751

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I know this has been asked before but almost only workarounds have been provided. None that solved my problem just yet.

    I'm trying to create my own .sh file which will generate an apk. After using jarsigner it asks for a password of my keystore. Now the security on this part doesn't play a role a.t.m. so I was just wondering, how can I (either remove the password of my .keystore file or enter the password as plain text) achieve this?

    The full command:

    jarsigner -sigalg SHA1withRSA -digestalg SHA1 -verbose -keystore keyForApk.keystore 
      apk/android-release-unsigned.apk alias_name
    

    Where it then prompts me the following:

    Enter Passphrase for keystore:
    

    Now via which command can I enter this dynamically after the jarsigner command?

    • Admin
      Admin over 7 years
      I'm not familiar with jarsigner, but it's possible that it's trying to directly read your terminal; test it out with echo | jarsigner -sigalg .... rest of it
    • Admin
      Admin over 7 years
      for testing you can provide passwords in the command line with options -storepass and -keypass. see man jarsigner.
  • canbax
    canbax almost 5 years
    "spawn" is not found. I installed expect and "expect" is found