Removing/restoring registry key/value on uninstall that was not added during install - setup-project

Program has option that adds a registry key from Settings, but I'd like to remove it on uninstall.
I have tried making a special startup argument on the main program that would check if user ever created that key, then remove/restore it. Then I used that argument in 'Custom Action > Uninstall > Primary output from x' with that in the 'arguments', thinking it will start the program, but this is never started.
Is that the right place for this or is there a more elegant solution?

Related

How can I permanently set an environment variable using Autotools?

I'm adapting an existing program to use Autotools for its build, but the resulting process depends on an environment variable. Is there a way to permanently set this environment variable during the build or installation process?
The program is intended to be used by Unix users and I could try to concatenate an export command directly to the .bashrc file and warn the user in case it fails because most of them will actually just use Ubuntu to run it (it's a relatively simple program that targets students), but I'd like to know if there's a more portable way to do this.
That's what I wouldn't like to do:
export VAR=/my/totally/not/hardcoded/path >> $HOME/.bashrc
Sorry to come to this late, but all of the answers to date are shockingly ... incomplete.
Building and installing software are both core use cases for the Autotools, and the installation part can absolutely involve adding or modifying files that affect user environments. If the software is installed by a user with sufficient privilege, then such effects can absolutely be applied to all system users, though the details may vary a bit from system to system (and the Autotools can help with that, too!).
For example, on RedHat-family Linuxes such as RedHat Enterprise, Fedora, Oracle Linux, and various others, you can drop an appropriately named file in /etc/profile.d, and the commands in it will automatically be read and executed by every login shell. Setting environment variables for all users is one of the common uses of this feature. I'm uncertain about Debian-family Linuxes such as Ubuntu, but it is always possible to modify file /etc/profile instead to have the same effect, and you absolutely can write an Automake install hook to do that.
Or for an altogether different approach, you can always provide a wrapper script around your program that sets the needed environment variables (supposing that the point is other than to add a directory to the PATH so as to find the program in the first place). In that case, you can even install the main program in a location that is not ordinarily in the path, so that users don't accidentally run it directly. This mechanism has the advantage that the environment variables are scoped to a run of the program, not a whole login session, but the disadvantage that users cannot override them.
I guess, no.
Autotools are about building your program, not about environment setup for the program to run. That's what users/admins are supposed to do. (Well I can imagine doing this, but I really don't want to try to figure it out, because the idea itself seems broken to me)
If your program REALLY needs some environment variable during run-time, then you should patch your sources for your application to test if the variable exists, and set one to default desired value, if it doesn't. Another idea is to enforce usage of an obligatory command line switch to pass the value in.
It's not clear what this has to do with autotools (or any other build system). No build system, by itself, can arrange for an env var to be present when the program it builds is run at a later tiem.
One solution is for your program to have a hardcoded default value for the var which is used if the environment var isn't present when the program starts running. Another frequently used solution is to name your binary something like myprog.bin and install a shell script named myprog which sets up the environment before doing exec myprog.bin.
I'm adapting an existing program to use Autotools for its build, but the resulting process depends on an environment variable. Is there a way to permanently set this environment variable during the build or installation process?
You've not been very concrete about what the program is (e.g. is the program a daemon? A user program?) or the nature of the environment variable dependency (e.g. is it another program? A mount point? A URL? A DB connection string?). Being more specific might give a better answer for you.
Anyway, autotools is not likely to offer any feature to help: It's a build system. Depending on the nature of your environment variable dependency, you're likely going to need package management (if you package it) or system administration level setup.
Since you think your primary user base is on Ubuntu this help page might give you some ideas.

How to Delete a Phabricator Diff

I made a diff in Phabricator containing a config file with sensitive information. Usually I would be content with abandoning the diff, but I don't want anybody seeing my password (even after I change it)
I should have been more careful when making my commit but it has already been done.
Take a look at the ./bin/remove command:
NAME
remove - remove objects
SYNOPSIS
remove command [options]
Administrative tool for destroying objects permanently.
WORKFLOWS
destroy [options] object ...
Permanently destroy objects.
help [command]
Show this help, or workflow help for command.
log
Show a log of permanently destroyed objects.
Use help command for a detailed command reference.
Use --show-standard-options to show additional options.

Changing publisher name and URL

So, yeah, the form is saying:
Please contact the system administrator to change your publisher name
and I'm the system administrator for the project and I don't know what the hell am I doing. :)
I can change the name of the publisher but not the URL. I guess this also changes some URL in the dataset? Do I need to do the change with API or there is some GUI?
BTW. I'm using DGU package.
You should ssh to your server and run commands like this to change the name, and optionally the title too with the -t:
source /home/co/ckan/bin/activate && cd /vagrant/src/ckanext-dgu
python ../ckanext-dgu/ckanext/dgu/bin/publisher_rename.py $CKAN_INI highways-agency highways-england -t 'Highways England'
From: http://guidance.data.gov.uk/publisher_editing.html#rename-a-publisher
The problem is it can take a few minutes to rename and reindex all the datasets, so this often can't be done during a web request. Ideally someone would code this as a background task so this can still be done in the form. However in the meantime DGU implemented this command-line script to do it, hence the need for a sysadmin.

R package with code that only runs once (per installation)

I'd like to create an R package that, upon installation, displays contact information for the maintainer and ask the user for permission to count them in our list of installations. It would also be acceptable to have the code run the first time the user calls one of our functions, instead of immediately on installation. Either way, this message should only appear once ever (unless the user reinstalls / updates the package).
What I've considered:
I know how to include a dataset for internal use, but I don't know how to change that data permanently.
We could set an environment variable / app setting, but I don't know if there's a way to make that persist after the end of the session.
Using an external service / server would be excessively heavyweight, and wouldn't allow users who don't want to be tracked to turn off the message.
Is there a good way to do this?
This can run more than once but only within a limited time window so perhaps it is good enough.
Add this code to your package and it will issue the message any time the package is loaded within 7 days of installation and thereafter it will not issue the message again until the package is updated.
It works by comparing the time the install files were created to the current time. It does not require write permissions to any directory, only read, so it should work generally.
.onLoad <- function(libname, pkgname) {
ctime <- file.info(find.package(pkgname, libname))$ctime
if (difftime(Sys.time(), ctime, unit = "day") < 7)
packageStartupMessage("This msg will go away one week after installing this package")
}
You may have to bite the bullet and store state information across sessions to show it once and only once.
Some packages which may help:
settings which retrieves user configuration settings
config which retrieves configuration information
httr which access config info
registry which offers a registry
pkgconfig offers private configuration.
but I am not sure which one reads and writes. Maybe the last one fits the bill.
Edit: Turns out that even pkgconfig does not persist values across sessions. I have solved this problem with company-local code when I had control over directories or databases to write. For public and portable code it is a little harder. I still think there is a package out there that stores user-level config on all major OSs but I cannot for now remember the name.
Edit 2: With a nod to Gabor Csardi to refresh my memory, the rappdirs solves the problem of portably supplying a config location per-user (with other tricks too, a port of a corresponding Python library). Combine this with a simple cvs or rds file to store when (at all) you last showed the message and you can now show it once and exactly once. Not even again after a package upgrade.
The following code allows you to create a file in the package library:
activate_file = paste(system.file('extdata', package = 'your_package'), 'activated.txt', sep = '/')
file.exists(activate_file)
# FALSE
file.create(activate_file)
file.exists(activate_file)
# TRUE
Now you can check in .onLoad whether or not the activated.txt file exists. The first time you show the message, and then you create activated.txt, and in the next time the package is used the onload function sees the file and can skip the message.
Advantages:
Persistent over sessions.
Platform independent way that ensures the user has write privileges to create the file.
Disadvantages:
Reinstall/upgrade wipes the activated file, thus showing the message again.
If this is not acceptable, you could try and find a persistent location, e.g. in the home drive to do this (e.g. ~/.your_package/activated.txt). Then the challenge is to make this platform independent. Maybe look at path.expand(~) to get the current users home drive, not sure if this works on Windows.

How can I check if database update is required before update module

Is there any good way for it? Like check some specific code in module.
Yes, it's possible.
Let's have an example with webform module.
Inside of each module there is an install file.
Open it and scroll to the down, find the last hook. In our example it's:
webform_update_7430
Here is a screen (bottom part) of install file.
How to check if it is going to run or already processed?
In order to do that, you need to check system table in your drupal database. Find the webform module in system table and check value in schema version column. That will be the number of last hook which was run for this module, if in your install file hooks have higher number it means they will be executed during update.

Resources