I just developed an opengl game in linux (ubuntu).. Now I would like to write a setup script for the same which installs the game directly into the apt using the command..
sudo apt-get install ...
so that it runs from anywhere throughout linux without going into the specified folder for the game. Anyone knows how to do that ?
http://blog.boxedice.com/2010/02/05/how-to-create-a-debian-deb-package/
http://ptspts.blogspot.com/2010/02/how-to-create-debianubuntu-package-deb.html
http://wiki.debian.org/HowToPackageForDebian
etc
#!/bin/bash
set -eu -o pipefail # fail on error , debug all lines
sudo -n true
test $? -eq 0 || exit 1 "you should have sudo priveledge to run this script"
echo installing the must-have pre-requisites
while read -r p ; do sudo apt-get install -y $p ; done < <(cat << "EOF"
perl
zip unzip
exuberant-ctags
mutt
libxml-atom-perl
postgresql-9.6
libdbd-pgsql
curl
wget
libwww-curl-perl
EOF
)
echo installing the nice-to-have pre-requisites
echo you have 5 seconds to proceed ...
echo or
echo hit Ctrl+C to quit
echo -e "\n"
sleep 6
sudo apt-get install -y tig
Related
I'm writing a bash script here to install docker and send all outputs to the logs.txt file. But i still get errors such as the one below displayed on the terminal, what I'm i doing wrong here to get these errors?
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
if [[ `command -v apt-get` ]]; then
echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Getting requirements....."
sleep 1;
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release >> logs.txt
echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Adding Docker’s official GPG key........"
sleep 1;
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Installing Docker......."
sleep 1;
sudo apt-get install -y docker-ce docker-ce-cli containerd.io >> logs.txt
echo -e "\n${GREEN}[${WHITE}+${GREENS}]${GREENS} Docker version........"
sleep 1;
docker --version | head -n1
Well not a question as such, but more of a brainstorming thing or better say an issue. Well today I came to my server and realised that i can't git pull due to the keys being denied which was okay because for sure there were no keys in .ssh directory. All deleted and a new file (pbcopyfy there). Not sure what this means though. The content of the file are shown below:
#!/bin/sh
# Copyright (C) 2009-2017 Three Nine Consulting
# Always good practice to update packages. However ask user if they would like to do so
# For explanation on how this works and why check out https://garywoodfine.com/use-pbcopy-on-ubuntu/
read -p "Do you want to update your package repositories before proceeding ? " -n 1 -r
echo #adding new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
fi
# Check to see if Xclip is installed if not install it
if [ $(dpkg-query -W -f='${Status}' xclip 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
echo 'xclip not installed .... installing now!'
sudo apt install xclip -y;
fi
# Add the aliases to the .bashrc
echo 'updating bash profile'
echo "#pbcopy & pbpaste aliases" >> ~/.bashrc
echo "alias pbcopy='xclip -selection clipboard'" >> ~/.bashrc
echo "alias pbpaste='xclip -selection clipboard -o'" >> ~/.bashrc
source ~/.bashrc
echo 'Complete! happy PbCopy'
Is this something I should be worried about or should I just get new keys and go up and running with new keys?
I'm trying to learn how to write Bash scripts. I have this script to update my servers through ssh. I'm trying to add a check and a conditional to determine if the OS uses Yum or Apt then it will run the appropriate update commands. The if else statement seems to be wrong but I'm not sure how to correct this.
Here is the script:
#!/bin/bash
USERNAME="root"
HOSTS="host1 host2 host3"
apt_run="apt update && apt -y upgrade"
yum_run="yum check-update && yum -y update"
for HOSTNAME in ${HOSTS} ; do
ssh -l ${USERNAME} ${HOSTNAME}
find_os=$( command -v yum || command -v apt-get ) || echo "Neither
yum nor apt-get found"
if [[ $find_os='yum' ]]
then
"${yum_run}"
else
"${apt_run}"
fi
done
Here is my script for my virtual machines.
#!/bin/bash
hosts=(
leap151 kali ubuntu omv
)
for hostname in "${hosts[#]}"; do
ssh -t root#"$hostname" << 'EOF'
if type -P zypper >/dev/null; then
command zypper ref && command zypper up
elif type -P apt-get >/dev/null; then
command apt-get update && command apt-get upgrade
else
echo 'Neither zypper nor apt found!' >&2
exit 127
fi
EOF
done
Use an array for the host. Since you're using bash the builtin type is fine just for searching the executable within your PATH. See help type for more info. Use the -t option in ssh also use a heredoc just what I have/did. The exit 127 is what the shell would exit if there are no executable see man 1p exit.
I have the following sh command in my Jenkinsfile which does not work because it tries to execute the last "DATA" as a command.
If I move last "DATA" to the beginning of the line it works but is not as beautiful as I want.
Is there a way to the indention in this case?
sh """
sshpass -p 'password' ssh -o StrictHostKeyChecking=no appsadm#$backup_registry <<DATA
sudo /etc/init.d/docker stop || true
sudo yum remove -y docker-engine.x86_64
sudo rm -fr /var/lib/docker /var/log/docker
sudo rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm || true
sudo yum update -y
sudo yum -y install docker-io
sudo sed -i 's#other_args=.*#other_args="--insecure-registry $official_registry:5000"#g' /etc/sysconfig/docker
sudo /etc/init.d/docker start
DATA
"""
I know this is an old question, but I had ran into this at some point, and eventually ended up using stripIndent()
steps {
echo 'Deploying....'
sh """
ssh somewhere <<EOF
cd somewhere
do some more stuff
EOF
""".stripIndent()
}
That way you can still keep your indentations and formatting
because <<DATA specifies the end of here-doc <<-DATA suppress leading tabs but not spaces
cat <<-DATA
hello
<tab>DATA
another option is to add spaces in marker
cat << " DATA"
hello
DATA
Edit: We don't need to use EOF, simply put the semicolon at the end of statement on multiline shell script as shown below
sh """ if [ -d /opt/tomcat/apache-tomcat-8.5.38/webapps/ROOT ] ;
then ;
ssh $USERNAME#$DEV_HOSTNAME 'sudo rm -rf /opt/tomcat/apache-tomcat-8.5.38/webapps/ROOT' ;
echo 'ROOT directory deleted successfully' ;
fi ;
"""
I've created a bash program using whiptail to give a graphical type interface to the user to setup their system. For some reason my script isn't running any of my bash commands though, instead it seems to be cycling through outputting to my log.txt file, but no packages are being installed.
STATUS=0
touch log.txt
while [ $STATUS -lt 100 ]; do
# update apt repos
apt-get update
wait
echo "apt-get update" >> log.txt
let STATUS=STATUS+15
echo $STATUS
# update apt package
apt-get upgrade
wait
echo "apt-get upgrade" >> log.txt
let STATUS=STATUS+15
echo $STATUS
# install required packages
apt-get -y git-all nmap hydra
wait
echo "apt-get -y git-all nmap hydra" >> log.txt
let STATUS=STATUS+10
echo $STATUS
# install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
wait
echo "cloning rbenv" >> log.txt
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'exporting PATH' >> log.txt
~/.rbenv/bin/rbenv init
wait
echo 'initializing rbenv' >> log.txt
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
wait
echo "cloning ruby-build" >> log.txt
rbenv install 2.1.4
wait
echo "installing ruby 2.1.4" >> log.txt
let STATUS=STATUS+25
echo $STATUS
done | whiptail --gauge "Setting Up Neo (THIS WILL TAKE SOME TIME)..." 40 78 0
So, to confirm my while loop is actually running, I started echoing things to log.txt. Here is the output:
apt-get update
apt-get upgrade
apt-get -y git-all nmap hydra
cloning rbenv
exporting PATH
initializing rbenv
cloning ruby-build
installing ruby 2.1.4
What have I done wrong?
First, since you have no backgrounded processes, wait is not doing anything.
Second, since whiptail is reading stdin, you need to ensure that stdout from all apt-get, git, rbenv, etc commands are redirected to stderr, or better, to your log.
# update apt repos
echo "apt-get update" >> log.txt
apt-get update >>log.txt 2>&1
(( STATUS += 15 ))
echo $STATUS
# update apt package
echo "apt-get upgrade" >> log.txt
apt-get upgrade >> log.txt 2>&1
(( STATUS += 15 ))
echo $STATUS
and so on.