pkgbuild postinstall script causes "Installation failed" on others' Macs - objective-c

I have an issue in my custom installer that occurs when I append a postinstall script to the pkg. On my computer the installation works just fine, but on other users' systems the .app is installed but the postinstall script fails without execution.
If I remove the --scripts argument on pkgbuild, the installer produces no issues. If I add it (and even if the postinstall script is empty) a "failed installation" message is shown. No logs are produced.
The pkg is built using a script similar to this:
pkgbuild --identifier $PKG_IDENTIFIER \
--version $APP_VERSION \
--root $APP_PATH \
--scripts Scripts/ \
--install-location /Applications/$APP_NAME.app $TMP_PKG_PATH
productbuild --sign "Developer ID Installer: $COMPANY_NAME" \
--distribution Distribution.xml \
--package-path $INSTALLER_BUILD_PATH $INSTALLER_PKG_PATH
On my system the app is installed into /Applications and the postinstall script runs and does it's business. On other systems the postinstall doesn't even seem to be executed at all.
It has been tested on OSX 10.8 and 10.7 and both get the same issue. The postinstall script is tested independently on all systems (using ./postinstall in the Terminal) and works.
The script looks like this:
#!/usr/bin/env sh
set -e
# Install launch agent
LAUNCH_AGENT_SRC="/Applications/MyApp.app/Contents/Resources/launchd.plist"
LAUNCH_AGENT_DEST="$HOME/Library/LaunchAgents/com.company.myapp.agent.plist"
# Uninstall old launch agent
if [ -f "$LAUNCH_AGENT_DEST" ]; then
launchctl unload "$LAUNCH_AGENT_DEST"
rm -f "$LAUNCH_AGENT_DEST"
fi
cp "$LAUNCH_AGENT_SRC" "$LAUNCH_AGENT_DEST"
launchctl load "$LAUNCH_AGENT_DEST"
# Open application
open -a "MyApp"
exit 0
What could be causing this issue?

It seems the cause of the issue was the if statement. And when it wasn't present the contents of the if could cause the error to fire unless the launch agent was installed already.
I solved it by switching the code for:
#!/usr/bin/env sh
set -e
# Launch agent location
LAUNCH_AGENT_SRC="/Applications/MyApp.app/Contents/Resources/launchd.plist"
LAUNCH_AGENT_DEST="$HOME/Library/LaunchAgents/com.company.myapp.agent.plist"
# Uninstall old launch agent
launchctl unload "$LAUNCH_AGENT_DEST" || true
rm -f "$LAUNCH_AGENT_DEST" || true
# Install launch agent
cp "$LAUNCH_AGENT_SRC" "$LAUNCH_AGENT_DEST" || true
launchctl load "$LAUNCH_AGENT_DEST" || true
# Open application
open -a "MyApp"
exit 0
The error I made before when testing an empty script was not having exit 0 at the end. So now when I got that working I could activate different rows of the code and see what was causing an error.

You might have found your answer already, and it's a bit hard to say without looking at the script, but can you make sure that you have "exit 0" at the end of your postinstall script?

Related

New Ubuntu RVM package - I used to use the wrappers binary folder for executables, but which one now?

whenever I run my install scripts for deploying new code, I used to use the /home/<$USER>/.rvm/gems/ruby-2.6.5/wrappers/bundle folder for hard coding executable paths to bundler
Since I see that there is now a separate installation now specifically for ubuntu and that folder path no longer exists, what should I use in my install scripts?
doing things like the following in my deployment scripts does not seem to find bundle
sudo -u <my-user> bash << eof
echo 'remove the current cron tasks'
crontab -r
echo 'running bundle install'
bundle install
echo 'install cron tasks'
(crontab -l 2>/dev/null; echo "00 13 * * * /bin/bash /var/www/application/bin/daily.sh")| crontab -
crontab -l
eof

Running PMD in GitLab CI Script doesn't work unless echo command is added after the script runs

