Skip to content

Instantly share code, notes, and snippets.

@christian-oudard
Created September 21, 2022 05:52
Show Gist options
  • Save christian-oudard/3c26d90651b7eb142008267d289e966a to your computer and use it in GitHub Desktop.
Save christian-oudard/3c26d90651b7eb142008267d289e966a to your computer and use it in GitHub Desktop.
Automate running pCloud from the command line with 1password and expect
#! /usr/bin/bash
# Account information.
OP_EMAIL=<email>
OP_MOUNTPOINT=/home/<username>/pCloudDrive
OP_USER_ID=<user-id> # Gotten from `op account list`.
# Stop server.
if [[ $1 == 'stop' ]]; then
expect -f - >/dev/null <<END_EXPECT
spawn pcloudcc --commands_only
expect "pCloud console client v.2.0.1\r
Supported commands are:\r
startcrypto <crypto pass>, stopcrypto, finalize, q, quit\r
> "
send -- "finalize\r"
expect eof
END_EXPECT
exit 0
fi
# Get passwords.
op whoami >/dev/null 2>&1
if [[ $? == 1 ]]; then
eval $(op signin --account $OP_USER_ID)
export "OP_SESSION_$OP_USER_ID"
fi
PASSWORD=$(op item get pcloud --fields label="password")
CRYPTO_PASS=$(op item get pcloud --fields label="crypto pass")
# Start server.
expect -f - >/dev/null <<END_EXPECT
spawn pcloudcc --daemonize --username=$OP_EMAIL --mountpoint $OP_MOUNTPOINT --password --crypto
expect "pCloud console client v.2.0.1\r
Please, enter password\r
"
send -- "$PASSWORD\r"
expect "Enter crypto password.\r
Please, enter password\r
"
send -- "$CRYPTO_PASS\r"
expect eof
END_EXPECT
@rjcab
Copy link

rjcab commented Apr 11, 2024

Hello. I tried but I got the error:

root@pve:~/pcloud# ./pcloudstartup.sh ./pcloudstartup.sh: line 29: op: command not found ./pcloudstartup.sh: line 30: op: command not found root@pve:~/pcloud#

Do I need to do something with:

PASSWORD=$(op item get pcloud --fields label="password")
CRYPTO_PASS=$(op item get pcloud --fields label="crypto pass")

thanks

@christian-oudard
Copy link
Author

christian-oudard commented Apr 11, 2024 via email

@rjcab
Copy link

rjcab commented Apr 11, 2024

but sorry what is 1password, a package to download ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment