Is there a way of combining bash scripts? - ruby

I am using chef to write a recipe that installs mysql connector, extracts it and moves the .jar to the /lib folder.
bash "install_mysql-connector" do
user "root"
cwd "/opt/tomcat/lib/"
code <<-EOH
wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.29.tar.gz
tar -zxvf mysql-connector-java-5.1.29.tar.gz
EOH
end
bash "setting_mysql-connector" do
user "root"
cwd "/opt/tomcat/lib/mysql-connector-java-5.1.29"
code <<-EOH
mv mysql-connector-java-5.1.29-bin.jar /opt/tomcat/lib/
rm -rf mysql-connector-java-5.1.29.tar.gz
EOH
end
Is there a way of combining these two so they run under the same bash?
I also tried extracting JUST the mysql-connector-java-5.1.29-bin.jar from the tar.gz file using
tar -zxvf mysql-connector-java-5.1.29.tar.gz -C /opt/tomcat/lib mysql-connector-java-5.1.29-bin.jar
Is something missing from this?

How about this? Extract the jar file out of .tar.gz and save under /opt/tomcat/lib directly?
tar -zxvf mysql-connector-java-5.1.29.tar.gz mysql-connector-java-5.1.29-bin.jar -O > /opt/tomcat/lib/mysql-connector-java-5.1.29-bin.jar

Related

Github action zip doesn't find the files on self hosted worker