This is an interesting issue. I have a GitLab project, and I've created a .gitlab-ci.yml to run a PMD that will scan my code after every commit. The ci.yml file looks like this:
image: "node:latest"
stages:
- preliminary-testing
apex-code-scan:
stage: preliminary-testing
allow_failure: false
script:
- install_java
- install_pmd
artifacts:
paths:
- pmd-reports/
####################################################
# Helper Methods
####################################################
.sfdx_helpers: &sfdx_helpers |
function install_java() {
local JAVA_VERSION=11
local JAVA_INSTALLATION=openjdk-$JAVA_VERSION-jdk
echo "Installing ${JAVA_INSTALLATION}"
apt update && apt -y install $JAVA_INSTALLATION
}
function install_pmd() {
local PMD_VERSION=6.52.0
local RULESET_PATH=ruleset.xml
local OUTPUT_DIRECTORY=pmd-reports
local SOURCE_DIRECTORY=force-app
local URL=https://github.com/pmd/pmd/releases/download/pmd_releases%2F$PMD_VERSION/pmd-bin-$PMD_VERSION.zip
# Here I would download and unzip the PMD source code. But for now I have the PMD source already in my project for testing purposes
# apt update && apt -y install unzip
# wget $URL
# unzip -o pmd-bin-$PMD_VERSION.zip
# rm pmd-bin-$PMD_VERSION.zip
echo "Installed PMD!"
mkdir -p $OUTPUT_DIRECTORY
echo "Going to run PMD!"
ls
echo "Start"
pmd-bin-$PMD_VERSION/bin/run.sh pmd -d $SOURCE_DIRECTORY -R $RULESET_PATH -f xslt -P xsltFilename=pmd_report.xsl -r $OUTPUT_DIRECTORY/pmd-apex.html
echo "Done"
rm -r pmd-bin-$PMD_VERSION
echo "Remove pmd"
}
before_script:
- *sfdx_helpers
When I try to run this pipeline, it will fail after starting the PMD:
However, if I make a small change to the PMD's .sh file and add an echo command at the very end. Then the pipeline succeeds:
PMD /bin/run.sh before (doesn't work):
...
java ${HEAPSIZE} ${PMD_JAVA_OPTS} $(jre_specific_vm_options) -cp "${classpath}" "${CLASSNAME}" "$#"
PMD /bin/run.sh after (does work):
...
java ${HEAPSIZE} ${PMD_JAVA_OPTS} $(jre_specific_vm_options) -cp "${classpath}" "${CLASSNAME}" "$#"
echo "Done1" // This is the last line in the file
I don't have the slightest idea why this is the case. Does anyone know why adding this echo command at the end of the .sh file would cause the pipeline to succeed? I could keep it as is with the echo command, but I would like to understand why it is behaving this way. I don't want to be that guy that just leaves a comment saying Hey don't touch this line of code, I don't know why, but without it the whole thing fails. Thank you!
PMD exits with a specific exit code depending whether it found some violations or not, see https://pmd.github.io/latest/pmd_userdocs_cli_reference.html#exit-status
I guess, your PMD run finds some violations, and PMD exits with exit code 4 - which is not a success exit code.
In general, this is used to make the CI build fail, in case any PMD violations are present - forcing to fix the violations before you get a green build.
If that is not what you want, e.g. you only want to report the violations but not fail the build, then you need to add the following command line option:
--fail-on-violation false
Then PMD will exit with exit code 0, even when there are violations.
So it appears that the java command that the PMD runs for some reason returns a non-zero exit code (even though the script is successful). Because I was adding an echo command at the end of that bash script, the last line in the script returned a success exit code, which is why the GitLab CI pipeline succeeded when the echo command was there.
In order to work around the non-zero exit code being returned by the java PMD command, I have changed this line in my .gitlab-ci.yml file to catch the non-zero exit code and proceed.
function install_pmd() {
// ... For brevity I'm just including the line that was changed in this method
pmd-bin-$PMD_VERSION/bin/run.sh pmd -d $SOURCE_DIRECTORY -R $RULESET_PATH -f xslt -P xsltFilename=pmd_report.xsl -r $OUTPUT_DIRECTORY/pmd-apex.html || echo "PMD Returned Exit Code"
// ...
}

Unable to connect to PostgreSQL from makefile and run migration scripts

I'm currently working on a simple project which is accessing the Github API.
PostgreSQL is used only to get more familiar with it.
I encountered a problem when trying to run the migration scripts from a makefile. This issue does only occur when I'm using make, by applying the migration scripts manually works fine.
The idea is to do this when running "make install":
Start the PostgreSQL container
Run migration scripts
Stop & remove the container
include ./config/dbConfig.env
all: install
.PHONY: all
install :
#runns all migration script. To run a specific migration version build more targets.
#echo "Get latest https://github.com/golang-migrate/migrate image"
docker pull migrate/migrate
#echo "Starting postgreSQL database"
docker run -t -d \
--name dev \
--env-file $(shell pwd)/config/dbConfig.env \
-p 5432:5432 \
-v $(shell pwd)/postgres:/var/lib/postgresql/data postgres
#echo "Wait for database"
sleep 5
#echo "Sun migration scripts"
docker run \
-v $(shell pwd)/migrations:/migrations \
--network host migrate/migrate \
-path=/migrations/ \
-database "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}#localhost:5432/?sslmode=disable" up
# for specific migration: ....432/?sslmode=disable" up {{add integer migration number}}
#echo "Stop and remove PostgreSQL container"
docker stop `docker ps -aqf "name=dev"`
docker rm `docker ps -aqf "name=dev"`
You can also find the latest version is on the branch "develop" or this specific commit here
Error:
error: read tcp [::1]:34022->[::1]:5432: read: connection reset by peer
Why am I unable to connect to the server from the makefile but if I run the same procedure manually it works? Do you maybe have any ideas about why the behavior is not consistent?

Installation of sql relay fails

I just created a docker container and tried to install SQL Relay inside it.
I've checked the prerequisites here and followed the installation documents here.
However, at the end of make install of sqlrelay, I saw an error like this:
update-rc.d: /etc/init.d/sqlrelay: file does not exist
update-rc.d: /etc/init.d/sqlrcachemanager: file does not exist
make[1]: *** [install] Error 1
make[1]: Leaving directory `/sqlrelay-0.66.0/init'
make: *** [install-init] Error 2
What might be wrong with my installation?
Here's the docker file I used to start my installation:
FROM ubuntu:trusty
RUN apt-get update && \
apt-get install libxml2-dev libpcre3 libpcre3-dev libmysqld-dev -y
RUN apt-get install mysql-server libmysqlclient-dev -y
# sql relay prerequisites
RUN apt-get install g++ make perl php5-dev python-dev ruby-dev \
tcl-dev openjdk-7-jdk erlang-dev nodejs-dev node-gyp mono-devel \
libmariadbclient-dev libpq-dev firebird-dev libfbclient2 libsqlite3-dev \
unixodbc-dev freetds-dev mdbtools-dev -y
COPY rudiments-0.56.0.tar.gz /
COPY sqlrelay-0.66.0.tar.gz /
EXPOSE 80
Here are the outputs of ./configure, make, and make install inside sqlrelay-0.66.0 folder:
configure_log
make_log
make_install_log
If you need more information of my installation process, just let me know. I can provide it.
I think you should use ADD instead of COPY in your lines such as
COPY rudiments-0.56.0.tar.gz /
Your COPY just copies the .tar.gz, but does not unpack them
as with ADD
If the <src> parameter of ADD is an archive in a recognised compression format, it will be unpacked
This is extracted from
What is the difference between the `COPY` and `ADD` commands in a Dockerfile?
I have recently hit the same issue. The issue I found was that the init Makefile was incorrectly detecting the use of systemctl on Ubuntu Trusty and putting the scripts there. Later on the script would try to find the scripts in init.d and fail.
The solution is to edit the Makefile: sqlrelay-X.X.X/init/Makefile
Replace:
install:
if ( test -d "/lib/systemd/system" ); \
With:
install:
if ( test -d "/lib/systemd/system_x" ); \
Make a similar change to the uninstall option later in the script and it will now correctly install on Ubuntu.

bundle not found via ssh

If I ssh into my VPS as the deployment user and run bundle -v I get Bundler version 1.1.5 as expected.
If I run ssh deployment#123.123.123.123 bundle -v, then I see bash: bundle: command not found
Why isn't bundle being shown running commands via ssh?
More Info
$ cat ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
fi
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
When you run:
ssh deployment#123.123.123.123
You get a login shell on the remote host, which means that your shell will run (...for bash...) .bash_profile or .profile or equivalent AS WELL AS your per-shell initialization file.
When you run:
ssh deployment#123.123.123.123 some_command
This does not start a login shell, so it only runs the per-shell initialization file (e.g., .bashrc).
The problem you've described typically means that you need something in your .profile file (typically an environment variable setting) for everything to work.