Skip to content

Instantly share code, notes, and snippets.

@slopp
Created September 24, 2018 17:49
Show Gist options
  • Select an option

  • Save slopp/9c873a1c05b8cfeb6cef33a8fcb6ff30 to your computer and use it in GitHub Desktop.

Select an option

Save slopp/9c873a1c05b8cfeb6cef33a8fcb6ff30 to your computer and use it in GitHub Desktop.
Have RSPM track a list of packages in packages.txt
#!/bin/bash
RSPM_CLI=/opt/rstudio-pm/bin
PRODUCTION = $RSPM_CLI list repos | grep -c production
if [[ $PRODUCTION < 1 ]]; then
echo "Creating repository 'production'"
$RSPM_CLI create repo --name=production
fi
CURATED = $RSPM_CLI list sources | grep -c curated
if [[ $CURATED == 1 ]]; then
echo "Subscribing the repo 'production' to the source 'curated'"
$RSPM_CLI subscribe --repo=production --source=curated
else
echo "ERROR: The source 'curated' does not exist, see update-curated.sh"
fi
#!/bin/bash
# This script converges a curated-cran source named "curated"
# to include packages in the list 'packages.txt'
# WARNING: This script _always_ udpates the entire set of packages
# in the source; use with caution!
RSPM_CLI=/opt/rstudio-pm/bin
# first, ensure that we have up-to-date metadata on CRAN
$RSPM_CLI sync
update {
UPDATE_ID = $RSPM_CLI update --source=curated --dryrun | sed -En "s/.*transaction-id=([0-9]+) flag.*/\1/p"
$RSPM_CLI update --source=curated --transaction-id=$UPDATE_ID
}
# check to see if the curated source exists
CURATED = $RSPM_CLI list sources | grep -c curated
if [[ $CURATED == 1 ]]; then
# update the existing packages before proceeding
echo "Updating existing source"
update
else
echo "Creating new curated source"
$RSPM_CLI create source --name=curated --type=curated-cran
fi
# now converge the source to the packages in packages.txt
ADD_ID = $RSPM_CLI add --file-in=packages.txt --source=curated --dryrun | sed -En "s/.*transaction-id=([0-9]+) flag.*/\1/p"
$RSPM_CLI add --file-in=packages.txt --source-curated --transaction-id=$ADD_ID
# TODO: ensure the source is surface through a repo; see expose-curated.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment