Howto: New Script to Restore osmc to clean state

Hello all,

Recently I wanted to remove all the muck I had installed on my osmc system using apt-get (multiple desktops such as mate and xfce, various applications such as tightvncserver and transmission, etc) which were wasting disk space and slowing down my osmc system.

I searched everywhere to no avail for an easy method of removing user installed packages but leaving the required osmc system packages alone, in essence to “refresh” the osmc install or restore it to defaults.

When it became clear that there was no “simple” solution other than a complete fresh install, I decided to remedy that situation and created the osmc-freshstart script.

Usage is quite simple, just install the script and supporting files (step by step directions below the disclaimer) and then execute the script from the command line:

$ osmc-freshstart.sh

The script will build a list of installed user packages to remove and ask you to confirm that you indeed do want to remove them, then ask if you want to also remove the package archives.

That’s all it takes from the user, the actual removal process is 100% automated.

When complete your osmc system should be restored to a near virgin state.

If you have installed packages you wish to keep, simply add them to the keep-packages file (in the same directory as the script) and enter each package you wish to keep on a single line. Packages listed in ‘keep-packages’ will not be removed by the script.

A simple example of a keep-packages file would be:
zip
unzip
parted

I have tested this script for the past week using three different osmc installs on various RPIs by installing dozens of packages and then running the script to clean the systems. I have found the script to be quite stable and bug free but as always, use it at your own risk (disclaimer below).

If you are about to do a fresh install to clean your system, it may be well worth your time to give this script a shot.


** DISCLAIMER: Though I have tested this script extensively (removed 3 different xdesktops, dozens of smaller apps, etc) and repeatedly on three separate OSMC setups but I cannot guarantee it will work for you. I accept no liability or responsibility if this script destroys your OSMC install or even if it sets your RPI on FIRE (okay, seriously IMHO very little chance of that with this script). This is run at your own risk, though I have taken reasonable care to ensure it will not cause you issues… you are warned.

Install and Use:

SSH into osmc (user & pass ‘osmc’)

using apt install wget and unzip

sudo apt-get update
sudo apt-get install wget unzip

if you don’t have one already, create the scripts directory

mkdir .scripts

cd into the scripts directory

cd .scripts

use wget to download script from github:

wget https://github.com/mwkeefer/osmc-freshstart/archive/master.zip

extract the script archive

unzip master.zip

rename the directory

mv ./osmc-freshstart-master ./osmc-freshstart

cd into the freshstart directory

cd osmc-freshstart

make the script executable

chmod +x osmc-freshstart.sh

execute the script

./osmc-freshstart.sh


The script will automatically determine which packages are user installed and not required by OSMC or part of the base system and then present a list of packages which will be removed.

** Take a few moments and check the packages to be removed, make sure there are not any packages you want to keep, then when you are satisfied simply press Y and enter to begin the cleaning process.

If your unsure of what other packages any given package you want to keep require to function, a quick way to determine this is to simply run:

sudo apt-get remove [package name]

Then when apt asks if you want to remove the package, simply note (copy and paste) the additional packages that are to be removed with the primary and then press N to exit apt. Then you add those package names to keep-packages file and run the osmc-freshstart.sh script again.

A simple example is vi.

To retain vi on your system, you would need to add three packages to your keep-packages list:
vim
vim-common
vim-runtime

Feel free to post any questions you have regarding this script here, I will answer as quickly as I am able. You will also find my email address in the comments at the top of the script, feel free to email me too.

I hope this helps many of you and perhaps gives you a bit more confidence to test various software on your OSMC RPI :smile:

-Mike

2 Likes

Hi,

While I think it is a good idea to have a method for restoring a system, I’m not sure what this method provides over a re-download and install. The problem with this approach is it can leave your system in an inconsistent state.

If it is possible, I will look at implementing a ‘Factory Reset’ option and getting @Karnage to add it to My OSMC.

Sam

Hello again Sam,

As a Project Lead, please know you have my utmost respect and thanks for helping me initially get aquanted with osmc and the internal aspects, issues I had (lack of reading the codebase).

