For rotating Google service accounts to bypass bans or any other myriad of reasons.
So I just do not have time to update this anymore or provide help but the good news is there is a new and improved version which covers a lot of gaps that mine had and you should switch over to it, as it will be less buggy. This was my first real project into programming and while it was fun I do not feel it is worth spending more time on. This program will now be archived, but can still be utilized if you choose but any remaining bugs will do just that, remain.
To find this new version go here:
SARotate written by saltydk and toutas
- [Added] Renamer script to rename
.json
files from something like safire. - [Changed] Formatted code to smaller in size.
- [Changed] Moved loop for minsa into a function for more portability.
- [Added] Added flag
(-f)
to use the minimum service account set if you want to the rclone.conf to start from the minsa value. - [Changed/Fixed] Adjusted the logic to be correct and not the same service account outside of the setting.
- [Added] Pushover support for apprise. If your apprise notification is not a part of the script yet let me know.
- [Changed] Added return code so the apprise doesn't go through every option, and only the 1 if off is returned.
- [Changed] Changed text a little bit for log rotation.
- [Fixed] Logr would return an issue with a character of the code. It is now fixed.
- [Added] New version.
- [Added] Uses a logger to easily identify issues.
- [Added] Script will check to see if the config you loaded exists, has information and if it matches the name you input.
- [Added] Much better logic for the handling of rotation.
- [Added] Now has much more error handling built in to prevent simple mistakes.
- [Added] Has a new
-h | help
option to let you know how to run the script../sarotate -h
- [Added] Can utilize the same service account on all teamdrives if you wish within the config.
- [Added] Script will now check to see if your service accounts are within the minjs and maxjs set inside the config.
- [Added] Script will now "remember" the last used service account. It does this by reading the last set service account and uses logic to determine if it needs to change it or use it.
- [Added] Script will now rotate logs based on the size you have set. It will keep the last log file but with an appended number.
- [Changed] Overall improved and made the script easier to read and fixed issues it had before.
- [Changed] Changed apprise notifications. Now supports discord/slack by default with the config file.
- [Old] Installs the dependency needed (yyq) to utilize the script.
- [Old] Uses a .yml file for a more customized and easier configuration.
- [Old] Uses passed arguments through -c if you want to use more than one config file.
- [Old] Can define whichever rclone/lclone/fclone/gclone variant you want in config.
- [Old] Can utilize different rclone config files in config.
- [Old] Added header with version number and credits.
- [Old] Comments in the .yml file will be stripped before being run through the script.
- [Deleted] Old versions.
This script was created with the help of 88lex. This was written mainly for CloudBox users but can be utilized by anyone.
- Any dependencies needed are taken care of by the script besides rclone.
- rclone:
curl https://rclone.org/install.sh | sudo bash
| Minimum version of 1.51.
-
cd /opt
-
git clone https://github.com/Visorask/sarotate.git
-
sudo chown -R <user>:<group> sarotate
- Runid
to find your user / group. -
cd /opt/sarotate && chmod +x sarotate renamer
renamer
is a script for renaming your files from000001.json
to1.json
. This is required as that is how my script runs them.- To run the script do:
./renamer -f /your/sa/path
- This will rename all of your
.json
files into a readable format for my script. - WARNING:
renamer
will NOT work with files named with alphabet characters. Example:i-don't-like-numbers-01.json
-
cp config.yml.sample config.yml
if you want comments in your config orcp config.yml.nocomments config.yml
if you do not want comments. -
nano config.yml
Edit the variables to match your settings. Save and close. -
Once you have done all this then you will need to restart the mounts you want to rotate before running this script. A command might look like this:
sudo systemctl restart <example>.service
Otherwise you might get an error like this:
Failed to rc: Failed to read rc response: 404 Not Found: {
"error": "couldn't find method \"backend/command\"",
"input": {
"command": "set",
"fs": "<remotename>:",
"opt": {
"service_account_file": "<file/path/1.json>"
}
},
"path": "backend/command",
"status": 404
}
# General rclone variables.
rclone:
# Default rclone config. Change this if you have a non-standard rclone config location.
rclone_config: "$HOME/.config/rclone/rclone.conf"
# Match rclone rc mount user and pass. If you use --no-auth then leave as default.
rc_user: "user"
# Match rclone rc mount user and pass. If you use --no-auth then leave as default.
rc_pass: "pass"
# Default is localhost/127.0.0.1 but you can change this to match your IP for RC.
ip: 127.0.0.1
# Global variables
global:
# Minimum json file that you want to use.
minjs: 1
# Maximum json file that you want to use.
maxjs: 50
# Use 1 or 101. 101 will split API usage to separate projects, but needs many service accounts.
nextjs: 1
# Location of the directory with your service account files.
json_dir: "/your/path/here"
# Time the script will sleep for until running again.
sleeptime: 15m
# Set this if you would like to use the same service account for all remotes.
# |on|off(default)|
same_sa: off
# Log variables
log:
# Name that you want your log file to have.
logr_name: "sarotate"
# Directory that you want your log files stored in.
logr_dir: "/opt/sarotate/logs"
# At what size do you want your log to rotate. 1 is default. (MB)
logr_size: 1
# How detailed do you want your output to be from the script.
# |quiet(Supresses everything except errors and rclone output.)|verbose(default)(Everything is printed.)|
logr_detail: verbose
# rclone --log-level.
# |DEBUG|INFO|ERROR(recommended)|NOTICE(default for rclone)|
log_level: ERROR
apprise:
# Apprise notifications.
# |discord|slack|off(default)|
notif: off
# Insert discord webhook information.
# https://github.com/caronc/apprise/wiki/Notify_discord
disc_id: "{WebhookID}/{WebhookToken}"
# Insert webhook information.
# https://github.com/caronc/apprise/wiki/Notify_slack
slack_id: "{tokenA}/{tokenB}/{tokenC}"
# Insert webhook information.
# https://github.com/caronc/apprise/wiki/Notify_pushover
pushover_id: "{user_key}@{token}"
# When filling these out you need to make sure the order of remote/port goes together or else
# the script will read wrong input/output and give errors.
main:
remote:
- teamdrive1
- teamdrive2
- teamdrive3
- teamdrive4
port:
- 5572
- 5573
- 5574
- 5575
For the script to work you must edit your mounts to have either --rc-no-auth
or --rc-user=<username>
and --rc-pass=<password>
. You can add those into a live mount by doing:
sudo nano /etc/systemd/system/<nameofmount>.service
(Fill in with your information.)sudo systemctl daemon-reload
sudo systemctl restart /etc/systemd/system/<nameofmount>.service
(Fill in with your information.)./sarotate -c <config>.yml
crontab -e
- Add
@reboot sleep 1m && /opt/sarotate/sarotate
cd /opt/sarotate/system
nano sarotate.service
- Edit the user / group from
changethis
to your user / group. -Runid
to find your user / group. - Exit and save the file.
sudo cp /opt/sarotate/system/sarotate.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable sarotate.service
sudo systemctl start sarotate.service
- If you would like to check that it is running working correctly run:
sudo service sarotate status
Will add more as people run into any issues.
BTC: 37iSj3YR1YP56fQi1Ue8fk1cYCuSmCugUB