mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-11 18:39:30 +00:00
Add mount volume migration
This commit is contained in:
parent
a6fe72608f
commit
e3245cd26a
|
@ -11,11 +11,10 @@ Adding DISABLE_ALL to that array disables the migrations module entirely.
|
||||||
from selfprivacy_api.utils import ReadUserData
|
from selfprivacy_api.utils import ReadUserData
|
||||||
from selfprivacy_api.migrations.fix_nixos_config_branch import FixNixosConfigBranch
|
from selfprivacy_api.migrations.fix_nixos_config_branch import FixNixosConfigBranch
|
||||||
from selfprivacy_api.migrations.create_tokens_json import CreateTokensJson
|
from selfprivacy_api.migrations.create_tokens_json import CreateTokensJson
|
||||||
from selfprivacy_api.migrations.migrate_to_selfprivacy_channel import (
|
from selfprivacy_api.migrations.migrate_to_selfprivacy_channel import MigrateToSelfprivacyChannel
|
||||||
MigrateToSelfprivacyChannel,
|
from selfprivacy_api.migrations.mount_volume import MountVolume
|
||||||
)
|
|
||||||
|
|
||||||
migrations = [FixNixosConfigBranch(), CreateTokensJson(), MigrateToSelfprivacyChannel()]
|
migrations = [FixNixosConfigBranch(), CreateTokensJson(), MigrateToSelfprivacyChannel(), MountVolume()]
|
||||||
|
|
||||||
|
|
||||||
def run_migrations():
|
def run_migrations():
|
||||||
|
|
|
@ -15,20 +15,16 @@ class MigrateToSelfprivacyChannel(Migration):
|
||||||
|
|
||||||
def is_migration_needed(self):
|
def is_migration_needed(self):
|
||||||
try:
|
try:
|
||||||
print("Checking if migration is needed")
|
|
||||||
output = subprocess.check_output(
|
output = subprocess.check_output(
|
||||||
["nix-channel", "--list"], start_new_session=True
|
["nix-channel", "--list"], start_new_session=True
|
||||||
)
|
)
|
||||||
output = output.decode("utf-8")
|
output = output.decode("utf-8")
|
||||||
print(output)
|
|
||||||
first_line = output.split("\n", maxsplit=1)[0]
|
first_line = output.split("\n", maxsplit=1)[0]
|
||||||
print(first_line)
|
|
||||||
return first_line.startswith("nixos") and (
|
return first_line.startswith("nixos") and (
|
||||||
first_line.endswith("nixos-21.11") or first_line.endswith("nixos-21.05")
|
first_line.endswith("nixos-21.11") or first_line.endswith("nixos-21.05")
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return False
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def migrate(self):
|
def migrate(self):
|
||||||
# Change the channel and update them.
|
# Change the channel and update them.
|
||||||
|
|
48
selfprivacy_api/migrations/mount_volume.py
Normal file
48
selfprivacy_api/migrations/mount_volume.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from selfprivacy_api.migrations.migration import Migration
|
||||||
|
from selfprivacy_api.utils import ReadUserData, WriteUserData
|
||||||
|
from selfprivacy_api.utils.block_devices import BlockDevices
|
||||||
|
|
||||||
|
class MountVolume(Migration):
|
||||||
|
"""Mount volume."""
|
||||||
|
|
||||||
|
def get_migration_name(self):
|
||||||
|
return "mount_volume"
|
||||||
|
|
||||||
|
def get_migration_description(self):
|
||||||
|
return "Mount volume if it is not mounted."
|
||||||
|
|
||||||
|
def is_migration_needed(self):
|
||||||
|
try:
|
||||||
|
with ReadUserData() as userdata:
|
||||||
|
return "volumes" not in userdata
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def migrate(self):
|
||||||
|
# Get info about existing volumes
|
||||||
|
# Write info about volumes to userdata.json
|
||||||
|
try:
|
||||||
|
volumes = BlockDevices().get_block_devices()
|
||||||
|
# If there is an unmounted volume sdb,
|
||||||
|
# Write it to userdata.json
|
||||||
|
is_there_a_volume = False
|
||||||
|
for volume in volumes:
|
||||||
|
if volume.name == "sdb":
|
||||||
|
is_there_a_volume = True
|
||||||
|
break
|
||||||
|
with WriteUserData() as userdata:
|
||||||
|
userdata["volumes"] = []
|
||||||
|
if is_there_a_volume:
|
||||||
|
userdata["volumes"].append({
|
||||||
|
"device": "/etc/sdb",
|
||||||
|
"mountPoint": "/volumes/sdb",
|
||||||
|
"fsType": "ext4",
|
||||||
|
})
|
||||||
|
print("Done")
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print("Error mounting volume")
|
Loading…
Reference in a new issue