I have made this script which:
- Clones all repositories from Bitbucket to folder "temporary projects" . To clone the repos, script is using my "repolinks.csv" which is generally what the name says, links to repos saved as text file :)
- After every repo Is cloned, the script search for all .ttf files in every folder(repo) in "temporaryprojects" and saves result(which are paths to every ttf file) as TTF-Project-Paths
- OTFINFO part is reading paths to .ttf files (TTF-Projects-Paths) and give me specified info about those ttf files (family, subfamily,author etc.) and saves it as "TTF-Projects-INFO"
#!/bin/bash
cd /Users/krzysztofpaszta/temporaryprojects
for repo in $(cat /users/krzysztofpaszta/repolinks.csv); do
git clone "$repo"
echo Repo cloned to /users/krzysztofpaszta/temporaryprojects
done
#tablica z nazwa repo (repo_links na przykład) repo pętla
echo Pobieranie ścieżek wszystkich plików TTF na urządzeniu z projektow Boombit
find "/users/krzysztofpaszta/temporaryprojects/" -name "*.ttf" > /Users/krzysztofpaszta/TTF-Projects-PATHS.csv
echo Sciezki plikow pobrane
while read in; do
otfinfo --info filename="${fullfile##*/}" >> /users/krzysztofpaszta/TTF-Projects-INFO.csv "$in"
done < /users/krzysztofpaszta/TTF-Projects-PATHS.csv
echo dane plikow pobrane
rm -vrf /Users/krzysztofpaszta/temporaryprojects/*
echo Repo deleted
Everything is working great but now I am struggling how to modify this script. As you can see, right now all the repos are downloaded and then all the info about repos are saved in one file named TTF-Project-INFO. What I need it to do is to search for every repo singly and save the results as $repo.csv (name of one repo as csv) and to it constantly to the last repo in "repolinks.csv" I modified the script like that:
#!/bin/bash
cd /Users/krzysztofpaszta/temporaryprojects
for repo in $(cat /users/krzysztofpaszta/repolinks.csv); do
git clone "$repo"
find "/users/krzysztofpaszta/temporaryprojects/$repo" -name "*.ttf" > /Users/krzysztofpaszta/$repo.csv
echo Repo cloned to /users/krzysztofpaszta/temporaryprojects
while read in; do
otfinfo --info filename="${fullfile##*/}" >> /users/krzysztofpaszta/TTF-Projects-INFO.csv "$in"
done < /users/krzysztofpaszta/TTF-Projects-PATHS.csv
But unfortunately it is doing actually the same this. Saves every repo to "temporary projects" and then search for every .ttf file paths and then info and saves those info in one file. I think it is just pretty simple loop in bash but I have no idea how to do it properly. Could someone give me some hint? I was trying to modify the script but no luck so far.
SAMPLES OF CSV'S: TTF-Projects-Paths.csv:
/users/krzysztofpaszta/temporaryprojects/project1/Fonts/SwallowFallsMixAllCyryl.ttf
/users/krzysztofpaszta/temporaryprojects/project2/Fonts/KOMIKAZE.ttf
/users/krzysztofpaszta/temporaryprojects/project2/Graphics/Fonts/Arial Unicode.ttf
/users/krzysztofpaszta/temporaryprojects/project3/fonts/SwallowFallsMixAll.ttf
TTF-Projects-INFO.csv:
/users/krzysztofpaszta/temporaryprojects/project1/Fonts/LiberationSans.ttf:Family: Liberation Sans
/users/krzysztofpaszta/temporaryprojects/project1/Fonts/LiberationSans.ttf:Subfamily: Regular
/users/krzysztofpaszta/temporaryprojects/project1/Fonts/LiberationSans.ttf:Full name: Liberation Sans
/users/krzysztofpaszta/temporaryprojects/project1/Fonts/LiberationSans.ttf:PostScript name: LiberationSans
etc... project2, project3 with the same info about fonts.
repolinks.csv:
https://bitbucket.org/organisation/project1-settings https://bitbucket.org/organisation/crave-man https://bitbucket.org/organisation/adverts https://bitbucket.org/organisation/pipeline https://bitbucket.org/organisation/data https://bitbucket.org/organisation/async https://bitbucket.org/organisation/audio
etc..
CodePudding user response:
If you want to use $repo.csv
instead of the same file for all repos, change the output file in the appending redirection:
# old
>> /users/krzysztofpaszta/TTF-Projects-INFO.csv
# new
>> /users/krzysztofpaszta/"$repo".csv
The name of the directory is not the whole URL, just the last part, which you can extract in bash using parameter expansion:
dir=${repo##*/} # Remove everything up to the last slash.
Proper indenting helps understanding of the flow:
#!/bin/bash
cd /Users/krzysztofpaszta/temporaryprojects
for repo in $(cat /users/krzysztofpaszta/repolinks.csv); do
git clone "$repo"
dir=${repo##*/}
echo Repo cloned to /users/krzysztofpaszta/temporaryprojects
find /users/krzysztofpaszta/temporaryprojects/"$dir" -name "*.ttf" > /users/krzysztofpaszta/TTF-list-"$dir".csv
while read in ; do
otfinfo --info filename="${fullfile##*/}" "$in" >> /users/krzysztofpaszta/"$dir".csv
done < /users/krzysztofpaszta/TTF-list-"$dir".csv
done
I'm not sure what $fullfile
is, so I left it as was.