Skip to content

Commit

Permalink
Merge branch 'extract-env-vars' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
seriema committed Apr 2, 2020
2 parents 1c46f12 + 0f7f71b commit 2650fbe
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 42 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ jobs:
bash -i ssh-vm.sh "bash -i ~/tmp/test-gamelist.sh"
bash -i ssh-vm.sh "rm ~/tmp/test-gamelist.sh ~/tmp/test-gamelist.xml ~/tmp/test-gamelist-screenscraper-failed.xml"
- run:
name: Print RaspberryPi ~/.retro-cloud.env
command: cat ~/.retro-cloud.env
when: always

- run:
name: Print VM ~/.retro-cloud.env
command: |
echo 'ssh $RETROCLOUD_VM_USER@$RETROCLOUD_VM_IP "cat ~/.retro-cloud.env"' > print-vm-bashrc.sh
bash -i print-vm-bashrc.sh
rm print-vm-bashrc.sh
when: always

- run:
name: Print RaspberryPi ~/.bashrc
command: cat ~/.bashrc
Expand Down
49 changes: 29 additions & 20 deletions raspberry-pi/create-vm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,36 @@ ssh "$($username)@$ip" "mkdir -p $sharePath"
###################################
$currentActivity = "Persist resource values"

ProgressHelper $currentActivity "Saving configuration variables locally (~/.bashrc)"
$envVarFile="$HOME/.retro-cloud.env"
ProgressHelper $currentActivity "Saving configuration variables locally in $envVarFile"

Add-Content "$envVarFile" '# RETRO-CLOUD: The environment variables below are from raspberry-pi/create-vm.ps1'
Add-Content "$envVarFile" '# These are needed by the RetroPie.'
Add-Content "$envVarFile" "export RETROCLOUD_VM_IP=$ip"
Add-Content "$envVarFile" "export RETROCLOUD_VM_USER=$username"
Add-Content "$envVarFile" '# These are needed by both the RetroPie and VM.'
Add-Content "$envVarFile" "export RETROCLOUD_VM_SHARE=$sharePath"
Add-Content "$envVarFile" '# These are mostly useful for troubleshooting.'
Add-Content "$envVarFile" "export RETROCLOUD_AZ_RESOURCE_GROUP=$rg"
Add-Content "$envVarFile" '# These are needed by the VM.'
Add-Content "$envVarFile" "export RETROCLOUD_AZ_STORAGE_ACCOUNT_NAME=$storageAccountName"
Add-Content "$envVarFile" "export RETROCLOUD_AZ_STORAGE_ACCOUNT_KEY=$storageAccountKey"
Add-Content "$envVarFile" "export RETROCLOUD_AZ_FILE_SHARE_NAME=$fileShareName"
Add-Content "$envVarFile" "export RETROCLOUD_AZ_FILE_SHARE_URL=$smbPath"

ProgressHelper $currentActivity "Add $envVarFile to be loaded by ~/.bashrc"
Add-Content "$HOME/.bashrc" ""
Add-Content "$HOME/.bashrc" '# RETRO-CLOUD: The environment variables below were set by the retro-cloud setup script.'
Add-Content "$HOME/.bashrc" "export RETROCLOUD_VM_IP=$ip"
Add-Content "$HOME/.bashrc" "export RETROCLOUD_VM_USER=$username"
Add-Content "$HOME/.bashrc" "export RETROCLOUD_VM_SHARE=$sharePath"
Add-Content "$HOME/.bashrc" '# RETRO-CLOUD: These are mostly useful for troubleshooting.'
Add-Content "$HOME/.bashrc" "export RETROCLOUD_AZ_RESOURCE_GROUP=$rg"
Add-Content "$HOME/.bashrc" "export RETROCLOUD_AZ_STORAGE_ACCOUNT_NAME=$storageAccountName"
Add-Content "$HOME/.bashrc" "export RETROCLOUD_AZ_STORAGE_ACCOUNT_KEY=$storageAccountKey"
Add-Content "$HOME/.bashrc" "export RETROCLOUD_AZ_FILE_SHARE_NAME=$fileShareName"
Add-Content "$HOME/.bashrc" "export RETROCLOUD_AZ_FILE_SHARE_URL=$smbPath"