I've been trying to archive files after compilation matching the wildcard **/dist when I look into my _work folder of my GitHub action worker, I see the files and if I run the zip command from shell, it works fine, but in action, it throws an error saying it can't find any files matching
zip error: Nothing to do! (try: zip -qq -r archive.zip . -i **/dist)
Yet when I run directly in the runner ls -la **/dist I get a list of over 200 files
I was also able to reproduce the issue by adding the command inside my package.json then when I run yarn archive I get the same issue as GitHub action
"archive": "pwd && ls -la **/dist && zip -r **/dist",
Output of yarn archive
yarn run v1.22.19
$ pwd && ls -la **/dist && zip -r **/dist
/home/mathieu_auclair/actions-runner/_work/server/server
ls: cannot access '**/dist': No such file or directory
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
It is about how the shell will interpret the wildcards used.
I would try and put the set of commands ls -la **/dist && zip -r **/dist in a bash executable script starting with #!/bin/bash, and call said script instead of chaining commands with '**'.
The OP MathieuAuclair confirms in the comments:
Indeed, I was able to fix it by making the zip command specification more detailed, I guess it's compatible between both interpretations
zip -r archive.zip . --include **/dist/**

How to re-link files in iron.io?

I'm trying to upload the following files and linksto iron.io:
After downloading the files from iron.io that were originally uploaded, I can see that the links are turned into these files
How do I maintain the links so that they are not turned into files in the process of uploading to iron.io.
Ideally, I can run this bash script on iron.io to solve for this:
rm libicudata.so.50 && ln -s libicudata.so.50.1.2 libicudata.so.50
rm libicui18n.so.50 && ln -s libicui18n.so.50.1.2 libicui18n.so.50
rm libicuio.so.50 && ln -s libicuio.so.50.1.2 libicuio.so.50
rm libicule.so.50 && ln -s libicule.so.50.1.2 libicule.so.50
rm libiculx.so.50 && ln -s libiculx.so.50.1.2 libiculx.so.50
rm libicutu.so.50 && ln -s libicutu.so.50.1.2 libicutu.so.50
rm libicuuc.so.50 && ln -s libicuuc.so.50.1.2 libicuuc.so.50
For reference, this is my worker:
# set the runtime language. Python workers use "python"
runtime "python"
# exec is the file that will be executed:
exec "test.py"
stack 'selenium'
remote
file "iron.json"
file "test.py"
dir '/Library/dataextract/'
I upload this worker with the following bash script:
iron_worker upload test
You can't "upload" a symlink. It's a symbolic link, there's no way to "send" it anywhere. You can create a tarball and upload that instead.
cd /path/to/the/files && tar cvf libs.tar *
Then on the receiving server, untar the files:
cd /path/to/the/files && tar xvf libs.tar
Assuming the symlinks are relative and pointing to files in the same directory, they will probably be successfully preserved. If they are absolute, they may be pointing to the wrong location.

sh script to build from source Ubuntu

Im trying to automate some dependency installing from an sh script, however, I feel that not all commands are getting through.
Here is an example:
#!/bin/sh
cd /Downloads
sudo wget https://github.com/tpaviot/oce/archive/OCE-0.16.1.tar.gz
sudo tar -xvf OCE-0.16.1.tar.gz
cd oce-OCE-0.16.1/
sudo mkdir build
cd build
sudo cmake ../
sudo make
sudo make install/strip
Is this valid in a .sh script?

Updating discourse

Anyone know why this line in these updating instructions don't work.
https://github.com/discourse/discourse/blob/master/docs/INSTALL-ubuntu.md#updating-discourse
DATESTAMP=$(TZ=UTC date +%F-%T)
pg_dump --no-owner --clean discourse_prod | gzip -c > ~/discourse-db-$DATESTAMP.sql.gz
tar cfz ~/discourse-dir-$DATESTAMP.tar.gz -C /var/www discourse
The first 2 lines work and I can see the .gz file being created in my home directory.
But when I run the third line tar cfz ~/discourse-dir-$DATESTAMP.tar.gz -C /mydiscourse directory it fails and give me an error:
tar: no files or directories specified
I even changed it to
tar cfz ~/discourse-db-$DATESTAMP.tar.gz -C /mydiscourse directory
because db is the name of the file. not dir but this still is giving me an error. Does anyone know what this could be?

Can't get shell script to run in Xcode

I'm fairly new to running scripts in Xcode and haven't been able to figure out whats wrong with the script I'm running. The first script I ran was this:
/bin/sh -x
PBXCP=${DEVELOPER_DIR}/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp
${PBXCP} -exclude .svn "${PROJECT_DIR}/../../base"
"${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
Which caused me to run into this error:
/Users/newperson/Library/Developer/Xcode/DerivedData/appname-etesgjzdmfzimlgvakidckjecgij
/Build
/Intermediates/appname.build/Debug-iphonesimulator/app.build/Script-
435F41A90F532CA300887552.sh: line 3: /Applications/Xcode.app/Contents/Developer/Library
/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp: No such file or directory
This error was fairly to the point, The file the script is looking for doesn't exist. The newer versions of Xcode have gotten rid of pbxcp. So I started looking for a good alternative script to run that wouldn't use pbxcp, when I found this:
/bin/sh -x
/usr/bin/tar -c -C "${PROJECT_DIR}/myframeworks" --exclude .DS_Store --exclude CVS --exclude
.svn --exclude .git -H `cd "${PROJECT_DIR}/myframeworks" && find DevToolsCore.framework` |
/usr/bin/tar -x -C ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}
This script also caused me to run into a problem, which was this:
tar: could not chdir to '/Users/newperson/Library/Developer/Xcode/DerivedData/appname-
etesgjzdmfzimlgvakidckjecgij/Build/Products/Debug-iphonesimulator/appname.app/Frameworks'
tar: Write error
Command /bin/sh failed with exit code 1
I couldn't find a clear answer to what this error meant, one forum suggest that I use the sudo command in my script to give the script permission to change directory, so I ran this:
/bin/sh -x
/usr/bin/tar -c -C "${PROJECT_DIR}/myframeworks" --exclude .DS_Store --exclude CVS --exclude
.svn --exclude .git -H `cd "${PROJECT_DIR}/myframeworks" && find DevToolsCore.framework`
| sudo /usr/bin/tar -x -C ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}
This script caused me to run into this error though:
tar: Write error
Command /bin/sh failed with exit code 1
++ find DevToolsCore.framework
sudo: no tty present and no askpass program specified
tar: Write error
This is as far as I got so far, I am fairly lost with my limited knowledge of shell script so any help correcting my script or finding a suitable replacement for the Xcode framework that contains pbxcp would be appreciated.
Change the permissions of the directory where your script wants to write files. Do it in an interactive session of Terminal:
$ sudo chmod a+w the_directory
Then you should be able to run your script (without sudoing the tar).

Resources