3

I'm trying to create a script to automate the setup for my Plex server, but it's not working. Here's the script:

#!/bin/bash

#makes backup of /etc/fstab and /etc/network/interfaces
cp /etc/fstab /etc/fstab.bak
cp /etc/network/interfaces /etc/network/interfaces.bak

#sets static IP
ifdown eth0
cat <<EOF > /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp

#Your static network configuration
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.4
EOF
ifup eth0

#runs updates and installs VM tools, CIFS, avahi-daemon, git-core and htop
apt-get install open-vm-tools cifs-utils avahi-daemon git-core htop
apt-get update -y 
apt-get dist-upgrade -y
apt-get autoremove
apt-get autoclean

#creates directories for file shares
mkdir /media/windowsshare
mkdir /media/windowsshare1

#creates file for file share credentials
cat <<EOF > ~/.smbcredentials
  username=username
  password=password
EOF

#adds file share location to /etc/fstab
cat <<EOF >> /etc/fstab
//server/Media /media/windowsshare cifs credentials=/home/plex/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
//server/Media1 /media/windowsshare1 cifs credentials=/home/plex/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
EOF

#mounts file shares
mount a

#installs plex
wget https://downloads.plex.tv/plex-media-server/0.9.14.6.1620-e0b7243/plexmediaserver_0.9.14.6.1620-e0b7243_amd64.deb
dpkg -i plexmediaserver_0.9.14.6.1620-e0b7243_amd64.deb

#configures plexpy
cd /opt
git clone https://github.com/drzoidberg33/plexpy.git
cd plexpy
python PlexPy.py
cd /opt/plexpy
touch /etc/default/plexpy
adduser --system --no-create-home plexpy
chown plexpy:nogroup -R /opt/plexpy
chmod +x /opt/plexpy/init-scripts/init.ubuntu
ln -s /opt/plexpy/init-scripts/init.ubuntu /etc/init.d/plexpy
update-rc.d plexpy defaults
service plexpy [restart]

I've set it as executable, but whenever I try to run:

sudo ./plexsetup.sh

I get:

sudo: unable to execute ./plexsetup.sh: No such file or directory

If I run:

sudo sh plexsetup.sh

I get:

 : not foundh: 2: plexsetup.sh
 : not foundh: 6: plexsetup.sh
 not configuredcd eth0

Any ideas?

EDIT:

start plexsetup.sh

returns:

start: unknown job: plexsetup.sh
9
  • Did you write it in a Windows text editor? Are there Windows-style line endings anywhere (you can check with cat -net plexsetup.sh) Dec 24, 2015 at 22:23
  • I originally wrote it in notepad, then copied it to Notepad++ and did an rewrote most of it. Dec 24, 2015 at 22:26
  • Just checked, all the lines end with "^M$" Dec 24, 2015 at 22:32
  • can you edit in the output of stat plexsetup.sh?
    – cat
    Dec 24, 2015 at 22:33
  • remark: those 1st 2 copies are dangerous... run the command twice and you'll remove the correctly running fstab. Use a datestring to make the backup.
    – Rinzwind
    Dec 24, 2015 at 22:48

0

Browse other questions tagged .