ProgressHelper $currentActivity "Passing configuration variables to VM ($username@${ip}:/home/$username/.bashrc)"
ssh "$($username)@$ip" "echo '' | sudo tee -a ~/.bashrc > /dev/null"
ssh "$($username)@$ip" "echo '# RETRO-CLOUD: The environment variables below were set by the retro-cloud setup script.' | sudo tee -a ~/.bashrc > /dev/null"
ssh "$($username)@$ip" "echo 'export RETROCLOUD_AZ_STORAGE_ACCOUNT_NAME=$storageAccountName' | sudo tee -a ~/.bashrc > /dev/null"
ssh "$($username)@$ip" "echo 'export RETROCLOUD_AZ_STORAGE_ACCOUNT_KEY=$storageAccountKey' | sudo tee -a ~/.bashrc > /dev/null"
ssh "$($username)@$ip" "echo 'export RETROCLOUD_AZ_FILE_SHARE_NAME=$fileShareName' | sudo tee -a ~/.bashrc > /dev/null"
ssh "$($username)@$ip" "echo 'export RETROCLOUD_AZ_FILE_SHARE_URL=$smbPath' | sudo tee -a ~/.bashrc > /dev/null"
ssh "$($username)@$ip" "echo 'export RETROCLOUD_VM_SHARE=$sharePath' | sudo tee -a ~/.bashrc > /dev/null"
Add-Content "$HOME/.bashrc" "# RETRO-CLOUD CONFIG START"
Add-Content "$HOME/.bashrc" ". $envVarFile"
Add-Content "$HOME/.bashrc" "# RETRO-CLOUD CONFIG END"

$vmEnvVarFile="/home/$username/.retro-cloud.env"
ProgressHelper $currentActivity "Passing configuration variables to VM (${username}@${ip}:${vmEnvVarFile})"
scp "$envVarFile" "${username}@${ip}:${vmEnvVarFile}"
ssh "${username}@${ip}" "echo '' | sudo tee -a ~/.bashrc > /dev/null"
ssh "${username}@${ip}" "echo '# RETRO-CLOUD CONFIG START' | sudo tee -a ~/.bashrc > /dev/null"
ssh "${username}@${ip}" "echo '. $vmEnvVarFile' | sudo tee -a ~/.bashrc > /dev/null"
ssh "${username}@${ip}" "echo '# RETRO-CLOUD CONFIG END' | sudo tee -a ~/.bashrc > /dev/null"

ProgressHelper "Done" " "

Expand Down
10 changes: 5 additions & 5 deletions raspberry-pi/mount-vm-share.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ ln -s "$gamelists" "$HOME/.emulationstation"
ln -s "$downloadedMedia" "$HOME/.emulationstation"
ln -s "$roms" "$HOME/RetroPie"

echo 'Add folder paths as environment variables'
echo "" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "# RETRO-CLOUD: The environment variables below are from raspberry-pi/mount-vm-share.sh" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "# RETRO-CLOUD: These are mostly useful for troubleshooting." | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_RPI_MOUNT_POINT=$mntPath" | sudo tee -a "$HOME/.bashrc" > /dev/null
envVarFile="$HOME/.retro-cloud.env"
echo "Add folder paths as environment variables in $envVarFile"
echo "# RETRO-CLOUD: The environment variables below are from raspberry-pi/mount-vm-share.sh" | sudo tee -a "$envVarFile" > /dev/null
echo "# RETRO-CLOUD: These are mostly useful for troubleshooting." | sudo tee -a "$envVarFile" > /dev/null
echo "export RETROCLOUD_RPI_MOUNT_POINT=$mntPath" | sudo tee -a "$envVarFile" > /dev/null

echo 'Done!'
echo "VM share mounted on $mntPath"
11 changes: 5 additions & 6 deletions virtual-machine/create-vm-share.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ cache="$RETROCLOUD_VM_SHARE/cache"
sudo mkdir -p "$cache"

echo 'Add folder paths as environment variables'
echo "" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "#RETRO-CLOUD: The environment variables below are from virtual-machine/create-vm-share.sh" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_SKYSCRAPER_GAMELISTFOLDER=$gamelists" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_SKYSCRAPER_MEDIAFOLDER=$downloadedMedia" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_ROMS=$roms" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_SKYSCRAPER_CACHEFOLDER=$cache" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "# RETRO-CLOUD: The environment variables below are from virtual-machine/create-vm-share.sh" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null
echo "export RETROCLOUD_VM_GAMELISTS=$gamelists" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null
echo "export RETROCLOUD_VM_DOWNLOADEDMEDIA=$downloadedMedia" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null
echo "export RETROCLOUD_VM_ROMS=$roms" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null
echo "export RETROCLOUD_VM_SKYSCRAPER_CACHE=$cache" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null

