Updating discourse - terminal

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?

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/**

Is there a way of combining bash scripts?

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

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).

Downloading and automatically installing a tgz file

#!/bin/bash
mkdir /tmp
curl -O http://www.mucommander.com/download/nightly/mucommander-current.app.tar.gz /tmp/mucommander.tgz
tar -xvzf /tmp/mucommander.tgz */mucommander.app/*
cp -r /tmp/mucommander.app /Applications
rm -r /tmp
I'm trying to create a shell script to download and extract muCommander to my applications directory on a Mac.
I tried cd into the tmp dir, but then the script stops when I do that.
I can extract all using the -C argument, but the current tgz path is muCommander-0_9_0/mucommander.app, which could change on later builds, so I'm trying to keep it generic.
Can anyone give me pointers where I'm going wrong?
Thanks in advance.
Strip the first path component when you untar the archive, from tar(1):
--strip-components count
(x mode only) Remove the specified number of leading path ele-
ments. Pathnames with fewer elements will be silently skipped.
Note that the pathname is edited after checking inclusion/exclu-
sion patterns but before security checks.
Update
Here is a working bash example of how to, fairly generically, copy the contents of the tgz file to /Applications.
shopt -s nocaseglob
TMPDIR=/tmp
APP=mucommander
TMPAPPDIR=$TMPDIR/$APP
mkdir -p $TMPAPPDIR
curl -o $TMPDIR/$APP.tgz http://www.mucommander.com/download/nightly/mucommander-current.app.tar.gz
tar --strip-components=1 -xvzf $APP.tgz -C $TMPAPPDIR
mv $TMPAPPDIR/${APP}* /Applications
# rm -rf $TMPAPPDIR $TMPDIR/$APP
The rm command is commented out for now, verify that it does no harm before you use it.
The following will update your muCommander.
#for the safety, remove old temporary extraction from the /tmp
rm -rf /tmp/muCommander.app
#kill the running mucommander - you dont want replace the runnung app
ps -ef | grep ' /Applications/muCommander.app/' | grep -v grep | awk '{print $2}' | xargs kill
#download, extract, remove old, move new, open
#each command run only when the previous ended with success
curl http://www.mucommander.com/download/nightly/mucommander-current.app.tar.gz |\
tar -xzf - -C /tmp --strip-components=1 '*/muCommander.app' && \
rm -rf /Applications/muCommander.app && \
mv /tmp/muCommander.app /Applications && \
open /Applications/muCommander.app
Beware, after the '\' must following new line, and not any spaces...

How to unpack and pack pkg file?

I have a pkg file created by Install Maker for Mac.
I want to replace one file in pkg. But I must do this under Linux system, because this is a part of download process. When user starts to download file server must replace one file in pkg.
I have a solution how unpack pkg and replace a file but I dont know how pack again to pkg.
http://emresaglam.com/blog/1035
http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html
Packages are just .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of that file hierarchy is a cpio.gz archive of the actual installables, and usually that's what you want to edit. And there's also a Bom file that includes information on the files inside that cpio archive, and a PackageInfo file that includes summary information.
If you really do just need to edit one of the info files, that's simple:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
# edit stuff
xar -cf ../Foo-new.pkg *
But if you need to edit the installable files:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc |cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o | gzip -c > Payload
mkbom Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar -cf ../Foo-new.pkg
I believe you can get mkbom (and lsbom) for most linux distros. (If you can get ditto, that makes things even easier, but I'm not sure if that's nearly as ubiquitously available.)
Here is a bash script inspired by abarnert's answer which will unpack a package named MyPackage.pkg into a subfolder named MyPackage_pkg and then open the folder in Finder.
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
pkgutil --expand "$filename" "$dirname"
cd "$dirname"
tar xvf Payload
open .
Usage:
pkg-upack.sh MyPackage.pkg
Warning: This will not work in all cases, and will fail with certain files, e.g. the PKGs inside the OSX system installer. If you want to peek inside the pkg file and see what's inside, you can try SuspiciousPackage (free app), and if you need more options such as selectively unpacking specific files, then have a look at Pacifist (nagware).
You might want to look into my fork of pbzx here: https://github.com/NiklasRosenstein/pbzx
It allows you to stream pbzx files that are not wrapped in a XAR archive. I've experienced this with recent XCode Command-Line Tools Disk Images (eg. 10.12 XCode 8).
pbzx -n Payload | cpio -i
In addition to what #abarnert said, I today had to find out that the default cpio utility on Mountain Lion uses a different archive format per default (not sure which), even with the man page stating it would use the old cpio/odc format. So, if anyone stumbles upon the cpio read error: bad file format message while trying to install his/her manipulated packages, be sure to include the format in the re-pack step:
find ./Foo.app | cpio -o --format odc | gzip -c > Payload
#shrx I've succeeded to unpack the BSD.pkg (part of the Yosemite installer) by using "pbzx" command.
pbzx <pkg> | cpio -idmu
The "pbzx" command can be downloaded from the following link:
pbzx Stream Parser
If you are experiencing errors during PKG installation following the accepted answer, I will give you another procedure that worked for me (please note the little changes to xar, cpio and mkbom commands):
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc | cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o --format odc --owner 0:80 | gzip -c > Payload
mkbom -u 0 -g 80 Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar --compression none -cf ../Foo-new.pkg
The resulted PKG will have no compression, cpio now uses odc format and specify the owner of the file as well as mkbom.
Bash script to extract pkg: (Inspired by this answer:https://stackoverflow.com/a/23950738/16923394)
Save the following code to a file named pkg-upack.sh on the $HOME/Downloads folder
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
mkdir "$dirname"
# pkgutil --expand "$filename" "$dirname"
xar -xf "$filename" -C "$dirname"
cd "$dirname"/*.pkg
pwd
# tar xvf Payload
cat Payload | gunzip -dc |cpio -i
# cd usr/local/bin
# pwd
# ls -lt
# cp -i * $HOME/Downloads/
Uncomment the last four lines, if you are using a rudix package.
Usage:
cd $HOME/Downloads
chmod +x ./pkg-upack.sh
./pkg-upack.sh MyPackage.pkg
This was tested with the ffmpeg and mawk package from rudix.org (https://rudix.org) search for ffmpeg and mawk packages on this site.
Source : My open source projects : https://sourceforge.net/u/nathan-sr/profile/

Resources