Install rpm and put file into symbolic link directory - linux

I have made an rpm package that install a program and one of the folders it needs to copy a file to is a symbolic link since the program the symbolic link is pointing to may change over time so it is easier to maintain the building of the rpm package by copying the file to the symbolic link rather then to the hard coded path. However, I get the error
cp: cannot overwrite directory with non-directory
when the rpm package tried to copy the file to the symbolic link folder. Why does this happen, and is there anything I can do to work around this error other then making the files to be copied to the folder the symbolic link points to? I am running RHEL 6.6 as of note.

That error generally means something like you having told cp to treat the target as a normal file (the -T argument).
$ ls -lR
.:
total 16
drwxr-xr-x 2 root root 4096 Feb 6 09:46 dir
-rw-r--r-- 1 root root 0 Feb 6 09:45 file
lrwxrwxrwx 1 root root 3 Feb 6 09:45 symdir -> dir
./dir:
total 0
$ cp -T file symdir
cp: cannot overwrite non-directory `symdir' with non-directory
$ ls -lR
.:
total 16
drwxr-xr-x 2 root root 4096 Feb 6 09:46 dir
-rw-r--r-- 1 root root 0 Feb 6 09:45 file
lrwxrwxrwx 1 root root 3 Feb 6 09:45 symdir -> dir
./dir:
total 0
$ cp file symdir
$ ls -lR
.:
total 16
drwxr-xr-x 2 root root 4096 Feb 6 09:46 dir
-rw-r--r-- 1 root root 0 Feb 6 09:45 file
lrwxrwxrwx 1 root root 3 Feb 6 09:45 symdir -> dir
./dir:
total 4
-rw-r--r-- 1 root root 0 Feb 6 09:46 file

Related

What does it mean to have a directory name prefixed with two dots?

I got the below file hierarchy in my Linux system. Wondering what it means to have two dots prefixed to a directory name?
/run/mydir # ls -la
total 4
drwxrwxrwt 3 root root 140 Sep 22 13:03 .
drwxr-xr-x 3 root root 4096 Sep 30 06:26 ..
drwxr-xr-x 2 root root 100 Sep 22 13:03 ..2019_09_22
lrwxrwxrwx 1 root root 31 Sep 22 13:03 ..data -> ..2019_09_22
lrwxrwxrwx 1 root root 13 Sep 22 13:03 address -> ..data/address
lrwxrwxrwx 1 root root 16 Sep 22 13:03 name -> ..data/name
lrwxrwxrwx 1 root root 12 Sep 22 13:03 cell -> ..data/cell
/run/mydir # ls -la ../
total 8
drwxr-xr-x 3 root root 4096 Sep 30 06:26 .
drwxr-xr-x 3 root root 4096 Sep 30 06:26 ..
drwxrwxrwt 3 root root 140 Sep 22 13:03 mydir
/run/mydir #
It has no significance except that ls will not normally list the names because the first character is a dot .. To see names beginning with a dot, you need ls -a or thereabouts, as you show. It looks like a convention that someone with root privileges on your machine likes as a way to identify other directories, but that's about all.
We could guess that over time, there might eventually be other directories such as ..2019_09_29 and that ..data might be rigged to point to the directory currently being analyzed, but that's guesswork.
There are always two default directories:
single period (.) = Current Directory
Double Period (..) = Parent Directory

Versioning linux folder with symlinks and them content

My use-case is versioning application changes on server because sometimes I need to rollback previous version before update, or before configuration changes.
This is my list of content:
dasper#debian:/usr/share/otrs$
drwxr-xr-x 6 root root 4096 Sep 18 16:56 .
drwxr-xr-x 109 root root 4096 Sep 18 13:13 ..
lrwxrwxrwx 1 root root 21 May 9 11:06 ARCHIVE -> /var/lib/otrs/ARCHIVE
drwxr-xr-x 4 root root 4096 Sep 11 15:53 bin
-rwx------ 1 root root 212450 Sep 18 16:06 .etckeeper
-rw-r--r-- 1 root root 1125 Jan 11 2019 .fetchmailrc.dist
drwx------ 8 root root 4096 Sep 18 16:06 .git
-rw-r--r-- 1 root root 932 Sep 18 15:40 .gitignore
drwxr-xr-x 9 root root 4096 Sep 11 15:53 Kernel
-rw-r--r-- 1 root root 104 Jan 12 2019 RELEASE
drwxr-xr-x 7 root root 4096 Sep 11 15:53 scripts
-rw-r--r-- 1 root root 0 Sep 18 15:36 testfile.txt
lrwxrwxrwx 1 root root 13 May 9 11:06 var -> /var/lib/otrs
I was trying etckeeper to auto commit after package manager make some changes, but git will as defaulte create only empty folder var/ and ARCHIVE/.
I was trying submodules, but then i don't know about changes in symlink folders (git add .) and submodule content can't lead to symlink folder.
My biggest issue is how to store these folders in git and how to clone/checkout in same structure.
Solution was easy & clean, i hope :)
apt-get install etckeeper
Make directory for repository. This is mounted to other disk
mkdir /BACKUP
cd /BACKUP
Initialize git repo & set worktree to root /. Now i can tracking whole system changes, not only /etc
git init
git config --path core.worktree /
My .gitignore inside /BACKUP:
# Ignore everything ~ whitelist
*
# But descend into directories
!*/
# Add /usr/share/otrs/ - main directory
!/usr/share/otrs/**
# Add /var/lib/otrs - symlink # Add /usr/share/otrs/var -> /var/lib/otrs
!/var/lib/otrs/**
...
# Add myself
!/.gitignore
# Add etckeeper staff
!/etc/.etckeeper/**
Add new line at the end of /etc/etckeeper/etckeeper.conf with path to repository:
ETCKEEPER_DIR=/BACKUP
At the end, remove unused repo initialized by etckeeper after installation:
cd /etc
rm -rf .git
rm .gitignore
Now you can make first inital commit: etckeeper commit

Folder Permissions not Sticking

I'd like to think I'm not a linux noob but I am having an issue I can't explain. I hope it something stupid. I have an external drive that I am trying to set up on plex. It was originally formatted ntfs but I shrunk the partition and made another ext4 partition. Plex can't look into the drive and see the folders. I have been trying to change the perms but they aren't sticking. They don't stick if
myUser#mint /media/myUser $ ls -lah
total 44K
drwxr-x---+ 6 root root 4.0K Oct 24 11:21 .
drwxr-xr-x 3 root root 4.0K Oct 24 10:50 ..
drwx------ 1 myUser myUser 20K Oct 14 07:27 DataDisk
myUser#myUserMint /media/myUser $ sudo chmod -R 766 DataDisk/
[sudo] password for myUser:
myUser#mint /media/myUser $ ls -lah
total 44K
drwxr-x---+ 6 root root 4.0K Oct 24 11:21 .
drwxr-xr-x 3 root root 4.0K Oct 24 10:50 ..
drwx------ 1 myUser myUser 20K Oct 14 07:27 DataDisk
myUser#mint /media/myUser $
Am I missing something obvious or is this just weird?

Can't CD to directory inside of root

I am currently creating an application that requires separate users running duplicate programs. They cannot run under root because of security reasons, so they are initiated by a Java app that I am working on, and I am starting them with runuser -l. However, I cannot cd into a directory, even though it is owned by the user, and the user has 770 permissions in the folder.
Here's what I'm running:
runuser -l lp1 -c 'java \-jar /root/Desktop/workspace/LitePanel/servers/server1/server.jar \-Xms1024M nogui'
And the output of this is:
runuser: warning: cannot change directory to /root/Desktop/workspace/LitePanel/bin/servers/server1/: Permission denied
Here's an ls -all:
drwxr-xr-x. 3 root root 4096 Jan 30 14:03 .
drwxr-xr-x. 7 root root 4096 Jan 30 14:02 ..
drwxrwx---. 2 lp1 lp1 4096 Jan 31 03:07 server1
Inside the directory:
drwxrwx---. 2 lp1 lp1 4096 Jan 31 03:07 .
drwxr-xr-x. 3 root root 4096 Jan 30 14:03 ..
-rwxrwx---. 1 lp1 lp1 9170551 Jan 31 03:07 server.jar
And here's /etc/passwd:
lp1:x:501:501::/root/Desktop/workspace/LitePanel/bin/servers/server1/:/bin/false
Anyone know why this is happening? It looks like the user has the necessary permissions to do this.
You have said that the directory itself has permissions 770 and is owned by the user, but what about its parents? I believe the cd command will need at least read access (and possibly execute) on the parent directories.

scp file not setting correct owner

Does SCP have a problem setting file permissions or have I misconfiguration my server?
Use case:
There is a file on a server that I want to edit called "importantFile.txt". The file has owner and group of "master":
ls -l importantFile.txt:
-rw-rw-r-- 1 master master 7 Mar 18 08:11 importantFile.txt
I am called "slave" but luckily, I am in group "master" so I can edit the file as I see fit. However, I'm a lazy slave and can't be bothered to edit the file on the server, I'd prefer to edit the file on my local machine and SCP it to the server:
echo "bored slave info" > importantFile.txt
scp importantFile.txt slave#theServerAddress:/pathToFile/importantFile.txt
If I do this, the contents of the file on the server are uploaded fine and the timestamp of the file is updated but the permissions of the file don't change, the file is still owned by "master". This is a problem because if "slave" uploaded bad content, no one would know it was "slave" who caused the problem, "master" would look guilty.
Perhaps I have to set a umask? if so where? I tried .bash_profile without success and haven't found anything on Google about umask in /etc/ssh/sshd_config.
That's nothing special about scp - try logging on to the server as slave, and editing the file using your favourite text editor... You'll find the same behaviour occurs... Writing to a file does not make you the owner of the file.
Example:
as root
#cd /tmp
#mkdir fubar
#chgrp vboxusers fubar
#cd fubar/
#touch testfile
#chgrp vboxusers testfile
#chmod g+w . testfile
#ls -al
total 16
drwxrwxr-x 2 root vboxusers 4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root 12288 2009-03-19 10:29 ..
-rw-rw-r-- 1 root vboxusers 0 2009-03-19 10:30 testfile
#echo foo > testfile
#ls -al
total 20
drwxrwxr-x 2 root vboxusers 4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root 12288 2009-03-19 10:29 ..
-rw-rw-r-- 1 root vboxusers 4 2009-03-19 10:30 testfile
as user (in vboxusers group)
>cd /tmp/fubar
>ls -al
total 20
drwxrwxr-x 2 root vboxusers 4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root 12288 2009-03-19 10:29 ..
-rw-rw-r-- 1 root vboxusers 4 2009-03-19 10:30 testfile
>echo bar >> testfile
>ls -al
total 20
drwxrwxr-x 2 root vboxusers 4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root 12288 2009-03-19 10:29 ..
-rw-rw-r-- 1 root vboxusers 8 2009-03-19 10:31 testfile
>vim testfile
>ls -al
total 20
drwxrwxr-x 2 root vboxusers 4096 2009-03-19 10:31 .
drwxrwxrwt 15 root root 12288 2009-03-19 10:31 ..
-rw-rw-r-- 1 root vboxusers 12 2009-03-19 10:31 testfile
>cat testfile
foo
bar
baz
You have to delete the file to overwrite it. Wether you are able to do that depends on the directory's permissions and ownership. Hijacking ownership of an already existing file is not possible. The write permission you have is only applied on the contents of the file.
It seems you can configure how Emacs deals with this through the backup-by-copying-when-mismatch variable (see the Emacs Manual or type C-h-v backup-by-copying-when-mismatch in Emacs).
I actually filed a bug report about this, because I thought it was a bug in Tramp.
I had misunderstood the way files work, modifying file contents do not change ownership or group.
Why the confusion? EMACS - Whenever I was editing a file I was using Emacs and Emacs does change the owner and group to the current user. It does this because it makes a backup file at save time by moving the "filename" to "filename~" and creating a new file called "filename" - because it's a new file, it has the current users file permissions. I guess this is 1up to VI fans?

Resources