echo 'Done!'
8 changes: 4 additions & 4 deletions virtual-machine/install-skyscraper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ mkdir -p "$HOME/.skyscraper"
cp -v .skyscraper/config.ini "$HOME/.skyscraper/config.ini"

# If these variables aren't available, make sure this script is running in interactive mode (https://stackoverflow.com/a/43660876) and mount-az-share.sh.
sed -i -e "s+RETROCLOUD_INPUTFOLDER+$RETROCLOUD_ROMS+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_GAMELISTFOLDER+$RETROCLOUD_SKYSCRAPER_GAMELISTFOLDER+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_MEDIAFOLDER+$RETROCLOUD_SKYSCRAPER_MEDIAFOLDER+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_CACHEFOLDER+$RETROCLOUD_SKYSCRAPER_CACHEFOLDER+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_INPUTFOLDER+$RETROCLOUD_VM_ROMS+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_GAMELISTFOLDER+$RETROCLOUD_VM_GAMELISTS+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_MEDIAFOLDER+$RETROCLOUD_VM_DOWNLOADEDMEDIA+g" "$HOME/.skyscraper/config.ini"
sed -i -e "s+RETROCLOUD_CACHEFOLDER+$RETROCLOUD_VM_SKYSCRAPER_CACHE+g" "$HOME/.skyscraper/config.ini"

echo 'Copy run script to user root'
cp -v local/run-skyscraper.sh "$HOME/run-skyscraper.sh"
Expand Down
6 changes: 3 additions & 3 deletions virtual-machine/local/run-skyscraper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ echo 'Create cache and generate gamelists and artwork'
for platform in "${platforms[@]}"
do
# If the are no games for this platform, skip (because starting Skyscraper for no games is really slow)
if ! [ -d "$RETROCLOUD_ROMS/$platform" ]; then
if ! [ -d "$RETROCLOUD_VM_ROMS/$platform" ]; then
echo "No games found for $platform. Skipping."
continue
fi
Expand All @@ -127,6 +127,6 @@ do
# This step is needed because the AZ mounted path is reflected in the gamelists, and they're symlinked on the rpi to look local.
echo "Fixing paths in gamelists for $platform"
# Need to sudo because Skyscraper creates the gamelists.xml without write access on them.
sudo sed -i -e "s+$RETROCLOUD_ROMS+/home/pi/RetroPie/roms+g" "$RETROCLOUD_SKYSCRAPER_GAMELISTFOLDER/$platform/gamelist.xml"
sudo sed -i -e "s+$RETROCLOUD_SKYSCRAPER_MEDIAFOLDER+/home/pi/.emulationstation/downloaded_media+g" "$RETROCLOUD_SKYSCRAPER_GAMELISTFOLDER/$platform/gamelist.xml"
sudo sed -i -e "s+$RETROCLOUD_VM_ROMS+/home/pi/RetroPie/roms+g" "$RETROCLOUD_VM_GAMELISTS/$platform/gamelist.xml"
sudo sed -i -e "s+$RETROCLOUD_VM_DOWNLOADEDMEDIA+/home/pi/.emulationstation/downloaded_media+g" "$RETROCLOUD_VM_GAMELISTS/$platform/gamelist.xml"
done
7 changes: 3 additions & 4 deletions virtual-machine/mount-az-share.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ sudo mount -a


echo 'Add folder paths as environment variables'
echo "" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "#RETRO-CLOUD: The environment variables below are from virtual-machine/mount-az-share.sh" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "# RETRO-CLOUD: The environment variables below are from virtual-machine/mount-az-share.sh" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null
# Note: RETROCLOUD_VM_SHARE and RETROCLOUD_VM_MOUNT_POINT are currently the same.
echo "export RETROCLOUD_VM_MOUNT_POINT=$mntPath" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_AZ_CREDENTIALS=$smbCredentialFile" | sudo tee -a "$HOME/.bashrc" > /dev/null
echo "export RETROCLOUD_VM_MOUNT_POINT=$mntPath" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null
echo "export RETROCLOUD_AZ_CREDENTIALS=$smbCredentialFile" | sudo tee -a "$HOME/.retro-cloud.env" > /dev/null

echo 'Done!'
echo "File share mounted on $mntPath"

0 comments on commit 2650fbe

Please sign in to comment.