diff --git a/create_secret_file.sh b/create_secret_file.sh index ca22cb44a4956a538f6f18fcec439a55dd0be5b4..07ff6052002b0c64fb7eecd9b420bd77d172a0a7 100755 --- a/create_secret_file.sh +++ b/create_secret_file.sh @@ -3,6 +3,8 @@ filename="$1" gpg_pubkey_id="$2" # leave empty to use default receipt. +[[ "$filename" = '' ]] && echo "Usage: $0 <filename> [gpg_pubkey_id]" && exit 1 + echo '>>> Please type keyring_name and password in the following format: keyring1:password1 @@ -13,5 +15,10 @@ login:12345678 >>> When you are done, use Ctrl-D to end.' -gpg --encrypt -o "$filename" -a -r "$gpg_pubkey_id" -exit $? +if [[ "$gpg_pubkey_id" = '' ]]; then + gpg --encrypt -o "$filename" -a + exit $? +else + gpg --encrypt -o "$filename" -a -r "$gpg_pubkey_id" + exit $? +fi diff --git a/on_gnome_start.sh b/on_gnome_start.sh new file mode 100644 index 0000000000000000000000000000000000000000..c72cdceed896b2163f8d611336b8e3f6658ce4ce --- /dev/null +++ b/on_gnome_start.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# This script should be run after gnome being started. + +_my_path="$0" +secret_file="$1" + +[[ "$secret_file" = '' ]] && echo "Usage: $0 <secret_file>" && exit 1 + +function where_is_him () { + SOURCE="$1" + while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + echo -n "$DIR" + } + +function where_am_i () { + where_is_him "$_my_path" +} + +cd `where_am_i` && +gpg --decrypt "$secret_file" | bin/unlock_keyrings --secret-file - # --quiet + +exit $? + + diff --git a/src/unlock_keyrings.cc b/src/unlock_keyrings.cc index 3425f6c8ef313b3deec29274e634efe9cac52ee8..8e829aedf905a58b6e548ef95bd9649918344129 100644 --- a/src/unlock_keyrings.cc +++ b/src/unlock_keyrings.cc @@ -3,17 +3,17 @@ #include <rlib/stream.hpp> #include "keyring_op.hpp" +rlib::logger rlog(std::cerr); int main(int argc, char **argv) { rlib::opt_parser args(argc, argv); - rlib::logger rlog(std::cout); if(args.getBoolArg("-h", "--help")) { rlog.info("Usage: {} [-h/--help] [-q/--quiet] --secret-file <filename> # use `-` as stdin."); return 0; } if(args.getBoolArg("-q", "--quiet")) { - rlog = rlib::logger(rlib::null_stream); + rlog.set_log_level(rlib::log_level_t::FATAL); } auto secret_file_name = args.getValueArg("--secret-file"); @@ -43,7 +43,7 @@ int main(int argc, char **argv) { auto res = do_unlock(keyring_and_pswd.at(0), keyring_and_pswd.at(1)); auto msg = keyringResultToString(res); if(res == GNOME_KEYRING_RESULT_OK) - rlog.verbose("line {}: {}.", line_num, msg); + rlog.info("line {}: {}.", line_num, msg); else { rlog.error("line {}: {}.", line_num, msg); no_error = false; diff --git a/unlock_keyring_from_secret_file.sh b/unlock_keyring_from_secret_file.sh new file mode 100755 index 0000000000000000000000000000000000000000..43e30718bdcc5a907640bedd5033bf1fd9b3909c --- /dev/null +++ b/unlock_keyring_from_secret_file.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# This script should be run after gnome being started. + +_my_path="$0" +secret_file="$1" + +[[ "$secret_file" = '' ]] && echo "Usage: $0 <secret_file>" && exit 1 + +function where_is_him () { + SOURCE="$1" + while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + echo -n "$DIR" + } + +function where_am_i () { + where_is_him "$_my_path" +} + +cd `where_am_i` && +gpg --decrypt "$secret_file" | bin/unlock_keyrings --secret-file - --quiet + +exit $? + +