Proper way to make this a shell script - linux

Hi guys anyone can guide me or re-write my script? well i manually type this code everytime i reinstall.
i want to make this all in just 1 script file only
yum update -y
yum install httpd -y
service httpd start
yum install mysql-server -y && service mysqld start && mysql_secure_installation
yum install php php-mysql -y && service httpd restart
rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm && yum check-update && yum install phpMyAdmin -y
vi /etc/httpd/conf.d/phpMyAdmin.conf (Will edit some of line)
yum install git -y && yum install gcc make mysql mysql-devel mysql-server pcre-devel zlib-devel && yum -y install dos2unix gdb nano screen unzip wget zip
yum -y groupinstall Desktop && yum -y install tigervnc-server pixman pixman-devel libXfont
vncpasswd
vi /etc/sysconfig/vncservers
(Will write this on the bottom of vncservers)
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1100x768"
yum -y install xterm && yum -y install subversion && yum install gnome-utils -y && yum -y install nautilus-open-terminal
service vncserver start
chkconfig httpd on && chkconfig mysqld on && chkconfig vncserver on
reboot
=====
Is there anyone can help me to clean up and put that in 1 file only?

in some directory of your choice do touch [script_name].sh then enter the following into the script
#!/bin/bash
#if not sudo or root yum fails
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
yum update -y
yum install httpd -y
service httpd start
yum install mysql-server -y && service mysqld start && mysql_secure_installation
yum install php php-mysql -y && service httpd restart
rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm && yum check-update && yum install phpMyAdmin -y
sed -i '24s/Deny from All/Allow from All/' /etc/httpd/conf.d/phpMyAdmin.conf
yum install git -y && yum install gcc make mysql mysql-devel mysql-server pcre-devel zlib-devel && yum -y install dos2unix gdb nano screen unzip wget zip
yum -y groupinstall Desktop && yum -y install tigervnc-server pixman pixman-devel libXfont
vncpasswd
echo VNCSERVERS="1:root" >> /etc/sysconfig/vncservers
echo VNCSERVERARGS[1]="-geometry 1100x768" >> /etc/sysconfig/vncservers
yum -y install xterm && yum -y install subversion && yum install gnome-utils -y && yum -y install nautilus-open-terminal
service vncserver start
chkconfig httpd on && chkconfig mysqld on && chkconfig vncserver on
echo rebooting computer
sleep 5
reboot
After that is done exit the text editor and run the command chmod +x /scriptpath/[script_name].sh and then cd to the directory containing the script and run ./[script_name].sh.

Related

Jupyterlab docker container error on starting the container

I have created a notebook Docker file as below to running the JupyterHub and JupyterLab
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install sudo
RUN sudo useradd -m admin
RUN sudo echo -e "admin\nadmin\n" | passwd admin
RUN sudo echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER admin
RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends apt-utils
RUN sudo apt-get update \
&& sudo apt-get install -y build-essential \
&& sudo apt-get install -y libffi-dev \
&& sudo apt-get install -y libmysqlclient-dev \
&& sudo apt-get install -y libsasl2-dev \
&& sudo apt-get install -y openjdk-8-jdk \
&& sudo apt-get install -y openssh-server \
&& sudo apt-get install -y python-dev \
&& sudo apt-get install -y unzip \
&& sudo apt-get install -y wget \
&& sudo apt-get install -y mysql-client \
&& sudo apt-get install -y git
RUN sudo apt-get install -y libssl-dev libxml2-dev libxslt1-dev zlib1g-dev libkrb5-dev
RUN sudo apt-get update
RUN sudo apt-get install -y python3-pip
RUN sudo apt-get install -y python-pip
RUN sudo apt-get install -y python3-venv
RUN sudo python3 -m venv /opt/jupyterhub/
RUN sudo /opt/jupyterhub/bin/python3 -m pip install --upgrade pip
RUN sudo /opt/jupyterhub/bin/python3 -m pip install wheel
RUN sudo /opt/jupyterhub/bin/python3 -m pip install jupyterhub jupyterlab
RUN sudo /opt/jupyterhub/bin/python3 -m pip install ipywidgets
RUN sudo apt-get install -y curl
RUN sudo apt-get install -y nodejs npm
RUN sudo curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
RUN sudo bash nodesource_setup.sh
RUN sudo apt-get install -y nodejs
RUN sudo npm install -g -y configurable-http-proxy
RUN sudo mkdir -p /opt/jupyterhub/etc/jupyterhub/
RUN cd /opt/jupyterhub/etc/jupyterhub/
RUN sudo /opt/jupyterhub/bin/jupyterhub --generate-config
RUN sudo mkdir -p /opt/jupyterhub/etc/systemd
RUN sudo chown -R admin:admin /opt/jupyterhub
RUN sudo echo "c.Spawner.default_url = '/lab' " >> /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py
RUN sudo echo "c.Authenticator.admin_users = {'admin'} " >> /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py
RUN sudo echo "c.LocalAuthenticator.create_system_users=True" >> /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py
RUN sudo echo -e '[Unit]\nDescription=JupyterHub\nAfter=syslog.target network.target\n\n[Service]\nUser=root\nEnvironment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/jupyterhub/bin"\nExecStart=/opt/jupyterhub/bin/jupyterhub -f /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py\n\n[Install]\nWantedBy=multi-user.target' >> /opt/jupyterhub/etc/systemd/jupyterhub.service
RUN sudo cp /opt/jupyterhub/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
RUN sudo systemctl enable jupyterhub.service
#RUN sudo chown -R admin:admin /home/admin/.cache/pip
RUN sudo /opt/jupyterhub/bin/python3 -m pip install --upgrade setuptools
RUN sudo /opt/jupyterhub/bin/python3 -m pip install ipython==3.2.3
RUN sudo /opt/jupyterhub/bin/python3 -m pip install zipp==1.2.0
RUN sudo /opt/jupyterhub/bin/python3 -m pip install git+https://github.com/as-sher/sparkmagic.git#subdirectory=sparkmagic
RUN sudo /opt/jupyterhub/bin/jupyter-kernelspec install /opt/jupyterhub/lib/python3.5/site-packages/sparkmagic/kernels/sparkkernel
RUN sudo /opt/jupyterhub/bin/jupyter-kernelspec install /opt/jupyterhub/lib/python3.5/site-packages/sparkmagic/kernels/pysparkkernel
RUN sudo sed -i 's|root:x:0:0:root:/root:/bin/bash|root:x:0:0:root:/root:/sbin/nolgin|g' /etc/passwd
WORKDIR /home/admin
#USER root
EXPOSE 8000 2222
CMD SUDO SYSTEMCTL START JUPYTERHUB.SERVICE
When I am running this container as a root user, it is working, but when I am running this with admin (sudo user), I am getting the following error
Failed to mount tmpfs at /run/lock: Operation not permitted
[!!!!!!] Failed to mount API filesystems, freezing.
Freezing execution.
So my concern is that I have to run this container on Kubernetes and I don't want to run it as a root user and with privileged flag.
Is there any way in which I can run the existing docker with non-root user or if we can run the jupyter service without adding systemd.
There are some ways you can try in order to run Docker as a non-root user.
Manage Docker as a non-root user:
If you don’t want to preface the docker command with sudo, create a
Unix group called docker and add users to it. When the Docker daemon
starts, it creates a Unix socket accessible by members of the docker
group.
Create a docker group if there isn’t one:
$ sudo groupadd docker
Add your user to the docker group:
$ sudo usermod -aG docker [non-root user]
Log out and log back in so that your group membership is re-evaluated.
Run the Docker daemon as a non-root user (Rootless mode):
Rootless mode allows running the Docker daemon and containers as a
non-root user to mitigate potential vulnerabilities in the daemon and
the container runtime. Rootless mode does not require root privileges
even during the installation of the Docker daemon, as long as the
prerequisites are met.
Notice however that the second option is currently available as an experimental feature. You can find all the necessary details in the linked docs.
Please let me know if that helped.

yum in dockerfile - There are no enabled repos

I am having issues with installing python3 with yum in dockerfile. I did look on internet, I did try few things, not working. Its just small thing but not able to figure it out. When I try to build below docker file I do get error . I get error at line -
RUN yum install -y oracle-epel-release-el7
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
You can enable repos with yum-config-manager --enable <repo>
The docker file is below.
FROM openjdk:13-jdk-slim
ARG MAVEN_VERSION=3.6.3
ARG USER_HOME_DIR="/root"
ARG SHA=c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
# Install prerequisites
RUN apt-get update && apt-get install -y curl
RUN apt-get update && apt-get install -y yum
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha512sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
# Install Python 3.6
RUN yum install -y oracle-epel-release-el7
RUN yum install -y python36
# Install AWS CLI
RUN pip3 install awscli
CMD ["/bin/bash"]
Why mix apt and yum? You're already using apt-get, just use it to install your python too:
apt-get install python3.6

Jenkins slave with nodejs to run npm publish

I have a dockerfile where I install nodejs. I create a container from that dockerfile to use as a slave in jenkins. The problem is that when I try to publish (npm publish --registry ...) it says that I need to login first. But I cannot use npm adduser in a jenkins file cause you have to enter user and password manually when it is required. I have tried to add the file .nmrw with a valid token, but it haven't worked. Any idea?
Best regards.
FROM jenkins/ssh-slave
# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean
RUN apt-get install -y curl
# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs && apt-get install -y nginx
The key is in the file .npmrc. You have to have the same server you publish to.
FROM jenkins/ssh-slave
# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean
RUN apt-get install -y curl
ARG NODEJS_VERSION=setup_11.x
# Install nodejs
RUN curl -sL https://deb.nodesource.com/${NODEJS_VERSION} | bash - && apt-get install -y nodejs && apt-get install -y nginx
RUN chown -R jenkins:jenkins /home/jenkins && chmod -R 777 /home/jenkins
COPY .npmrc /home/jenkins/.npmrc
RUN npm -v

Docker building fails: returned a non-zero code: 1

Dockerfile1
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update
RUN apt-get update && apt-get install -y net-tools \
&& apt-get install inetutils-traceroute \
&& apt-get install iputils-ping \
&& apt-get install xinetd telnetd
Dockerfile2
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update
RUN apt-get update && apt-get install -y net-tools
RUN apt-get update && apt-get install inetutils-traceroute
RUN apt-get update apt-get install iputils-ping
RUN apt-get install xinetd telnetd
Dockerfile3
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update
RUN apt-get install inetutils-traceroute
RUN apt-get install -y net-tools
RUN apt-get update apt-get install iputils-ping
RUN apt-get install xinetd telnetd
I tried all the above flavors of my dockerfile but every time I get the same error :
The command '/bin/sh -c apt-get update && apt-get install -y net-tools && apt-get install inetutils-traceroute && apt-get install iputils-ping && apt-get install xinetd telnetd' returned a non-zero code: 1
Someone posted an answer and deleted it before I could accept it. But here it is -
FROM ubuntu:latest
MAINTAINER ME
RUN apt-get update && apt-get install -y \
net-tools inetutils-traceroute \
iputils-ping xinetd telnetd
This works!!
try to use key -y for apt-get or apt managers, on docker side.
For example:
RUN apt-get update
RUN apt -y install net-tools
Without -y, apt-get asks a clarifying question - "are you sure you want to install this?". Without answer docker droped installation with code 1. The issue in here.

Wine 1.9.24 on Centos 7

The problem
When I try to start any windows program I get no error and nothing happens. I tried on 3 different machines with Centos 7. Also tried older versions of Wine. Tested with winbox.exe from Mikrotik and with putty.exe. What could be the problem?
$ ./wine winbox.exe
$
CentOS 7 version
$ cat /etc/*elease | grep "release" | head -1
CentOS Linux release 7.3.1611 (Core)
Kernel version
$ uname -r
3.10.0-514.2.2.el7.x86_64
Openbox version
$ openbox --version | grep "Openbox"
Openbox 3.5.2
Wine install steps
sudo yum clean all
sudo yum update -y
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y libX11-devel freetype-devel zlib-devel libxcb-devel libxml2-devel libxslt-devel libjpeg-devel gnutls-devel flex bison
cd /tmp
wget http://dl.winehq.org/wine/source/1.9/wine-1.9.24.tar.bz2
tar xjf wine-1.9.24.tar.bz2
cd wine-1.9.24
./configure --enable-win64
make -j4
and the executable is working
$ ./wine --version
wine-1.9.24
wine-2.0-rc3
Had no time to try the latest Wine 2.0 version, but all my problems are gone with wine-2.0-rc3. Tested only 32bit install. Step by step:
sudo yum clean all
sudo yum update -y
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y libX11-devel freetype-devel zlib-devel libxcb-devel libxml2-devel libxslt-devel libjpeg-devel gnutls-devel flex bison
sudo yum install -y samba-winbind samba-winbind-clients samba-winbind-modules libwbclient-devel mod_auth_ntlm_winbind
# OpenGL support
sudo yum install mesa-dri-drivers.i686 mesa-libGL.i686
mkdir ~/bin && cd ~/bin
wget http://dl.winehq.org/wine/source/2.0/wine-2.0-rc3.tar.bz2
tar xjf wine-2.0-rc3.tar.bz2 && cd wine-2.0-rc3
# run provided install tool and write the output to file
./tools/wineinstall | tee output.file
# get the winetricks tool
wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks
chmod +x winetricks
WINE=~/bin/wine-2.0-rc3/wine sh winetricks corefonts vcrun6 mfc40 ie8 ie7
# start the downloaded windows program
./wine ~/Downloads/winbox.exe
winbox from Mikrotik
SketchUp

Resources