import { addBanner, addArticle, addTitle, addHeader, addParagraph, addClassParagraph, addSubHeader, addSmallHeader, addOrderedList, addUnorderedList, addBlockquote, addInset, addInsetList, addInsetCodeListing, addInsetBulletList, addImageWithCaption, addButtonGroup, addSidebar, addSyntax, menu, global_menu } from '/scripts/import.js'; import { local_menu } from '/scripts/raspberrypi.js'; const heading = document.querySelector(".heading"); const global = document.querySelector(".global_menu"); const local = document.querySelector(".local_menu"); const sidebar = document.querySelector(".sidebar"); const main = document.querySelector(".main_content"); heading.append(addTitle("Raspberry Pi")); heading.append(addParagraph("Git Server")); main.append(addHeader("Install the Raspberry Pi Git Server")) main.append(addParagraph("There are several steps that are very important for a project like this, but because I am setting this up on a Raspberry Pi that I am already using as a development machine and I am already using Git on my Windows machine, I have been able to skip these. If you are doing this from scratch, you will need to make sure that these steps are carried out.")) main.append(addInsetBulletList(["Set up ssh on your Raspberry Pi and make sure that you can access it via an ssh client such as putty or kitty.", "Install Git on the machine you will be using to connect to the Pi from or any machine from which you will be using the Git service."])) main.append(addParagraph("You may also need to install it on the Pi. It should already be installed and you can check that with a command such as")) main.append(addInset("git --version")) main.append(addParagraph("If you do need to install, you can do that with the command")) main.append(addInset("sudo apt install git-core")) main.append(addHeader("Setting Up Your First Repository")) main.append(addParagraph("Once Git is installed, the next step is to set up the remote respository so that is the repository on the Raspberry Pi. Bear in mind that I am experimenting with this and the way I chose to proceed is this. I wanted to have a folder to which I could mount a storage device. Initially, this is going to be a USB stick but later, I plan to replace that with a larger drive which would likely be either a 256GB SSD or a 2TB SATA drive.")) main.append(addParagraph("I want to be able to set up multiple users, so more than one user will need to be able to create their own directory inside a common folder and use that as their own so in a sense, this would be like a second home folder - you might think of this as the Git home folder. All you need for that is a folder that everyone has full access to. I actually took a slightly different approach by setting up a new user which I called gituser. I mounted my USB stick to that folder so essentially the USB stick is the home folder for gituser and I modified the folder so that everyone has full access.")) main.append(addParagraph("I actually use the Raspberry Pi with two other users, philip (which is my own user account) and an account for a pseudo user called developer. I had initially set this user up because the current version of the Raspberry Pi OS doesn't allow multiple logins for a user so if I had started the machine with my own account (as I do), I can't ssh to it with the same account. Of course, I can now ssh in with the gituser account so keeping that and removing the developer user probably makes more sense and at least means that I have a sensible reason for having the gituser account!")) main.append(addParagraph("In this folder (/home/gituser), I created a folder called philip and since I was logged in with that account, I am the owner of that folder so I have full control. Note that unlike its parent folder, it does not give full access to everyone so it's as private as a home directory. Since my first repository is foing to contain the files for my website, I have created a folder called website which is going to be the remote repository.")) main.append(addParagraph("Next, I will cd into that folder and initialise the repository with the command")) main.append(addInset("git init --bare")) main.append(addParagraph("That's all that we need to do on the Raspberry Pi.")) main.append(addHeader("Setting Up the Local Repository")) main.append(addParagraph("I mentioned earlier that it is important that you have Git installed on the computer hosting the local repository. As it happens, I do have it installed and I had associated the folder containing my website files with a remote respository on BitBucket. I committed all of the files to the remote respoitory - possibly for the last time - and then used the command")) main.append(addInset("git init")) main.append(addParagraph("To be honest, I wasn't completely sure that this would work - I had hoped that it would sever the connection to the existing remote repository and allow me to create a new connection to the repository on the Pi and this is exactly what happened.")) main.append(addParagraph("The command to create that connection is")) main.append(addInset("git remote add website philip@192.168.0.10:/home/gituser/philip/website")) main.append(addParagraph("Of course, if you are doing this yourself, you will want to amend the command to show the ip address of your own Pi and the directory for your respository. Once that is done, it works in the same was as I am used to with the BitBucket repository. I don't want to go into the details of that here because that is covered in tmy notes on the course Programming Foundations: Version Control with Git.")) main.append(addParagraph("The image in figure 1 shows the commands I entered to make my add files, make my initial commit and push them to the remote repository.")) main.append(addImageWithCaption("images/figure1.png", "Figure 1 - the commands to add and commit the local files and to send them to the remote respository.")) main.append(addParagraph("This all seems fairly straightforward, and if everything worked as expected, the folder I created on my Raspberry Pi to host the remote repository for my website should now contain the remote respository, so it is probably worth checking that just to make sure everything is working as it should.")) main.append(addParagraph("I haven't ever looked at the actual files associated with a remote repository other than through some interface such as the web interface for GitHub or a GUI like SourceTree so I'm not sure what that looks like. The contents of the folder can be seen in figure 2.")) main.append(addImageWithCaption("images/figure2.png", "Figure 2 - the contents of the folder I set up as the local repository.")) main.append(addParagraph("A more sensible approach would be to check the status of the repository with the command")) main.append(addInset("git status")) main.append(addParagraph("The output for this command is shown in figure 3.")) main.append(addImageWithCaption("images/figure3.png", "Figure 2 - the result of running git status.")) main.append(addParagraph("This is showing the status after the initial commit has been made, but it shows that there is an untracked file (which is actually this page) and that is to be expected because, of course, the two repositories will only be in perfect sync with each other when the local reposiry has been uploaded to the server (or vice versa) and no other changes to the site have been made and in most cases, this is likely to be a very short period of time due to the fact that the site is under constant development so that looks perfectly fine.")) main.append(addParagraph("So that is my Git server up and running and I can easily upload local files to the respository when needed. For reference, I used a tutotial from PiMyLifeUp.com which provides all of the instructions shown here as well as the commands to clone the respository which in my case would be")) main.append(addInset("git clone philip@192.168.0.10:/home/gituser/philip/website")) addSidebar("raspberrypi");