The advantage over a full download and reinstall is time saved, while I will again respond as I am loading and configuring from scratch a new system today I will clock the time required for just the install which as I recall with configuration (minus the libraries or restore of settings automatically which I have found restoring from backup can indeed cause instability in my testing cases). In my experience it takes approx 2-3 hours to reconfigure shares (not including import process, movies, tv, music) where as the script will accompilsh restoring to near virgin state in 3-8 minutes to remove and clean: ubuntu mate desktop, xfce, lxdm, tightvncserver, Mono Runtimes (had to try c# and VB.NET on the Pi), ephiany browser, kde desktop, lightdm, alsa, transmission, VIM, unzip, zip, pptp client, etc.

This includes the packages, their dependency packages, etc.

Now as far as leaving the system in an inconsistent state, after about 45 test scenarios across 3 RPI2’s and a single RPI 1 I have found NO inconsistencies providing you reboot upon completion… The systems not only run clean but a diff of an entire virgin file list and the cleaned system file list only shows about 6 non essential (apps were removed so they are not referenced anymore nor do they cause any other part of the system to attempt to use them).

Additionally not a single stock OSMC system package is removed, give this a shot…

Download the script master.zip archive form github, don’t run it but look at the packages base folder and there are 2 lists of stock required packages (system and user), next run the script but do not allow it to clean your system and then check the files in the .tmp directory for the current-osmc-system, and finally packages to be removed and I think you will see it doesn’t remove any needed packages.

I have also (since you mentioned @Karnage) sent him a message asking to be added to the contributing developers on the master branch of osmc so I can work on possible bugs and additional features.

Finally, just FYI… I have been writing a Windows based NFS server for the last week and a half which will solve many of the issues I’ve seen users encounter and as of now implements:

mountd service
nfs service (versions 2 and 3… working on 4 now)
portmapper service aka RPCBind Service
and obviously rpcbind service.
This version also supports udp or tcp and 90% of the osmc/debian options (well all those supported in osmc).

I began this because after attempting to use Winnfsd, FreeNFS and 3 different non open source and free versions, I ran into so many issues I’ve seen posted to the forums.

This system already runs as a service under Windows 7 32 and 64 bit and is capable (mostly, still a few bits to finish) of exporting multiple paths by alias so you can have say:c/media/tv /mnt/TV, :c/shared\media\movies ~/mnt/Movies, c:/shared/media/music :~/mnt/music and c/shared/media/pictures ~/mnt/Music.

I just got tired of all the available free NFS daemons not working properly on Windows 7 (32 or 64) and will be offering the first alpha release in approx 1-2 weeks. This should help eliminate many of the issues users are having with NFS share use.

I hope this answers why it provides a better option than just redownloading, install and configuration.

Regards,
Mike

Hi

While I can appreciate that this saves time, my fear of an inconsistent state is not unfounded. For example, with the July update we had a dependency that existed for Kodi but was not explicitly defined. This means systems that upgraded were fine, unless of course, someone ran apt-get autoremove. Granted, that was something we introduced and that is resolved now, but I am worried that changes could be made; users think their system is stable and then they experience problems when we release an update. A factory restore will take longer, but it’s the only way of guaranteeing that the system is back to its vanilla state

Fork OSMC on GitHub and send PRs.

This is quite documented:

C#/.NET Network File System (NFS) Server - CodeProject.

I am exploring the possibility of adding some sharing software to OSMC that users can run on their desktop to share files without any knowledge of SMB or NFS. I would probably use NFS as the underlying server as it has less overhead, but we would be developing this in C++ for portability.

I am less concerned about protocol version. V3 is probably the best to support a wide range of legacy devices. What would be nice is:

  • POSIX compliance
  • Case insensitivity

This would let us use the server for NFSroots. A lot of Windows users have wanted to do this but don’t want to set up Linux or a VM. Unfortunately, I think you would need a form of object store as well, because NTFS will not allow you to handle ACLs and case sensitivity properly…

I’m looking forward to seeing how you can make OSMC better

Cheers

Sam

My OSMC install wasn’t really performing as fast, nor as stable, as I hoped it would be. Might be due to the 311(!) extra packages I had apparently installed just mucking about.

Will report back with performance results but for now transmission is broken and seemingly cannot be fixed be reinstalling in the gui, trying cli

Solved it by doing

sudo apt-get install armv7-transmission-app-osmc

For some reason it didn’t want to run through the gui