Last active
April 16, 2022 10:55
-
-
Save Aceralon/d121f0ebae838ca4a690a129fa58ce19 to your computer and use it in GitHub Desktop.
Auto hard link for pt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Set this in qb | |
#bash /config/hardLink.sh "%N" "%F" "%R" "%D" "%C" "%Z" "%I" | |
torrent_name=$1 | |
content_dir=$2 | |
root_dir=$3 | |
save_dir=$4 | |
files_num=$5 | |
torrent_size=$6 | |
file_hash=$7 | |
log_dir="/config" #Log | |
media_location="YOUR_MEDIA_lOCATION" #Link to folder | |
if [ -f "${content_dir}" ]; then | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Type:file" >>${log_dir}/qb.log | |
target_folder=${save_dir#*/} | |
target_folder=${target_folder#*/} | |
target_folder="${media_location}/${target_folder%/*}" | |
if [ ! -d "${target_folder}" ]; then #folder not exists | |
mkdir "$target_folder" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Make directory: ${target_folder}" >>${log_dir}/qb.log | |
fi | |
if [ ! -f "${target_folder}/${content_dir##*/}" ]; then #file not exists | |
command="cp -ul '${content_dir}' '${target_folder}'" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Running: ${command}" >>${log_dir}/qb.log | |
eval ${command} | |
command="chown -R 1026 '${target_folder}'" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Running: ${command}" >>${log_dir}/qb.log | |
eval ${command} | |
command="chmod -R 755 '${target_folder}'" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Running: ${command}" >>${log_dir}/qb.log | |
eval ${command} | |
else | |
echo "ERROR: [$(date '+%Y-%m-%d %H:%M:%S')] : File: "${target_folder}/${content_dir##*/}" exists" >>${log_dir}/qb.log | |
fi | |
elif [ -d "${content_dir}" ]; then | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Type:directory" >>${log_dir}/qb.log | |
target_folder=${content_dir#*/} | |
target_folder=${target_folder#*/} | |
target_folder="${media_location}/${target_folder}" | |
if [ ! -d "${target_folder}" ]; then ##folder not exists | |
command="cp -url '${content_dir}' '${target_folder}'" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Running: ${command}" >>${log_dir}/qb.log | |
eval ${command} | |
rmnfo="rm -f '${target_folder}/*.nfo'" #remove nfo files, nfo files are often edited by media service. | |
eval ${rmnfo} | |
command="chown -R 1026 '${target_folder}'" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Running: ${command}" >>${log_dir}/qb.log | |
eval ${command} | |
command="chmod -R 755 '${target_folder}'" | |
echo "INFO: [$(date '+%Y-%m-%d %H:%M:%S')] Running: ${command}" >>${log_dir}/qb.log | |
eval ${command} | |
else | |
echo "ERROR: [$(date '+%Y-%m-%d %H:%M:%S')] Folder exists ${target_folder}" >>${log_dir}/qb.log | |
fi | |
else | |
echo "ERROR: [$(date '+%Y-%m-%d %H:%M:%S')] Unknown type: ${content_dir}, abort" >>${log_dir}/qb.log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment