I am trying to write a script where I can tell whether the package is a pre-installed or it was installed by user.
And also can we have way to get to know that following are the dependencies of the package 'X'
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
rpm level you cannot really know. Depending on the package manager you use there might be some information stored there.
Note that this only works if the user ran the installation commands with
sudo. If he became root, you'll never know who did it.
gives you a list of transactions and which user launched the command.
gives you a list of transactions, but doesn't list the user by default. You can however run:
dnf history info <ID>
and then you will see the user who launched the command
there is no way to know this afaik.
Your tags are unclear, we don't know which package manager you use. But since you used the tag arch-linux I am going to answer for pacman.
Well the first question is a hard one, it is not really possible to my knowledge and heavily depends on your installation. There isn't one standard Linux installation since there are many different distributions, desktop environments, installer options,...
But one way would be to look up which groups of packages are installed with your setup and get the other ones (which are likely to be installed by the user) with the following command:
comm -23 <(pacman -Qeq | sort) <(pacman -Qgq base | sort) where base is one of the groups that you got preinstalled for sure.
To the second part of the question: You can get information about a package using
pacman -Si <yourpackage> and if you want to get the output reduced to just the dependencies check out this thread