How can I make a Cydia tweak that modifies files on install and reverts changes on uninstall? - plist

I have been developing a Cydia tweak called BrightnessControl (I am very new to developing). For now, all it does is use Winterboard to patch var/stash/Applications/Brightness.plist with my modified version. Is there a way, maybe with Theos, that I can patch this file without Winterboard? I am wanting to back this file up somehow and replace it with my modified .plist upon imstall, and then upon un-install delete my modified .plist and restore the original .plist. I have seen something like this done with other tweaks, but I don't know how this is done. May anyone please push me in the right direction?

You don't even need to know programming to do this. The trick is inside the Debian packages' postinst and prerm scripts.
Edit: as per #Nate's comments: beware, because these scripts also run upon updating a package. So, for example, a package with one update which is then removed would do this:
1st installation:
run preinst
(APT installs your package)
run postinst
update:
run prerm of the old version
(APT removes old version)
run postrm of old version
run preinst of new version
(APT installs new version)
run postinst of new version
removal:
run prerm of new version
(APT removes the new version... you no longer have the package)
run postrm of new version

Related

After updating R and RStudio, push to GitHub fails stating remote is ahead even though it's not

I am having some sort of communication issue with my RStudio project and GitHub, potentially related to updating R and RStudio.
I recently updated my R to version 4.0.3 on my windows machine:
R version 4.0.3 (2020-10-10); Platform: x86_64-w64-mingw32/x64 (64-bit)
I also updated my RStudio to Version 1.3.1093, and finally, as a result of the issues below, I updated my git version to 2.30.0.windows.1
I have two existing R Packages hosted on GitHub, and recently created a third. To create my new Repo and link it to my local project I followed the instructions on:
https://aberdeenstudygroup.github.io/studyGroup/lessons/SG-T1-GitHubVersionControl/VersionControl/
I have interacted with GitHub to update my current packages, but it's been years since I created a new repository. It wasn't easy but eventually everything seemed to be working properly. I made some edits, performed a commit, went to push (using the shell or RStudio's GUI) and got this error:
To github.com:user/repo.git
! [rejected] HEAD -> main (non-fast-forward)
error: failed to push some refs to 'github.com:user/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I am the only person using this repo, and when I perform a pull, I'm told everything is up to date. I also found a post suggesting I first fetch, then rebase (Git push rejected "non-fast-forward"). When I tried these steps I got an error:
$ git rebase tmp
error: could not apply 4fc4d3e... Conflict test
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 4fc4d3e... Conflict test
CONFLICT (add/add): Merge conflict in R/conflict test.R
Auto-merging R/conflict test.R
How do I have a conflict? How can my local copy be behind if I am the only one working on this project?
To work around this I've started performing commits, then forcing the push via git push -f origin main. Since I am the only person who will ever work on this project, perhaps this is safe; however, it's obviously not recommended and shouldn't be needed.
Also, I went back to my previous packages and performed some test commits. Sure enough, I now have this same error when I try to push new commits to GitHub for packages that were communicating perfectly previously.
I have spent some time trying to figure this out, but my efforts are limited to trying to create the repo and local package in different ways and connecting them with SSH vs URL, etc. I'm not well versed in GitHub; once my previous projects were set up I just used the same protocol to commit and push (again, I am the only user editing any of these packages). My guess is that somehow my updates to R, RStudio, or git seem to have created some sort of communication issue that I can't figure out.

Running newer version of R from terminal when older version is invoked by default

I'm trying to run R from iTerm on an OSX computer (OSX 10.11.6). When I enter R, it opens up an older version of R, from the path /Users/***/miniconda2/bin/R. I would like it to run, by default, an R version found at /usr/local/bin/R, without having to enter the full path every time. How would one go about changing the location of the default R?
Thanks for your help
This is likely due to the PATH variable preferring ~/miniconda2/bin before /usr/local/bin. I'm giving you a few options here to help understand why it is happening.
Let's assume your PATH looks like this:
/Users/me/bin:/Users/me/miniconda2/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Modify PATH
You could modify PATH to move /Users/me/miniconda2/bin after /usr/local/bin or remove it from PATH completely. The downside is that if you rely on other binaries in ~/miniconda2/bin they will no longer be found when executing them by name.
Move R out of the way
Another option would be to move ~/miniconda/bin/R out of the way, for example using
mv ~/miniconda/bin/R ~/miniconda/bin/R-miniconda
Afterwards R will be run from the next location in $PATH, but if you update miniconda2 it may return.
Link to R further up in the PATH (easiest/best)
Finally, you could make sure that there is an R executable in something that is further up the $PATH. This is probably the easiest and most effective option.
First, make sure you have a bin folder in your home directory. If this is not the case, create it using mkdir ~/bin and then restart the terminal. The restart should cause the code in ~/.profile to add that folder to your $PATH. You can verify by doing echo $PATH. If this is not the case, add the following line to your ~/.profile or ~/.bash_profile:
export PATH=$HOME/bin:$PATH
In the example at the top, the PATH already contains /Users/me/bin at the beginning of the line (highest priority).
Next, create a soft link to the R binary in the newly created folder:
ln -s /usr/local/bin/R ~/bin/R
You should now be able to execute R, which will prefer the softlink created, which will execute the one you like. If it does not work right away execute hash -r or restart the terminal.
Just in case you happen to be using RStudio Server (open source) or someone is looking for how to change the RStudio Server default version of R, here is what I found when trying to answer the same question:
Starting in RStudio Server 1.3 (the newest version is 1.4.1106, released February 22, 2021), a user’s preferred version of R can be specified in the rstudio-prefs.json file in the global-level /etc/rstudio folder or in the user-level ~/.config/rstudio folder.
See https://blog.rstudio.com/2020/02/18/rstudio-1-3-preview-configuration/ and https://docs.rstudio.com/ide/server-pro/session-user-settings.html for user setting options in newer versions of RStudio Server.
See https://support.rstudio.com/hc/en-us/articles/200716783-RStudio-Release-History for RStudio release history and https://www.rstudio.com/products/rstudio/download-server/redhat-centos/ for Red Hat downloads of the newest version of RStudio Server.

Reverting GIT directories to previous ones in RStudio

I am using Rstudio to build an R package with version control being handled by GIT. There was a mistake and several files were overwritten and I would like to be able to revert back to a previous version in the commit timeline.
Can I use the SHA number to revert back to that version? Also, I am using RStudio so is there an easy way to do that in this environment?
WARNING THIS WILL DELETE EVERYTHING YOU HAVE DONE SINCE THE COMMIT
git reset --hard SHA-NUMBER

Building Brackets Shell (After running the grunt build command)

On windows after running the grunt build command for creating brackets shell it gives done without errors but i dont see any .exe file generated..
What might be the problem???
Here are some possible solutions:
Are you following the full brackets-shell build instructions, including all prerequisites?
Make sure Brackets isn't running at the same time. The build will fail silently if the .exe file is currently in use (see bug).
Try with a fresh git clone of the repo. If your brackets-shell local copy has been around for a while, sometimes the build & deps folders can get in a bad state. (I'm assuming you haven't modified the source at all. If you have, try with an unmodified copy of the source first to make sure it builds correctly without any of your changes).
Check that python --version shows 2.7.x
Verbose build output would also be helpful in diagnosing issues like this, but unfortunately there's not yet an easy way to get that...
If you follow the instructions on bracket-shell's wiki page, the Windows executable should be created in the Release directory.

R 3.0.0 crashes on startup

I just updated R from version 2.15.1 to version 3.0.0 on my MAC running 10.6.8 and now R crashes on startup.
I get the error:
Error in getLoadedDLLs() : there is no .Internal function 'getLoadedDLLs'
Error in checkConflicts(value) :
".isMethodsDispatchOn" is not a BUILTIN function
Any ideas on how to go about?
The most common cause of this is having a corrupted ".Rdata" file in your working directory. Using the Mac Finder.app you will not by default be able to see files that begin with a ".", so-called dotfiles. Those files can be "seen" if you execute a change to the plist controlling the behavior of Finder.app. Open a Terminal.app window and run this bit of code:
defaults write com.apple.Finder AppleShowAllFiles YES
Then /point/-/click/-/hold/ on Dock-Finder-icon, and choose "Relaunch"
If you to do so, you can then change it back with the obvious modfication to that procedure. I happen to like seeing the hidden files so that's the way I run my Mac all the time, but some people may feel it is too dangerous to expose the "hidden secrets" to their own bumbling.
Paul raises a good point: I run the following R function in the R console after updating:
update.packages(checkBuilt=TRUE, ask=FALSE)
I have a lot of installed packages and paging through the entire list has gotten too tiresome so I bypass the ask-messages. Sometimes you will get errors because there may be dependencies on r-forge or Omegahat packages or on packages that need to be compiled from source. These may need to be updated "by hand". And you may need more than one pass through such an effort. Take notes of which packages are missing and fill them in.
I had the same problem running RKWard on ubuntu 12.04.
Check your r-base-core, like Paul suggested, to make sure the version is also at the latest version. Mine didn't update automatically. I had a platform dependent version, but RKWard was calling the new version. To solve this problem, I simply marked r-base-core for removal and reinstalled the latest version or r-base-core. poof problem fixed, bippity boppity boo!
I suspect that your error is similar to mine because I had also JUST updated RKWard. Start at updating r-base-core or try to get all of the dependencies to match up the versions.
I hope that you can translate this into what to do on a MAC,
SU

Resources